From 13ebd4b1de517b24f4675c55c4f2637a49cf01c8 Mon Sep 17 00:00:00 2001 From: phonil Date: Thu, 11 Jan 2024 18:46:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FIX]:=20=EC=A0=84=EC=8B=9C=20=EA=B3=B5?= =?UTF-8?q?=EA=B0=84=20=EA=B2=80=EC=83=89,=20=EA=B0=90=EC=83=81=ED=8F=89?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EC=97=AC=EB=B6=80=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/application/AlarmService.java | 2 +- .../place/application/PlaceService.java | 6 ++--- .../place/converter/PlaceConverter.java | 23 +++---------------- .../domain/repository/PlaceRepository.java | 2 -- .../domain/place/dto/PlaceResponseDto.java | 17 ++------------ .../place/presentation/PlaceController.java | 2 +- .../review/application/ReviewService.java | 15 ++++++++++-- .../domain/repository/ReviewRepository.java | 4 ++-- .../domain/review/dto/ReviewResponseDto.java | 3 +++ 9 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java b/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java index 4116167..b68404a 100644 --- a/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java +++ b/src/main/java/depth/jeonsilog/domain/alarm/application/AlarmService.java @@ -63,7 +63,7 @@ public ResponseEntity getActivityAlarmList(Integer page, UserPrincipal userPr User findUser = userService.validateUserByToken(userPrincipal); List types = Arrays.asList(AlarmType.RATING, AlarmType.REVIEW, AlarmType.REPLY, AlarmType.FOLLOW); - PageRequest pageRequest = PageRequest.of(page, 20, Sort.by(Sort.Direction.DESC, "modifiedDate")); + PageRequest pageRequest = PageRequest.of(page, 20, Sort.by(Sort.Direction.DESC, "createdDate")); Slice alarmPage = alarmRepository.findSliceByUserIdAndAlarmTypeIn(pageRequest, findUser.getId(), types); List alarmList = alarmPage.getContent(); diff --git a/src/main/java/depth/jeonsilog/domain/place/application/PlaceService.java b/src/main/java/depth/jeonsilog/domain/place/application/PlaceService.java index d9f509b..61ded96 100644 --- a/src/main/java/depth/jeonsilog/domain/place/application/PlaceService.java +++ b/src/main/java/depth/jeonsilog/domain/place/application/PlaceService.java @@ -63,11 +63,11 @@ public ResponseEntity searchPlaces(Integer page, String searchWord) { DefaultAssert.isTrue(!places.isEmpty(), "해당 검색어를 포함한 전시 공간이 존재하지 않습니다."); - List searchPlaceResList = PlaceConverter.toSearchPlaceListRes(places); + List placeInfoListRes = PlaceConverter.toPlaceInfoListRes(places); boolean hasNextPage = placePage.hasNext(); - PlaceResponseDto.SearchPlaceResWithPaging searchPlaceResWithPaging = PlaceConverter.toSearchPlaceResWithPaging(hasNextPage, searchPlaceResList); + PlaceResponseDto.PlaceInfoResWithPaging placeInfoResWithPaging = PlaceConverter.toPlaceInfoResWithPaging(hasNextPage, placeInfoListRes); - ApiResponse apiResponse = ApiResponse.toApiResponse(searchPlaceResWithPaging); + ApiResponse apiResponse = ApiResponse.toApiResponse(placeInfoResWithPaging); return ResponseEntity.ok(apiResponse); } diff --git a/src/main/java/depth/jeonsilog/domain/place/converter/PlaceConverter.java b/src/main/java/depth/jeonsilog/domain/place/converter/PlaceConverter.java index 7a8ff0c..65f6638 100644 --- a/src/main/java/depth/jeonsilog/domain/place/converter/PlaceConverter.java +++ b/src/main/java/depth/jeonsilog/domain/place/converter/PlaceConverter.java @@ -37,27 +37,10 @@ public static List toPlaceInfoListRes(List return placeInfoResList; } - // Places -> SearchPlaceResList - public static List toSearchPlaceListRes(List places) { - - List searchPlaceResList = new ArrayList<>(); - - for (Place place : places) { - PlaceResponseDto.SearchPlaceRes searchPlaceRes = PlaceResponseDto.SearchPlaceRes.builder() - .placeId(place.getId()) - .placeName(place.getName()) - .build(); - - searchPlaceResList.add(searchPlaceRes); - } - - return searchPlaceResList; - } - - public static PlaceResponseDto.SearchPlaceResWithPaging toSearchPlaceResWithPaging(boolean hasNextPage, List searchPlaceResList) { - return PlaceResponseDto.SearchPlaceResWithPaging.builder() + public static PlaceResponseDto.PlaceInfoResWithPaging toPlaceInfoResWithPaging(boolean hasNextPage, List placeInfoResList) { + return PlaceResponseDto.PlaceInfoResWithPaging.builder() .hasNextPage(hasNextPage) - .data(searchPlaceResList) + .data(placeInfoResList) .build(); } diff --git a/src/main/java/depth/jeonsilog/domain/place/domain/repository/PlaceRepository.java b/src/main/java/depth/jeonsilog/domain/place/domain/repository/PlaceRepository.java index 3f33b4b..3b9e993 100644 --- a/src/main/java/depth/jeonsilog/domain/place/domain/repository/PlaceRepository.java +++ b/src/main/java/depth/jeonsilog/domain/place/domain/repository/PlaceRepository.java @@ -16,7 +16,5 @@ public interface PlaceRepository extends JpaRepository { Optional findByAddress(String placeAddr); - Page findByNameContainingOrAddressContaining(Pageable pageable, String searchWord, String searchWord2); - Slice findSliceByNameContainingOrAddressContaining(Pageable pageable, String searchWord, String searchWord2); } diff --git a/src/main/java/depth/jeonsilog/domain/place/dto/PlaceResponseDto.java b/src/main/java/depth/jeonsilog/domain/place/dto/PlaceResponseDto.java index 44a6165..03c436d 100644 --- a/src/main/java/depth/jeonsilog/domain/place/dto/PlaceResponseDto.java +++ b/src/main/java/depth/jeonsilog/domain/place/dto/PlaceResponseDto.java @@ -45,27 +45,14 @@ public static class PlaceInfoRes { private String placeAddress; } - // 검색어를 포함한 전시 공간 목록 조회 @Data @Builder - public static class SearchPlaceRes { - - @Schema(type = "Long", example = "1", description = "전시 공간 ID입니다.") - private Long placeId; - - @Schema(type = "String", example = "롯데콘서트홀", description = "전시 공간 이름입니다.") - private String placeName; - - } - - @Data - @Builder - public static class SearchPlaceResWithPaging { + public static class PlaceInfoResWithPaging { @Schema(type = "boolean", example = "true", description = "다음 페이지 존재 여부를 반환합니다.") private boolean hasNextPage; - private List data; + private List data; } diff --git a/src/main/java/depth/jeonsilog/domain/place/presentation/PlaceController.java b/src/main/java/depth/jeonsilog/domain/place/presentation/PlaceController.java index 774a1ae..f73e46f 100644 --- a/src/main/java/depth/jeonsilog/domain/place/presentation/PlaceController.java +++ b/src/main/java/depth/jeonsilog/domain/place/presentation/PlaceController.java @@ -44,7 +44,7 @@ public ResponseEntity findExhibitionListInPlace( // TODO : 논의 후 페이징 처리 @Operation(summary = "검색어를 포함한 전시 공간의 목록 조회", description = "전시 공간을 검색합니다.") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = PlaceResponseDto.SearchPlaceResWithPaging.class))}), + @ApiResponse(responseCode = "200", description = "조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = PlaceResponseDto.PlaceInfoResWithPaging.class))}), @ApiResponse(responseCode = "400", description = "조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), }) @GetMapping("/search/{searchWord}") diff --git a/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java b/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java index 46a011d..5c4b938 100644 --- a/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java +++ b/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java @@ -162,8 +162,19 @@ public ResponseEntity checkIsWrite(UserPrincipal userPrincipal, Long exhibiti Optional findExhibition = exhibitionRepository.findById(exhibitionId); DefaultAssert.isTrue(findExhibition.isPresent(), "전시회 정보가 올바르지 않습니다."); - Boolean isWrite = reviewRepository.existsByUserIdAndExhibitionId(findUser.getId(), exhibitionId); - ReviewResponseDto.CheckIsWriteRes responseDto = ReviewResponseDto.CheckIsWriteRes.builder().isWrite(isWrite).build(); + Optional findReview = reviewRepository.findByUserIdAndExhibitionId(findUser.getId(), exhibitionId); + Boolean isWrite = false; + String contents = ""; + if (findReview.isPresent()) { + isWrite = true; + contents = findReview.get().getContents(); + } else { + contents = null; + } + ReviewResponseDto.CheckIsWriteRes responseDto = ReviewResponseDto.CheckIsWriteRes.builder() + .isWrite(isWrite) + .contents(contents) + .build(); ApiResponse apiResponse = ApiResponse.toApiResponse(responseDto); return ResponseEntity.ok(apiResponse); } diff --git a/src/main/java/depth/jeonsilog/domain/review/domain/repository/ReviewRepository.java b/src/main/java/depth/jeonsilog/domain/review/domain/repository/ReviewRepository.java index 549fb9d..1155b77 100644 --- a/src/main/java/depth/jeonsilog/domain/review/domain/repository/ReviewRepository.java +++ b/src/main/java/depth/jeonsilog/domain/review/domain/repository/ReviewRepository.java @@ -1,6 +1,5 @@ package depth.jeonsilog.domain.review.domain.repository; -import depth.jeonsilog.domain.reply.domain.Reply; import depth.jeonsilog.domain.review.domain.Review; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -9,13 +8,14 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface ReviewRepository extends JpaRepository { List findAllByUserId(Long userId); - Boolean existsByUserIdAndExhibitionId(Long userId, Long exhibitionId); + Optional findByUserIdAndExhibitionId(Long userId, Long exhibitionId); Page findByUserId(PageRequest pageRequest, Long userId); diff --git a/src/main/java/depth/jeonsilog/domain/review/dto/ReviewResponseDto.java b/src/main/java/depth/jeonsilog/domain/review/dto/ReviewResponseDto.java index da11831..301a226 100644 --- a/src/main/java/depth/jeonsilog/domain/review/dto/ReviewResponseDto.java +++ b/src/main/java/depth/jeonsilog/domain/review/dto/ReviewResponseDto.java @@ -92,6 +92,9 @@ public static class CheckIsWriteRes { @Schema(type = "boolean", example = "true", description = "해당 전시회 - 감상평 작성 여부를 출력합니다.") private Boolean isWrite; + + @Schema(type = "string", example = "멋진 전시였다.", description = "감상평을 출력합니다. isWrite = false 시 contents = null.") + private String contents; } } From d56a3f6446101a86ec5e7d0f1896eb9b7c7b77f1 Mon Sep 17 00:00:00 2001 From: phonil Date: Thu, 11 Jan 2024 21:29:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]:=20Reveiw=20ID=EB=A1=9C=20Review=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20rating=20=EA=B4=80=EB=A0=A8=20null=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/application/ReviewService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java b/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java index 5c4b938..7f94eee 100644 --- a/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java +++ b/src/main/java/depth/jeonsilog/domain/review/application/ReviewService.java @@ -185,8 +185,13 @@ public ResponseEntity getReview(Long reviewId) { Review review = validateReviewById(reviewId); User user = review.getUser(); Exhibition exhibition = review.getExhibition(); - Rating rating = ratingService.validateRatingByUserIdAndExhibitionId(user.getId(), exhibition.getId()); - Double rate = rating.getRate(); + + Optional findRating = ratingRepository.findByUserIdAndExhibitionId(user.getId(), exhibition.getId()); + Double rate = null; + if (findRating.isPresent()) { + Rating rating = findRating.get(); + rate = rating.getRate(); + } UserResponseDto.SearchUsersRes userRes = UserConverter.toSearchUserRes(user); ReviewResponseDto.ReviewListRes reviewRes = ReviewConverter.toReviewListRes(review, userRes, rate);