Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
[#164] feat: WishBook LibraryBook 중복 체크 로직을 추가한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevLuffy committed May 23, 2020
1 parent d23f2f3 commit 5607ec2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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())
Expand All @@ -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);
}
}
}

0 comments on commit 5607ec2

Please sign in to comment.