diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java index 0255c0e..51bbd94 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/controller/PostsController.java @@ -132,6 +132,15 @@ public BaseResponse reviewPostController(@PathVa } return new BaseResponse<>(postsService.DoReviewPostService(postId,userId,request)); } + @Operation(summary = "리뷰조회",description = "리뷰 조회") + @GetMapping("/reviews/{postId}") + public BaseResponse getReviewsController(@PathVariable(value="postId",required = true)String postId){ + String userId = ""; + if(MDC.get(JWTUtil.MDC_USER_ID) != null) { + userId= MDC.get(JWTUtil.MDC_USER_ID).toString(); + } + return new BaseResponse<>(postsService.ViewReviewService(userId,postId)); + } @Operation(summary="해당 게시물 불가능한 날짜 조회",description = "해당 게시물의 불가능한 날짜 조회를 합니다. owner : 게시물을 등록할 때 작성한 게시물 대여 불가 기간입니다. user : 해당 채팅방에서, 논의중인 대여기간입니다. ") @GetMapping("/{postId}/blocked") public BaseResponse blockPostController(@PathVariable(value = "postId",required = true)String postId){ diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java index 349f1ea..831e18d 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/converter/PostsConverter.java @@ -84,6 +84,20 @@ public static PostsResponse.Post toPost(ItemsJpaEntity item, ItemsBorrowJpaEntit public static PostsResponse.ViewAllResultResponse toViewAllList(List posts){ return PostsResponse.ViewAllResultResponse.builder().result(posts).build(); } + public static PostsResponse.ReviewResponse toReview(ItemsReviewJpaEntity review){ + return PostsResponse.ReviewResponse.builder() + .reviewId(review.getId()) + .content(review.getContent()) + .reviewDate(review.getCreatedAt().format(DATE_TIME_FORMATTER)) + .rating(review.getRating()) + .UserId(review.getUser().getUserId()) + .UserName(review.getUser().getNickname()) + .UserProfile(review.getUser().getProfile()) + .build(); + } + public static PostsResponse.ReviewsResponse toReviews(List reviews){ + return PostsResponse.ReviewsResponse.builder().reviews(reviews).build(); + } public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem, String status,UserJpaEntity user){ return PostsResponse.ViewPostResponse.builder() .postId(item.getId()) diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java index b11d33e..aa4a2df 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/response/PostsResponse.java @@ -98,4 +98,22 @@ public static class ReviewIdResponse{ private String itemId; private String reviewId; } + @Getter + @Setter + @Builder + public static class ReviewResponse{ + private String reviewId; + private String content; + private String reviewDate; + private int rating; + private String UserId; + private String UserName; + private String UserProfile; + } + @Getter + @Setter + @Builder + public static class ReviewsResponse{ + private List reviews; + } } diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java index 652eab3..05fade9 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java @@ -28,4 +28,5 @@ public interface PostsService { PostsResponse.BillAcceptResponse DoBillAcceptService(String userId, PostsRequest.BillAcceptRequest request); + PostsResponse.ReviewsResponse ViewReviewService(String userId, String postId); } diff --git a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java index 7b8bcb7..5b33583 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsServiceImpl.java @@ -259,7 +259,7 @@ public PostsResponse.BillAcceptResponse DoBillAcceptService(String userId, Posts throw new CustomException(ErrorCode.BadRequest, "올바른 게시물 아이디가 아닙니다.", HttpStatus.BAD_REQUEST); } if(user == item.getOwner()){ - throw new CustomException(ErrorCode.BadRequest, "자기 자신의 게시물을 거리할 수는 없습니다.", HttpStatus.BAD_REQUEST); + throw new CustomException(ErrorCode.BadRequest, "자기 자신의 게시물을 거래할 수는 없습니다.", HttpStatus.BAD_REQUEST); } BorrowHistJpaEntity borrowHist = PostsConverter.toBorrowHist(item,user,request); BorrowHistJpaEntity savedBorrowHist=borrowHistRepository.save(borrowHist); @@ -276,6 +276,19 @@ public PostsResponse.BillAcceptResponse DoBillAcceptService(String userId, Posts } + public PostsResponse.ReviewsResponse ViewReviewService(String userId, String postId){ + + ItemsJpaEntity item = itemsRepository.findById(postId).orElse(null); + List itemReviews= itemsReivewRepository.findAllByItemsOrderByCreatedAtDesc(item); + + + + List reviews=itemReviews.stream().map(itemReview->{ + return PostsConverter.toReview(itemReview); + }).toList(); + + return PostsConverter.toReviews(reviews); + } diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java index ae158bc..7207dce 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java @@ -1,8 +1,13 @@ package site.billbill.apiserver.repository.borrowPosts; import org.springframework.data.jpa.repository.JpaRepository; +import site.billbill.apiserver.model.post.ItemsJpaEntity; import site.billbill.apiserver.model.post.ItemsReviewJpaEntity; +import java.util.List; + public interface ItemsReivewRepository extends JpaRepository { + List findAllByItemsOrderByCreatedAtDesc(ItemsJpaEntity item); + }