Skip to content

Commit

Permalink
Revert "Feature/chung step5 (#12)"
Browse files Browse the repository at this point in the history
This reverts commit 9919fac.
  • Loading branch information
kochungcheon authored Jun 2, 2024
1 parent 9919fac commit 78f957d
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 549 deletions.
50 changes: 23 additions & 27 deletions src/main/java/com/c4cometrue/mystorage/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,37 @@
@Getter
@AllArgsConstructor
public enum ErrorCode {
UNAUTHORIZED_FILE_ACCESS(HttpStatus.FORBIDDEN, "비정상적인 요청입니다."),
UNAUTHORIZED_FILE_ACCESS(HttpStatus.FORBIDDEN, "비정상적인 요청입니다."),

CANNOT_FOUND_FILE(HttpStatus.NOT_FOUND, "해당 파일을 찾을 수 없습니다."),
CANNOT_FOUND_FILE(HttpStatus.NOT_FOUND, "해당 파일을 찾을 수 없습니다."),

FILE_COPY_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "파일 복사 중 오류가 발생했습니다."),
FILE_COPY_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "파일 복사 중 오류가 발생했습니다."),

FILE_DELETE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "파일 삭제 중 오류가 발생했습니다."),
FILE_DELETE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "파일 삭제 중 오류가 발생했습니다."),

DUPLICATE_FILE_NAME(HttpStatus.BAD_REQUEST, "파일 업로드에 중복이 발생 했습니다"),
DUPLICATE_FILE_NAME(HttpStatus.BAD_REQUEST, "파일 업로드에 중복이 발생 했습니다"),

FOLDER_CREATE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "폴더 생성 중 오류가 발생했습니다"),
UNAUTHORIZED_FOLDER_ACCESS(HttpStatus.FORBIDDEN, "비정상적인 요청입니다."),
DUPLICATE_FOLDER_NAME(HttpStatus.BAD_REQUEST, "폴더 업로드에 중복이 발생 했습니다"),
DUPLICATE_SERVER_FOLDER_NAME(HttpStatus.BAD_REQUEST, "폴더 UUID 중복이 발생 했습니다"),
CANNOT_FOUND_FOLDER(HttpStatus.NOT_FOUND, "해당 폴더를 찾을 수 없습니다."),
FOLDER_CREATE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "폴더 생성 중 오류가 발생했습니다"),
UNAUTHORIZED_FOLDER_ACCESS(HttpStatus.FORBIDDEN, "비정상적인 요청입니다."),
DUPLICATE_FOLDER_NAME(HttpStatus.BAD_REQUEST, "폴더 업로드에 중복이 발생 했습니다"),
DUPLICATE_SERVER_FOLDER_NAME(HttpStatus.BAD_REQUEST, "폴더 UUID 중복이 발생 했습니다"),
CANNOT_FOUND_FOLDER(HttpStatus.NOT_FOUND, "해당 폴더를 찾을 수 없습니다."),

DUPLICATE_BASE_PATH(HttpStatus.BAD_REQUEST, "기본 경로 생성에 중복이 발생했습니다"),
DUPLICATE_BASE_PATH(HttpStatus.BAD_REQUEST, "기본 경로 생성에 중복이 발생했습니다"),

MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 맴버를 찾지 못했습니다"),
EXCEEDED_CAPACITY(HttpStatus.INSUFFICIENT_STORAGE, "더 이상 업로드 할 수 없습니다"),
INVALID_OPERATION(HttpStatus.BAD_REQUEST, "사용 중인 공간보다 많은 공간은 해제할 수 없습니다"),
VALIDATION_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 요청입니다."),
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 맴버를 찾지 못했습니다"),
EXCEEDED_CAPACITY(HttpStatus.INSUFFICIENT_STORAGE, "더 이상 업로드 할 수 없습니다"),
INVALID_OPERATION(HttpStatus.BAD_REQUEST, "사용 중인 공간보다 많은 공간은 해제할 수 없습니다"),
VALIDATION_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 요청입니다.");

DUPLICATE_SHARE_LINK(HttpStatus.INTERNAL_SERVER_ERROR, "링크 생성에 중복이 발생했습니다"),
NOT_FOUND_SHARE_LINK(HttpStatus.NOT_FOUND, "링크를 찾을 수 없습니다"),
NOT_FRESH_LINK(HttpStatus.BAD_REQUEST, "만료된 링크입니다.");
private final HttpStatus httpStatus;
private final String message;

private final HttpStatus httpStatus;
private final String message;
public ServiceException serviceException() {
return new ServiceException(this.name(), message);
}

public ServiceException serviceException() {
return new ServiceException(this.name(), message);
}

public ServiceException serviceException(String debugMessage, Object... debugMessageArgs) {
return new ServiceException(this.name(), message, String.format(debugMessage, debugMessageArgs));
}
public ServiceException serviceException(String debugMessage, Object... debugMessageArgs) {
return new ServiceException(this.name(), message, String.format(debugMessage, debugMessageArgs));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,50 @@
@Service
@RequiredArgsConstructor
public class FileDataHandlerService {
private final FileRepository fileRepository;

@Transactional
public void deleteBy(Long fileId) {
existBy(fileId);
fileRepository.deleteById(fileId);
}

private void existBy(Long fileId) {
if (!fileRepository.existsById(fileId)) {
throw ErrorCode.CANNOT_FOUND_FILE.serviceException("fileId : {}", fileId);
}
}

public FileMetadata findBy(Long fileId, Long userId) {
return fileRepository.findByIdAndUploaderId(fileId, userId)
.orElseThrow(() -> ErrorCode.CANNOT_FOUND_FILE.serviceException("fileId : {}, userId : {}", fileId,
userId));
}

public void persist(FileMetadata fileMetadata) {
fileRepository.save(fileMetadata);
}

public void duplicateBy(Long parentId, String fileName) {
if (fileRepository.existsByParentIdAndOriginalFileName(parentId, fileName)) {
throw ErrorCode.DUPLICATE_FILE_NAME.serviceException("fileName : {}", fileName);
}
}

public List<FileMetadata> getFileList(Long parentId, Long cursorId, Long userId, Pageable page) {
return cursorId == null ? fileRepository.findAllByParentIdAndUploaderIdOrderByIdDesc(parentId, userId, page)
: fileRepository.findByParentIdAndUploaderIdAndIdLessThanOrderByIdDesc(parentId, cursorId, userId, page);
}

public Boolean hashNext(Long parentId, Long userId, Long lastIdOfList) {
return fileRepository.existsByParentIdAndUploaderIdAndIdLessThan(parentId, userId, lastIdOfList);
}

public List<FileMetadata> findAllBy(Long parentId) {
return fileRepository.findAllByParentId(parentId);
}

public void deleteAll(List<FileMetadata> fileMetadataList) {
fileRepository.deleteAll(fileMetadataList);
}

// 파일이 삭제된 경우에는 파일 공유 링크로 다운 받을 수 없다.
public FileMetadata findBy(Long fileId) {
return fileRepository.findById(fileId).orElseThrow(ErrorCode.CANNOT_FOUND_FILE::serviceException);
}
private final FileRepository fileRepository;

@Transactional
public void deleteBy(Long fileId) {
existBy(fileId);
fileRepository.deleteById(fileId);
}

private void existBy(Long fileId) {
if (!fileRepository.existsById(fileId)) {
throw ErrorCode.CANNOT_FOUND_FILE.serviceException("fileId : {}", fileId);
}
}

public FileMetadata findBy(Long fileId, Long userId) {
return fileRepository.findByIdAndUploaderId(fileId, userId)
.orElseThrow(() -> ErrorCode.CANNOT_FOUND_FILE.serviceException("fileId : {}, userId : {}", fileId,
userId));
}

public void persist(FileMetadata fileMetadata) {
fileRepository.save(fileMetadata);
}

public void duplicateBy(Long parentId, String fileName) {
if (fileRepository.existsByParentIdAndOriginalFileName(parentId, fileName)) {
throw ErrorCode.DUPLICATE_FILE_NAME.serviceException("fileName : {}", fileName);
}
}

public List<FileMetadata> getFileList(Long parentId, Long cursorId, Long userId, Pageable page) {
return cursorId == null ? fileRepository.findAllByParentIdAndUploaderIdOrderByIdDesc(parentId, userId, page)
: fileRepository.findByParentIdAndUploaderIdAndIdLessThanOrderByIdDesc(parentId, cursorId, userId, page);
}

public Boolean hashNext(Long parentId, Long userId, Long lastIdOfList) {
return fileRepository.existsByParentIdAndUploaderIdAndIdLessThan(parentId, userId, lastIdOfList);
}

public List<FileMetadata> findAllBy(Long parentId) {
return fileRepository.findAllByParentId(parentId);
}

public void deleteAll(List<FileMetadata> fileMetadataList) {
fileRepository.deleteAll(fileMetadataList);
}
}
19 changes: 10 additions & 9 deletions src/main/java/com/c4cometrue/mystorage/file/FileRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface FileRepository extends JpaRepository<FileMetadata, Long> {
Optional<FileMetadata> findByIdAndUploaderId(Long id, Long uploaderId);
Optional<FileMetadata> findByIdAndUploaderId(Long id, Long uploaderId);

boolean existsByParentIdAndOriginalFileName(Long parentId, String fileName);
boolean existsByParentIdAndOriginalFileName(Long parentId, String fileName);

List<FileMetadata> findByParentIdAndUploaderId(Long parentId, Long userId);
List<FileMetadata> findByParentIdAndUploaderId(Long parentId, Long userId);

Boolean existsByIdAndUploaderId(Long parentId, Long userId);
Boolean existsByIdAndUploaderId(Long parentId, Long userId);

List<FileMetadata> findAllByParentIdAndUploaderIdOrderByIdDesc(Long parentId, Long uploaderId, Pageable page);
List<FileMetadata> findAllByParentIdAndUploaderIdOrderByIdDesc(Long parentId, Long uploaderId, Pageable page);

List<FileMetadata> findByParentIdAndUploaderIdAndIdLessThanOrderByIdDesc(Long parentId, Long userId, Long cursorId,
Pageable pageable);
List<FileMetadata> findByParentIdAndUploaderIdAndIdLessThanOrderByIdDesc(Long parentId, Long userId, Long cursorId,
Pageable pageable);

Boolean existsByParentIdAndUploaderIdAndIdLessThan(Long parentId, Long uploaderId, Long id);
Boolean existsByParentIdAndUploaderIdAndIdLessThan(Long parentId, Long uploaderId, Long id);

List<FileMetadata> findAllByParentId(Long parentId);
List<FileMetadata> findAllByParentId(Long parentId);
}
5 changes: 4 additions & 1 deletion src/main/java/com/c4cometrue/mystorage/file/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ protected void uploadFile(Long userId, Long rootId, BigDecimal fileSize, FileMet

public void downloadFile(Long fileId, String userPath, Long userId) {
FileMetadata fileMetadata = fileDataHandlerService.findBy(fileId, userId);
FileUtil.download(fileMetadata, userPath);
Path originalPath = Paths.get(fileMetadata.getFilePath());
Path userDesignatedPath = Paths.get(userPath).resolve(fileMetadata.getOriginalFileName()).normalize();

FileUtil.download(originalPath, userDesignatedPath, bufferSize);
}

@Transactional
Expand Down

This file was deleted.

46 changes: 0 additions & 46 deletions src/main/java/com/c4cometrue/mystorage/fileshare/FileShare.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 78f957d

Please sign in to comment.