@@ -79,38 +79,38 @@ public class FileEntityService {
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileEntityResponse getById(String fileId) {
|
||||
public FileEntityResponse getById(String fileId, int version) {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(fileId)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException(fileId));
|
||||
|
||||
return convertToResponse(fileEntity);
|
||||
return convertToResponse(fileEntity, version);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileEntityResponse getByUploadSessionId(String uploadSessionId) {
|
||||
public FileEntityResponse getByUploadSessionId(String uploadSessionId, int version) {
|
||||
FileEntity fileEntity = fileEntityRepository.findByUploadSessionId(uploadSessionId)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException(
|
||||
"Not found for upload session: " + uploadSessionId));
|
||||
|
||||
return convertToResponse(fileEntity);
|
||||
return convertToResponse(fileEntity, version);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileEntityResponse getByFilePath(String filePath) {
|
||||
public FileEntityResponse getByFilePath(String filePath, int version) {
|
||||
FileEntity fileEntity = fileEntityRepository.findByFilePath(filePath)
|
||||
.orElseThrow(() -> new FileEntityNotFoundException("Path: " + filePath));
|
||||
|
||||
return convertToResponse(fileEntity);
|
||||
return convertToResponse(fileEntity, version);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileResponse getAllUserFiles(Long userId) {
|
||||
public FileResponse getAllUserFiles(Long userId, int version) {
|
||||
List<FileEntity> fileEntities = fileEntityRepository.findByUserIdAndStatus(
|
||||
userId, FileStatus.ACTIVE);
|
||||
|
||||
List<FileEntityResponse> files = fileEntities.stream()
|
||||
.map(this::convertToResponse)
|
||||
.map(file -> convertToResponse(file, version))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
long totalSize = fileEntities.stream()
|
||||
@@ -129,7 +129,7 @@ public class FileEntityService {
|
||||
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public FileResponse getUserFiles(Long userId, int page, int pageSize) {
|
||||
public FileResponse getUserFiles(Long userId, int page, int pageSize, int version) {
|
||||
List<FileEntity> allFiles = fileEntityRepository.findByUserIdAndStatus(
|
||||
userId, FileStatus.ACTIVE);
|
||||
|
||||
@@ -150,7 +150,7 @@ public class FileEntityService {
|
||||
List<FileEntity> pageFiles = allFiles.subList(start, end);
|
||||
|
||||
List<FileEntityResponse> files = pageFiles.stream()
|
||||
.map(this::convertToResponse)
|
||||
.map(file -> convertToResponse(file, version))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
long totalSize = allFiles.stream()
|
||||
@@ -185,16 +185,6 @@ public class FileEntityService {
|
||||
return totalSize != null ? totalSize : 0L;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<FileEntityResponse> searchFiles(Long userId, String query) {
|
||||
List<FileEntity> files = fileEntityRepository.searchByFileName(userId, query);
|
||||
|
||||
return files.stream()
|
||||
.filter(f -> f.getStatus() == FileStatus.ACTIVE)
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean checkFileExistsOnDisk(String filePath) {
|
||||
try {
|
||||
return Files.exists(Paths.get(filePath));
|
||||
@@ -204,7 +194,7 @@ public class FileEntityService {
|
||||
}
|
||||
}
|
||||
|
||||
private FileEntityResponse convertToResponse(FileEntity fileEntity) {
|
||||
private FileEntityResponse convertToResponse(FileEntity fileEntity, int version) {
|
||||
boolean existsOnDisk = checkFileExistsOnDisk(fileEntity.getFilePath());
|
||||
|
||||
return FileEntityResponse.builder()
|
||||
@@ -222,7 +212,7 @@ public class FileEntityService {
|
||||
.createdAt(fileEntity.getCreatedAt())
|
||||
.updatedAt(fileEntity.getUpdatedAt())
|
||||
.formattedSize(formatFileSize(fileEntity.getFileSize()))
|
||||
.downloadUrl("/api/files/download/" + fileEntity.getId())
|
||||
.downloadUrl("/api/v" + version + "/files/download/" + fileEntity.getId())
|
||||
.existsOnDisk(existsOnDisk)
|
||||
.build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user