From 5afa03b24bf511b0831c811330daf104db6bd07f Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Thu, 30 May 2024 22:14:38 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EA=B0=80=20=EB=B3=84=EC=A0=90=20=EB=8B=A8=EC=9D=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EC=98=88=EC=99=B8=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/rating/RatingService.java | 4 ++-- .../application/rating/RatingServiceTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jisungin/application/rating/RatingService.java b/src/main/java/com/jisungin/application/rating/RatingService.java index 56d01bd..95bf632 100644 --- a/src/main/java/com/jisungin/application/rating/RatingService.java +++ b/src/main/java/com/jisungin/application/rating/RatingService.java @@ -48,7 +48,7 @@ public RatingCreateResponse creatingRating(Long userId, RatingCreateServiceReque public RatingGetOneResponse getRating(Long userId, String isbn) { User user = userRepository.findById(userId) - .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); + .orElse(null); Book book = bookRepository.findById(isbn) .orElseThrow(() -> new BusinessException(ErrorCode.BOOK_NOT_FOUND)); @@ -56,7 +56,7 @@ public RatingGetOneResponse getRating(Long userId, String isbn) { Rating rating = ratingRepository.findRatingByUserAndBook(user, book) .orElse(null); - if (rating == null) { + if (rating == null || user == null) { return RatingGetOneResponse.of(null, null, book.getIsbn()); } diff --git a/src/test/java/com/jisungin/application/rating/RatingServiceTest.java b/src/test/java/com/jisungin/application/rating/RatingServiceTest.java index d8c5d98..1b0cb5a 100644 --- a/src/test/java/com/jisungin/application/rating/RatingServiceTest.java +++ b/src/test/java/com/jisungin/application/rating/RatingServiceTest.java @@ -118,6 +118,21 @@ void getRatingWithEmpty() { assertThat(result.getIsbn()).isEqualTo(book.getIsbn()); } + @DisplayName("게스트가 책의 별점을 조회한다.") + @Test + void getRatingWithGuest() { + //given + Book book = bookRepository.save(createBook("제목1", "내용1", "1234")); + + //when + RatingGetOneResponse result = ratingService.getRating(-1L, book.getIsbn()); + + //then + assertThat(result.getId()).isNull(); + assertThat(result.getRating()).isNull(); + assertThat(result.getIsbn()).isEqualTo(book.getIsbn()); + } + @DisplayName("유저가 별점을 수정한다.") @Test void updateRating() {