-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/chung step2 #6
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
63bb89b
refactor: FileService 의존 관계 변화
kochungcheon b4c3d5a
feat: 폴더 생성
kochungcheon 5d81365
feat: 폴더 이름 변경
kochungcheon 70ffaa3
feat: MetadataType
kochungcheon 89e5678
feat: step2
kochungcheon af8ff26
chore: gradlew.bat 수정
kochungcheon 7732bf6
refactor: 트랜잭션 범위 및 코드 위치 변경
kochungcheon 539d0d2
refactor: 파일 조회 컨트롤러 위치 변경
kochungcheon 576e60b
refactor: Reader, Writer 제거
kochungcheon d5b94bb
refactor: FolderMetadata index 추가 및 제거 작업
kochungcheon 4149f7a
refactor: MetadataService -> StoregeFasadeService
kochungcheon 99fb8e0
chore: 오탈자 수정
kochungcheon 4986865
refactor: 유효성 검사 어노테이션 추가
kochungcheon 962485c
feat: 커서 기반 페이징 도입-
kochungcheon 15ad8be
chore : 사용하지 않는 파일 정리
kochungcheon a0fce68
test : 변경 사항에 따른 테스트 코드 추가
kochungcheon bc03dbf
chore : 코드 스멜 수정
kochungcheon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
src/main/java/com/c4cometrue/mystorage/dto/FileDeleteRequest.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/com/c4cometrue/mystorage/dto/FileDownloadRequest.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/com/c4cometrue/mystorage/dto/FileUploadRequest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/java/com/c4cometrue/mystorage/file/FileDataAccessService.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/com/c4cometrue/mystorage/file/FileDataHandlerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.c4cometrue.mystorage.file; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.c4cometrue.mystorage.exception.ErrorCode; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@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)); | ||
} | ||
|
||
@Transactional | ||
public void persist(FileMetadata fileMetadata, Long userId, Long parentId) { | ||
validateFileOwnershipBy(parentId, userId); | ||
duplicateBy(parentId, userId, fileMetadata.getOriginalFileName()); | ||
fileRepository.save(fileMetadata); | ||
} | ||
|
||
private void duplicateBy(Long parentId, Long userId, String fileName) { | ||
if (fileRepository.checkDuplicateFileName(parentId, userId, fileName)) { | ||
throw ErrorCode.DUPLICATE_FILE_NAME.serviceException("fileName : {}", fileName); | ||
} | ||
} | ||
|
||
public List<FileMetadata> findChildBy(Long parentId, Long userId) { | ||
validateFileOwnershipBy(parentId, userId); | ||
return fileRepository.findByParentIdAndUploaderId(parentId, userId); | ||
} | ||
|
||
private void validateFileOwnershipBy(Long folderId, Long userId) { | ||
if (folderId != null && !fileRepository.existsByIdAndUploaderId(folderId, userId)) { | ||
throw ErrorCode.UNAUTHORIZED_FILE_ACCESS.serviceException(); | ||
} | ||
} | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
25 changes: 17 additions & 8 deletions
25
src/main/java/com/c4cometrue/mystorage/file/FileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
package com.c4cometrue.mystorage.file; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
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<Metadata, Long> { | ||
Optional<Metadata> findByIdAndUploaderId(Long id, Long uploaderId); | ||
public interface FileRepository extends JpaRepository<FileMetadata, Long> { | ||
Optional<FileMetadata> findByIdAndUploaderId(Long id, Long uploaderId); | ||
|
||
@Query("SELECT CASE WHEN COUNT(m) > 0 " | ||
+ "THEN TRUE " | ||
+ "ELSE FALSE END " | ||
+ "FROM Metadata m " | ||
+ "WHERE m.uploaderId = :uploaderId " | ||
@Query("SELECT CASE WHEN COUNT(m) > 0 " + "THEN TRUE " + "ELSE FALSE END " + "FROM FileMetadata m " + "WHERE " | ||
+ "(m.parentId = :parentId OR (m.parentId IS NULL AND :parentId IS NULL)) " + "AND m.uploaderId = :uploaderId " | ||
+ "AND m.originalFileName = :fileName ") | ||
boolean checkDuplicateFileName(String fileName, Long uploaderId); | ||
boolean checkDuplicateFileName(Long parentId, Long uploaderId, String fileName); | ||
|
||
List<FileMetadata> findByParentIdAndUploaderId(Long parentId, Long userId); | ||
|
||
Boolean existsByIdAndUploaderId(Long parentId, Long userId); | ||
|
||
List<FileMetadata> findAllByParentIdAndUploaderIdOrderByIdDesc(Long parentId, Long uploaderId, Pageable page); | ||
|
||
List<FileMetadata> findByParentIdAndUploaderIdAndIdLessThanOrderByIdDesc(Long parentId, Long userId, Long cursorId, | ||
Pageable pageable); | ||
|
||
Boolean existsByParentIdAndUploaderIdAndIdLessThan(Long parentId, Long uploaderId, Long id); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata 컨트롤러로 인해 파일 업로드를 이동하셨군요..
그리고 메타데이터 서비스가 파일과 폴더 서비스를 다시 의존하고 있군요..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파일과 폴더 서비스에 의존성이 생기는 게 자연스러운가 생각해서
Metadata 서비스를 만들어서 의존을 관리하고자 했습니다
지금 생각해보니
네이밍이 MetadataFasade 쪽으로 됐어야 하고
파일과 폴더 사이 의존에 대해 좀 더 생각해봐야겠네요