From 5607ec24e7a52be4e57460eb69ed537e8855fc4c Mon Sep 17 00:00:00 2001 From: thedevluffy Date: Sat, 23 May 2020 17:12:41 +0900 Subject: [PATCH] =?UTF-8?q?[#164]=20feat:=20WishBook=20LibraryBook=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=B2=B4=ED=81=AC=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/WishBookAlreadyExistException.java | 6 ++---- .../web/wishbook/service/WishBookFacade.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/exception/WishBookAlreadyExistException.java b/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/exception/WishBookAlreadyExistException.java index a2f07d9..e931782 100644 --- a/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/exception/WishBookAlreadyExistException.java +++ b/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/exception/WishBookAlreadyExistException.java @@ -5,12 +5,10 @@ @Getter public class WishBookAlreadyExistException extends RuntimeException { - private static final String DUPLICATED_WISH_BOOK_ISBN_EXCEPTION_MESSAGE = "이미 희망도서에 등록되어 있습니다."; - private final String isbn; - public WishBookAlreadyExistException(String isbn) { - super(DUPLICATED_WISH_BOOK_ISBN_EXCEPTION_MESSAGE); + public WishBookAlreadyExistException(String isbn, String message) { + super(message); this.isbn = isbn; } } diff --git a/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/service/WishBookFacade.java b/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/service/WishBookFacade.java index f728732..c8724c2 100644 --- a/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/service/WishBookFacade.java +++ b/tecobrary-core-api/src/main/java/com/woowacourse/tecobrary/web/wishbook/service/WishBookFacade.java @@ -1,5 +1,6 @@ package com.woowacourse.tecobrary.web.wishbook.service; +import com.woowacourse.tecobrary.domain.librarybook.repository.LibraryBookRepository; import com.woowacourse.tecobrary.domain.user.entity.User; import com.woowacourse.tecobrary.domain.user.repository.UserRepository; import com.woowacourse.tecobrary.web.tecorvis.api.SlackBotService; @@ -18,7 +19,11 @@ @Service public class WishBookFacade { + private static final String DUPLICATED_WISH_BOOK_ISBN_EXCEPTION_MESSAGE = "이미 희망도서에 등록되어 있습니다."; + private static final String ALREADY_ENROLLED_BOOK_EXCEPTION_MESSAGE = "이미 등록된 장서 입니다."; + private final WishBookRepository wishBookRepository; + private final LibraryBookRepository libraryBookRepository; private final UserRepository userRepository; private final WishBookConverter wishBookConverter; private final SlackBotService slackBotService; @@ -30,6 +35,10 @@ public WishBookInfoDto createWishBook(final WishBookInfoDto wishBookInfoDto) { User user = userRepository.findById(wishBookInfoDto.getUserId()) .orElseThrow(() -> new WishBookRequestUserNotFoundException(wishBookInfoDto.getUserId())); + if (libraryBookRepository.existsByIsbn(wishBookInfoDto.getIsbn())) { + throw new WishBookAlreadyExistException(wishBookInfoDto.getIsbn(), ALREADY_ENROLLED_BOOK_EXCEPTION_MESSAGE); + } + WishBook wishBook = wishBookRepository.save(WishBook.builder() .title(wishBookInfoDto.getTitle()) .image(wishBookInfoDto.getImage()) @@ -53,7 +62,7 @@ public WishBookInfoDto createWishBook(final WishBookInfoDto wishBookInfoDto) { private void checkDuplicated(final WishBookInfoDto wishBookInfoDto) { if (wishBookRepository.existsByIsbn(wishBookInfoDto.getIsbn())) { - throw new WishBookAlreadyExistException(wishBookInfoDto.getIsbn()); + throw new WishBookAlreadyExistException(wishBookInfoDto.getIsbn(), DUPLICATED_WISH_BOOK_ISBN_EXCEPTION_MESSAGE); } } }