From 0d6b5a49031e5d86794175c43925056be9debc85 Mon Sep 17 00:00:00 2001 From: jainefer Date: Fri, 6 Dec 2024 15:13:37 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A6=AC=EB=B7=B0=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PostsController.java | 11 ++++++++++ .../borrowPosts/converter/PostsConverter.java | 16 +++++++++++++++ .../borrowPosts/dto/request/PostsRequest.java | 9 +++++++++ .../dto/response/PostsResponse.java | 7 +++++++ .../api/borrowPosts/service/PostsService.java | 1 + .../borrowPosts/service/PostsServiceImpl.java | 20 +++++++++++++++++++ .../borrowPosts/ItemsReivewRepository.java | 8 ++++++++ 7 files changed, 72 insertions(+) create mode 100644 src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java 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 4f56905..b3698c1 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 @@ -123,6 +123,17 @@ public BaseResponse updatePostController(@PathVariable(value="postId",re return new BaseResponse<>(postsService.UpdatePostService(postId,userId,request)); } + @Operation(summary="리뷰작성",description = "리뷰 작성") + @PostMapping("/reviews/{postId}") + public BaseResponse reviewPostController(@PathVariable(value="postId",required = true)String postId, + @RequestBody @Valid PostsRequest.ReviewRequest request){ + + String userId = ""; + if(MDC.get(JWTUtil.MDC_USER_ID) != null) { + userId= MDC.get(JWTUtil.MDC_USER_ID).toString(); + } + return new BaseResponse<>(postsService.DoReviewPostService(postId,userId,request)); + } } 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 9697a2f..0e7c760 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 @@ -109,6 +109,22 @@ public static PostsResponse.saveSearchListResponse toUserSearhList(List findRecommandService(); } 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 7b14d5f..a5a3d8b 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 @@ -37,6 +37,7 @@ public class PostsServiceImpl implements PostsService { private final ItemsCategoryRepository itemsCategoryRepository; private final UserSearchHistRepository userSearchHistRepository; private final SearchKeywordStatRepository searchKeywordStatRepository; + private final ItemsReivewRepository itemsReivewRepository; public PostsResponse.UploadResponse uploadPostService(PostsRequest.UploadRequest request,String userId){ //먼저 item 생성, Optional isUser=userRepository.findById(userId); @@ -194,6 +195,25 @@ public List findRecommandService(){ List result =searchKeywordStats.stream().map(searchKeywordStat-> PostsConverter.toRecommandSearch(searchKeywordStat)).toList(); return result; } + + public PostsResponse.ReviewIdResponse DoReviewPostService(String postId,String userId,PostsRequest.ReviewRequest request){ + UserJpaEntity user = userRepository.findById(userId).orElse(null); + ItemsJpaEntity item=itemsRepository.findById(postId).orElse(null); + String postsId = ULIDUtil.generatorULID("REVIEW"); + if (item == null) { + throw new CustomException(ErrorCode.BadRequest, "올바른 게시물 아이디가 아닙니다.", HttpStatus.BAD_REQUEST); + }else if(request.getRating()>=6||request.getRating()<=0){ + throw new CustomException(ErrorCode.BadRequest, "평점이 올바르지 않습니다. 1~5 사이로 입력해주셔야합니다.", HttpStatus.BAD_REQUEST); + } + ItemsReviewJpaEntity review=PostsConverter.toItemsReview(user,item,request,postsId); + itemsReivewRepository.save(review); + + return PostsConverter.toReviewIdResponse(item,review); + } + + + + //모듈화 코드 private Pageable createPageable(int page, Sort.Direction direction, String orderType) { diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java new file mode 100644 index 0000000..ae158bc --- /dev/null +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsReivewRepository.java @@ -0,0 +1,8 @@ +package site.billbill.apiserver.repository.borrowPosts; + +import org.springframework.data.jpa.repository.JpaRepository; +import site.billbill.apiserver.model.post.ItemsReviewJpaEntity; + +public interface ItemsReivewRepository extends JpaRepository { + +}