diff --git a/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java b/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java index 6cb122d..0d2b15b 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java @@ -32,17 +32,20 @@ public class BookmarkService { private final BookmarkRepository bookmarkRepository; - private final FolderRepository folderRepository; - private final StoreRepository storeRepository; - private final UserRepository userRepository; + private final FolderRepository folderRepository; + private final StoreRepository storeRepository; + private final UserRepository userRepository; private final StoreService storeService; @Transactional public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) { // 북마크 폴더 생성하는 Flow를 따르므로 bookmarkRequestDto의 folderId는 존재 - Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(()-> new CustomException(ErrorCode.NO_FOLDER_FOUND)); - Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new CustomException(ErrorCode.NO_BOOKMARK_FOUND)); - User user = userRepository.findBySocialId(socialId); if(user == null) {throw new CustomException(ErrorCode.NO_USER_FOUND); } + Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(() -> new CustomException(ErrorCode.NO_FOLDER_FOUND)); + Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(() -> new CustomException(ErrorCode.NO_BOOKMARK_FOUND)); + User user = userRepository.findBySocialId(socialId); + if (user == null) { + throw new CustomException(ErrorCode.NO_USER_FOUND); + } Bookmark bookmark = Bookmark .builder() @@ -53,17 +56,21 @@ public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) { if (!bookmarkRepository.existsByStoreIdAndUserId(store, user)) { bookmarkRepository.save(bookmark); - storeService.updateBookmarkCnt(store,socialId); + storeService.updateBookmarkCnt(store, socialId); } } + @Transactional public void bookmarkDelete(Long storeId, String socialId) { - User user = userRepository.findBySocialId(socialId); if(user == null) { throw new CustomException(ErrorCode.NO_USER_FOUND); } - Store store = storeRepository.findById(storeId).orElseThrow(()-> new CustomException(ErrorCode.NO_STORE_FOUND)); + User user = userRepository.findBySocialId(socialId); + if (user == null) { + throw new CustomException(ErrorCode.NO_USER_FOUND); + } + Store store = storeRepository.findById(storeId).orElseThrow(() -> new CustomException(ErrorCode.NO_STORE_FOUND)); Bookmark bookmark = bookmarkRepository.findByStoreIdAndUserId(store, user).orElseThrow(() -> new CustomException(ErrorCode.NO_BOOKMARK_FOUND)); store.removeBookmark(bookmark); bookmarkRepository.delete(bookmark); - storeService.updateBookmarkCnt(store,socialId); + storeService.updateBookmarkCnt(store, socialId); } @@ -74,7 +81,7 @@ public List bookmarkTop(String socialId, Pageable pageable) { Page bookmarkPage = bookmarkRepository.findAllByUserId(user, pageable); List bookmarkList = new ArrayList<>(); - for(Bookmark bookmark: bookmarkPage){ + for (Bookmark bookmark : bookmarkPage) { BookmarkInfoDto bookmarkInfoDto = new BookmarkInfoDto(bookmark); bookmarkList.add(bookmarkInfoDto); } @@ -87,7 +94,7 @@ public BookmarkPagedResponseDto bookmarkList(String socialId, int folderId, Page if (user == null) { throw new CustomException(ErrorCode.NO_USER_FOUND); } - Folder folder = folderRepository.findById(folderId).orElseThrow(()-> new CustomException(ErrorCode.NO_FOLDER_FOUND)); + Folder folder = folderRepository.findById(folderId).orElseThrow(() -> new CustomException(ErrorCode.NO_FOLDER_FOUND)); Page pagedBookmark = bookmarkRepository.findAllByFolderId(folder, pageable); return new BookmarkPagedResponseDto(pagedBookmark); } 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 923fa28..51c3556 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java @@ -74,10 +74,24 @@ public List folderList(String socialId) { List folderResponseDtoList = new ArrayList<>(); for (Folder obj : user.getFolderList()) { FolderResponseDto folderResponseDto = FolderResponseDto.FolderDtoRes(obj); - List latestFolder = bookmarkRepository.findLatestFolder(obj.getId()); +// List latestFolder = bookmarkRepository.findLatestFolder(obj.getId()); // folderResponseDto.setThumbNail(); -// folderResponseDtoList.add(); - + folderResponseDtoList.add(folderResponseDto); + } + 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); + List latestFolder = bookmarkRepository.findLatestFolder(obj.getId()); + //TODO ThumbNail + folderResponseDtoList.add(folderResponseDto); } return folderResponseDtoList; }