diff --git a/src/main/java/com/mpnp/baechelin/bookmark/controller/FolderController.java b/src/main/java/com/mpnp/baechelin/bookmark/controller/FolderController.java index 81dde4c..12daed1 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/controller/FolderController.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/controller/FolderController.java @@ -63,7 +63,7 @@ public SuccessResponse folderUpdate (@PathVariable int folderId, @GetMapping("/folderList") public List folderList (@AuthenticationPrincipal User user){ // return folderService.folderList(user.getUsername()); - return folderService.folderListV2(user.getUsername()); + return folderService.folderList(user.getUsername()); } /** diff --git a/src/main/java/com/mpnp/baechelin/bookmark/dto/BookmarkInfoDto.java b/src/main/java/com/mpnp/baechelin/bookmark/dto/BookmarkInfoDto.java index d27e46f..6704655 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/dto/BookmarkInfoDto.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/dto/BookmarkInfoDto.java @@ -48,9 +48,6 @@ public BookmarkInfoDto(Bookmark bookmark){ if(!bookmark.getStoreId().getStoreImageList().isEmpty()) { this.storeImageList = bookmark.getStoreId().getStoreImageList().get(0).getStoreImageUrl(); - - } else if(bookmark.getStoreId().getStoreImageList().isEmpty()) { - this.storeImageList = ""; } } } diff --git a/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java b/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java index 62cd492..748af73 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java @@ -1,11 +1,14 @@ package com.mpnp.baechelin.bookmark.dto; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.mpnp.baechelin.bookmark.domain.Bookmark; import com.mpnp.baechelin.bookmark.domain.Folder; import com.mpnp.baechelin.store.domain.StoreImage; import lombok.*; +import javax.persistence.Transient; import java.util.ArrayList; import java.util.List; @@ -29,26 +32,22 @@ public static FolderResponseDto FolderDtoRes(Folder folder) { /** 북마크의 정보를 담는 작업 */ List bookmarks = new ArrayList<>(); - - if(folder.getBookmarkList() != null) { - for (Bookmark bookmark : folder.getBookmarkList()) { - BookmarkInfoDto bookmarkInfoDto = new BookmarkInfoDto(bookmark); - bookmarks.add(bookmarkInfoDto); - - } - } else if(folder.getBookmarkList() == null) { + if (folder.getBookmarkList() == null || folder.getBookmarkList().isEmpty()) { return FolderResponseDto.builder() .folderName(folder.getFolderName()) .id(folder.getId()) .thumbNail(null) .build(); } - + for (Bookmark bookmark : folder.getBookmarkList()) { + BookmarkInfoDto bookmarkInfoDto = new BookmarkInfoDto(bookmark); + bookmarks.add(bookmarkInfoDto); + } return FolderResponseDto.builder() .folderName(folder.getFolderName()) .id(folder.getId()) .bookmarkList(bookmarks) - .thumbNail(null) + .thumbNail(bookmarks.size() == 0 ? null : bookmarks.get(bookmarks.size() - 1).getStoreImageList()) .build(); } } diff --git a/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java b/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java index cc56a08..beb7704 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java @@ -83,26 +83,4 @@ public List folderList(String socialId) { } return folderResponseDtoList; } - - @Transactional(readOnly = true) - public List folderListV2(String socialId) { - User user = userRepository.findBySocialId(socialId); - if (user == null) { - throw new CustomException(ErrorCode.NO_USER_FOUND); - } - List folderResponseDtoList = new ArrayList<>(); - for (Folder obj : user.getFolderList()) { - FolderResponseDto folderResponseDto = FolderResponseDto.FolderDtoRes(obj); - // 폴더의 최신 업장 찾기 - Long latestStoreId = bookmarkRepository.findLatestStore(obj.getId()); - if (latestStoreId != null) { - Store latestStore = storeRepository.findById(latestStoreId).orElseThrow(() -> new CustomException(ErrorCode.NO_STORE_FOUND)); - Optional storeImage = latestStore.getStoreImageList().stream().findFirst(); - storeImage.ifPresent(image -> folderResponseDto.setThumbNail(image.getStoreImageUrl())); - } - folderResponseDtoList.add(folderResponseDto); - } - return folderResponseDtoList; - } - }