Skip to content

Commit

Permalink
Merge pull request #83 from billbill-project/feature/borrowPosts
Browse files Browse the repository at this point in the history
[feat] 리뷰조회
  • Loading branch information
jainefer authored Dec 17, 2024
2 parents 3e11ac5 + 658c0ff commit 8ee1794
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public BaseResponse<PostsResponse.ReviewIdResponse> reviewPostController(@PathVa
}
return new BaseResponse<>(postsService.DoReviewPostService(postId,userId,request));
}
@Operation(summary = "리뷰조회",description = "리뷰 조회")
@GetMapping("/reviews/{postId}")
public BaseResponse<PostsResponse.ReviewsResponse> 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<PostsResponse.NoRentalPeriodsResponse> blockPostController(@PathVariable(value = "postId",required = true)String postId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ public static PostsResponse.Post toPost(ItemsJpaEntity item, ItemsBorrowJpaEntit
public static PostsResponse.ViewAllResultResponse toViewAllList(List<PostsResponse.Post> 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<PostsResponse.ReviewResponse> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReviewResponse> reviews;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public interface PostsService {

PostsResponse.BillAcceptResponse DoBillAcceptService(String userId, PostsRequest.BillAcceptRequest request);

PostsResponse.ReviewsResponse ViewReviewService(String userId, String postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<ItemsReviewJpaEntity> itemReviews= itemsReivewRepository.findAllByItemsOrderByCreatedAtDesc(item);



List<PostsResponse.ReviewResponse> reviews=itemReviews.stream().map(itemReview->{
return PostsConverter.toReview(itemReview);
}).toList();

return PostsConverter.toReviews(reviews);
}



Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemsReviewJpaEntity,String> {
List<ItemsReviewJpaEntity> findAllByItemsOrderByCreatedAtDesc(ItemsJpaEntity item);


}

0 comments on commit 8ee1794

Please sign in to comment.