From 0bf2d80c31058654a0af2262807a046b351d5d81 Mon Sep 17 00:00:00 2001 From: Dayun Lee Date: Fri, 23 Aug 2024 20:21:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feature]=20=EC=B1=85=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EA=B0=92=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/BookListService/BookListService.java | 2 +- .../BookListService/BookListServiceImpl.java | 16 ++++++++++------ .../web/controller/BookListRestController.java | 6 +++--- .../web/dto/request/BookListRequestDTO.java | 8 ++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/umc/server/service/BookListService/BookListService.java b/src/main/java/com/umc/server/service/BookListService/BookListService.java index a397226..9a2e595 100644 --- a/src/main/java/com/umc/server/service/BookListService/BookListService.java +++ b/src/main/java/com/umc/server/service/BookListService/BookListService.java @@ -22,7 +22,7 @@ BookList updateBookList( Optional getBookList(Long id); - void deleteBookList(Long bookListId); + void deleteBookList(BookListRequestDTO.DeleteBookListDTO request); List getLibraryBookList(Integer page, Member member); diff --git a/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java b/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java index ca2d65f..3ff5987 100644 --- a/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java +++ b/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java @@ -147,12 +147,16 @@ public Optional getBookList(Long id) { // 책리스트 삭제 @Override - public void deleteBookList(Long bookListId) { - BookList bookList = - bookListRepository - .findById(bookListId) - .orElseThrow(() -> new BookListHandler(ErrorStatus.BOOKLIST_NOT_FOUND)); - bookListRepository.delete(bookList); + public void deleteBookList(BookListRequestDTO.DeleteBookListDTO request) { + List bookListIds = request.getBookListId(); + + List bookLists = bookListRepository.findAllById(bookListIds); + + if (bookLists.size() != bookListIds.size()) { + throw new BookListHandler(ErrorStatus.BOOKLIST_NOT_FOUND); + } + + bookListRepository.deleteAll(bookLists); } @Override diff --git a/src/main/java/com/umc/server/web/controller/BookListRestController.java b/src/main/java/com/umc/server/web/controller/BookListRestController.java index b23753f..be587be 100644 --- a/src/main/java/com/umc/server/web/controller/BookListRestController.java +++ b/src/main/java/com/umc/server/web/controller/BookListRestController.java @@ -73,9 +73,9 @@ public ApiResponse updateBookList( @Operation(summary = "책리스트 삭제 API", description = "책리스트를 삭제하는 API입니다.") @DeleteMapping("list/{bookListId}") - @Parameter(name = "bookListId", description = "책리스트의 아이디, path variable 입니다!") - public ApiResponse deleteBookList(@PathVariable(name = "bookListId") Long bookListId) { - bookListService.deleteBookList(bookListId); + public ApiResponse deleteBookList( + @RequestBody @Valid BookListRequestDTO.DeleteBookListDTO request) { + bookListService.deleteBookList(request); return ApiResponse.onSuccess("삭제에 성공하였습니다!"); } diff --git a/src/main/java/com/umc/server/web/dto/request/BookListRequestDTO.java b/src/main/java/com/umc/server/web/dto/request/BookListRequestDTO.java index 2894d94..02af8a7 100644 --- a/src/main/java/com/umc/server/web/dto/request/BookListRequestDTO.java +++ b/src/main/java/com/umc/server/web/dto/request/BookListRequestDTO.java @@ -42,6 +42,14 @@ public static class UpdateBookListDTO { @NotEmpty private List books; } + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class DeleteBookListDTO { + @NotEmpty private List bookListId; + } + @Getter @Builder @NoArgsConstructor From a26a517f00b9e1f8e156cafc802a2b146250bbb5 Mon Sep 17 00:00:00 2001 From: Dayun Lee Date: Fri, 23 Aug 2024 22:45:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[fix]=20=EA=B2=BD=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/server/web/controller/BookListRestController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/umc/server/web/controller/BookListRestController.java b/src/main/java/com/umc/server/web/controller/BookListRestController.java index be587be..7b0bbac 100644 --- a/src/main/java/com/umc/server/web/controller/BookListRestController.java +++ b/src/main/java/com/umc/server/web/controller/BookListRestController.java @@ -72,7 +72,7 @@ public ApiResponse updateBookList( } @Operation(summary = "책리스트 삭제 API", description = "책리스트를 삭제하는 API입니다.") - @DeleteMapping("list/{bookListId}") + @DeleteMapping("list") public ApiResponse deleteBookList( @RequestBody @Valid BookListRequestDTO.DeleteBookListDTO request) { bookListService.deleteBookList(request); From 5f300a1bec63922542d0a517715b77b7476fd08f Mon Sep 17 00:00:00 2001 From: Dayun Lee Date: Fri, 23 Aug 2024 23:22:26 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=20=EC=B1=85=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20=ED=83=80=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EC=82=AD=EC=A0=9C=20=ED=8F=AC=ED=95=A8?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookListService/BookListService.java | 2 +- .../BookListService/BookListServiceImpl.java | 39 +++++++++++++++---- .../controller/BookListRestController.java | 7 +++- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/umc/server/service/BookListService/BookListService.java b/src/main/java/com/umc/server/service/BookListService/BookListService.java index 9a2e595..f2f273d 100644 --- a/src/main/java/com/umc/server/service/BookListService/BookListService.java +++ b/src/main/java/com/umc/server/service/BookListService/BookListService.java @@ -22,7 +22,7 @@ BookList updateBookList( Optional getBookList(Long id); - void deleteBookList(BookListRequestDTO.DeleteBookListDTO request); + void deleteBookList(BookListRequestDTO.DeleteBookListDTO request, Member member); List getLibraryBookList(Integer page, Member member); diff --git a/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java b/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java index 3ff5987..5a9d4dc 100644 --- a/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java +++ b/src/main/java/com/umc/server/service/BookListService/BookListServiceImpl.java @@ -147,16 +147,41 @@ public Optional getBookList(Long id) { // 책리스트 삭제 @Override - public void deleteBookList(BookListRequestDTO.DeleteBookListDTO request) { + public void deleteBookList(BookListRequestDTO.DeleteBookListDTO request, Member member) { List bookListIds = request.getBookListId(); + Long memberId = member.getId(); - List bookLists = bookListRepository.findAllById(bookListIds); - - if (bookLists.size() != bookListIds.size()) { - throw new BookListHandler(ErrorStatus.BOOKLIST_NOT_FOUND); + for (Long bookListId : bookListIds) { + // 책 리스트를 조회 + BookList bookList = + bookListRepository + .findById(bookListId) + .orElseThrow(() -> new BookListHandler(ErrorStatus.BOOKLIST_NOT_FOUND)); + + // 해당 책 리스트가 본인의 것인지 확인 + if (bookList.getMember().getId().equals(memberId)) { + // 본인의 책 리스트일 경우 삭제 + bookListRepository.delete(bookList); + } else { + // 타 사용자의 책 리스트일 경우 보관함에서 삭제 + MemberBookList memberBookList = + memberBookListRepository + .findByBookListIdAndMemberId(bookListId, memberId) + .orElse(null); + + if (memberBookList == null) { + throw new BookListHandler(ErrorStatus.BOOKLIST_NOT_FOUND); + } + + if (memberBookList.getIsLiked().equals(Boolean.FALSE)) { + memberBookListRepository.delete(memberBookList); + } else { + // 좋아요 표시가 되어 있으면 보관함에서만 비활성화 + memberBookList.setIsStored(false); + memberBookListRepository.save(memberBookList); + } + } } - - bookListRepository.deleteAll(bookLists); } @Override diff --git a/src/main/java/com/umc/server/web/controller/BookListRestController.java b/src/main/java/com/umc/server/web/controller/BookListRestController.java index 8ed9252..9e323e0 100644 --- a/src/main/java/com/umc/server/web/controller/BookListRestController.java +++ b/src/main/java/com/umc/server/web/controller/BookListRestController.java @@ -74,8 +74,11 @@ public ApiResponse updateBookList( @Operation(summary = "책리스트 삭제 API", description = "책리스트를 삭제하는 API입니다.") @DeleteMapping("list") public ApiResponse deleteBookList( - @RequestBody @Valid BookListRequestDTO.DeleteBookListDTO request) { - bookListService.deleteBookList(request); + @Parameter(hidden = true) @AuthenticationPrincipal Member signInmember, + @RequestParam List bookListIds) { + BookListRequestDTO.DeleteBookListDTO request = + BookListRequestDTO.DeleteBookListDTO.builder().bookListId(bookListIds).build(); + bookListService.deleteBookList(request, signInmember); return ApiResponse.onSuccess("삭제에 성공하였습니다!"); }