From de1b059ba949da113c8f8d09bdd35feddeb7f46e Mon Sep 17 00:00:00 2001 From: kcc Date: Tue, 6 Feb 2024 21:14:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=ED=8C=8C=EC=9D=BC/=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storage/StorageFacadeService.java | 22 ++++--------- .../c4cometrue/mystorage/TestConstants.java | 20 +++--------- .../storage/StorageFacadeServiceTest.java | 31 +++++++------------ 3 files changed, 23 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/c4cometrue/mystorage/storage/StorageFacadeService.java b/src/main/java/com/c4cometrue/mystorage/storage/StorageFacadeService.java index 97475b4..b1d657d 100644 --- a/src/main/java/com/c4cometrue/mystorage/storage/StorageFacadeService.java +++ b/src/main/java/com/c4cometrue/mystorage/storage/StorageFacadeService.java @@ -21,31 +21,24 @@ public class StorageFacadeService { private final FolderService folderService; private final FileService fileService; - public CursorMetaRes getFolderContents(Long parentId, Long cursorId, Long userId, Integer size, - boolean cursorFlag) { + public CursorMetaRes getFolderContents(Long parentId, Long cursorId, Long userId, Integer size, boolean cursorFlag) { Integer contentsSize = PagingUtil.calculateSize(size); - - return cursorFlag - ? handleFolderFirstStrategy(parentId, cursorId, userId, contentsSize) - : handleFileFirstStrategy(parentId, cursorId, userId, contentsSize); + return cursorFlag ? handleFolderFirstStrategy(parentId, cursorId, userId, contentsSize) : handleFileFirstStrategy(parentId, cursorId, userId, contentsSize); } - private CursorMetaRes handleFolderFirstStrategy(Long parentId, Long cursorId, Long userId, - Integer contentsSize) { + private CursorMetaRes handleFolderFirstStrategy(Long parentId, Long cursorId, Long userId, Integer contentsSize) { Pageable page = PagingUtil.createPageable(contentsSize); CursorFolderResponse cursorFolderResponse = folderService.getFolders(parentId, cursorId, userId, page); if (Boolean.FALSE.equals(cursorFolderResponse.folderHasNext())) { - Pageable remainPage = PagingUtil.createPageable( - contentsSize - cursorFolderResponse.folderMetadata().size()); + Pageable remainPage = PagingUtil.createPageable(contentsSize - cursorFolderResponse.folderMetadata().size()); CursorFileResponse cursorFileResponse = fileService.getFiles(parentId, null, userId, remainPage); return CursorMetaRes.of(cursorFolderResponse, cursorFileResponse); } return CursorMetaRes.of(cursorFolderResponse, new CursorFileResponse(null, false)); } - private CursorMetaRes handleFileFirstStrategy(Long parentId, Long cursorId, Long userId, - Integer contentsSize) { + private CursorMetaRes handleFileFirstStrategy(Long parentId, Long cursorId, Long userId, Integer contentsSize) { Pageable page = PagingUtil.createPageable(contentsSize); CursorFileResponse cursorFileResponse = fileService.getFiles(parentId, cursorId, userId, page); return CursorMetaRes.of(CursorFolderResponse.of(null, false), cursorFileResponse); @@ -61,20 +54,17 @@ public void deleteFolderContents(long folderId, long userId) { deleteFolderContents(folderMetadata); } - // softDelete + // hardDelete private void deleteFolderContents(FolderMetadata folderMetadata) { // 삭제 할 폴더리스트 조회 List folderMetadataList = folderService.findAllBy(folderMetadata.getId()); // 삭제 할 파일리스트 조회 List fileMetadataList; fileMetadataList = fileService.findAllBy(folderMetadata.getId()); - - // 파일 일괄 삭제 softDelete fileService.deleteAll(fileMetadataList); // 재귀적으로 폴더 삭제 folderMetadataList.forEach(this::deleteFolderContents); - folderService.deleteFolder(folderMetadata); } } diff --git a/src/test/java/com/c4cometrue/mystorage/TestConstants.java b/src/test/java/com/c4cometrue/mystorage/TestConstants.java index 5e002f7..34adea6 100644 --- a/src/test/java/com/c4cometrue/mystorage/TestConstants.java +++ b/src/test/java/com/c4cometrue/mystorage/TestConstants.java @@ -1,16 +1,13 @@ package com.c4cometrue.mystorage; -import java.nio.file.Path; -import java.nio.file.Paths; - +import com.c4cometrue.mystorage.file.FileMetadata; +import com.c4cometrue.mystorage.folder.FolderMetadata; +import com.c4cometrue.mystorage.folder.dto.FolderNameChangeRequest; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; -import com.c4cometrue.mystorage.common.MetadataType; -import com.c4cometrue.mystorage.deletedmetadata.DeletedMetadata; -import com.c4cometrue.mystorage.folder.dto.FolderNameChangeRequest; -import com.c4cometrue.mystorage.file.FileMetadata; -import com.c4cometrue.mystorage.folder.FolderMetadata; +import java.nio.file.Path; +import java.nio.file.Paths; public class TestConstants { public static final Long USER_ID = 1L; @@ -48,11 +45,4 @@ public class TestConstants { public static final Long FOLDER_ID = 1L; public static final FolderNameChangeRequest FOLDER_NAME_CHANGE_REQUEST = FolderNameChangeRequest.of(USER_ID, FOLDER_ID, USER_FOLDER_NAME); - - public static final DeletedMetadata DELETE_METADATA = DeletedMetadata.builder() - .type(MetadataType.FILE) - .filePath(PARENT_PATH) - .parentId(PARENT_ID) - .userId(USER_ID) - .build(); } diff --git a/src/test/java/com/c4cometrue/mystorage/storage/StorageFacadeServiceTest.java b/src/test/java/com/c4cometrue/mystorage/storage/StorageFacadeServiceTest.java index 07e86a0..ed57ff7 100644 --- a/src/test/java/com/c4cometrue/mystorage/storage/StorageFacadeServiceTest.java +++ b/src/test/java/com/c4cometrue/mystorage/storage/StorageFacadeServiceTest.java @@ -1,29 +1,23 @@ package com.c4cometrue.mystorage.storage; -import static com.c4cometrue.mystorage.TestConstants.*; -import static org.mockito.BDDMockito.*; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.c4cometrue.mystorage.deletedmetadata.DeleteMetadataService; -import com.c4cometrue.mystorage.file.FileMetadata; import com.c4cometrue.mystorage.file.FileService; import com.c4cometrue.mystorage.file.dto.CursorFileResponse; import com.c4cometrue.mystorage.file.dto.FileContent; -import com.c4cometrue.mystorage.folder.FolderMetadata; import com.c4cometrue.mystorage.folder.FolderService; import com.c4cometrue.mystorage.folder.dto.CursorFolderResponse; import com.c4cometrue.mystorage.folder.dto.FolderContent; import com.c4cometrue.mystorage.util.PagingUtil; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static com.c4cometrue.mystorage.TestConstants.*; +import static org.mockito.BDDMockito.*; @ExtendWith(MockitoExtension.class) @DisplayName("스토리지 파사드 서비스 테스트") @@ -34,8 +28,7 @@ class StorageFacadeServiceTest { private FolderService folderService; @Mock private FileService fileService; - @Mock - private DeleteMetadataService deleteMetadataService; + @Test @DisplayName("폴더조회테스트 flag가 true 일때") void getFolderContentsTrueTest() {