Skip to content

Commit

Permalink
Merge pull request #59 from Beyond-B/refactor/58-book-recommend
Browse files Browse the repository at this point in the history
♻️ [Refactor]: 책 추천 API 수정
  • Loading branch information
jinuklee777 authored Feb 16, 2024
2 parents ddff264 + 471ccc8 commit 2e4b7bd
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public BookResponseDTO.DetailBookDTO getDetailBook(User user, Long bookId) {
}

@Override
@Transactional
public Book recommendBook(Emotion emotion, User user) {
Feeling feeling = feelingRepository.findByEmotion(emotion);
List<Book> books = bookRepository.findAllByFeeling(feeling);
Expand All @@ -114,6 +115,8 @@ public Book recommendBook(Emotion emotion, User user) {

Book recommendedBook = findBookByAge(books, age, readBookIds);
if (recommendedBook != null) {
UserBook userBook = UserBook.builder().book(recommendedBook).user(user).build();
userBookRepository.save(userBook);
return recommendedBook;
}

Expand All @@ -135,6 +138,8 @@ public Book recommendBook(Emotion emotion, User user) {
if (recommendedBook == null) {
throw new BookException(ErrorStatus.BOOK_EMOTION_NOT_EXIST);
}
UserBook userBook = UserBook.builder().book(recommendedBook).user(user).build();
userBookRepository.save(userBook);
return recommendedBook;
}

Expand Down

0 comments on commit 2e4b7bd

Please sign in to comment.