From 0d6b5a49031e5d86794175c43925056be9debc85 Mon Sep 17 00:00:00 2001 From: jainefer Date: Fri, 6 Dec 2024 15:13:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20=EB=A6=AC=EB=B7=B0=EC=9E=91?= =?UTF-8?q?=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 { + +} From 693461bbfedf9ece2921b4a4629646b37f89559d Mon Sep 17 00:00:00 2001 From: jainefer Date: Sat, 14 Dec 2024 20:41:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EB=B6=88=EA=B0=80=EB=8A=A5=ED=95=9C=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=9E=91=EC=84=B1=20=EC=97=90=EB=9F=AC=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PostsController.java | 12 ++++- .../borrowPosts/converter/PostsConverter.java | 19 ++++++-- .../dto/response/PostsResponse.java | 9 +++- .../api/borrowPosts/service/PostsService.java | 2 + .../borrowPosts/service/PostsServiceImpl.java | 47 +++++++++++++++++-- .../borrowPosts/BorrowHistRepository.java | 9 ++++ .../repository/chat/ChatRepository.java | 8 ++++ 7 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 src/main/java/site/billbill/apiserver/repository/borrowPosts/BorrowHistRepository.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 b3698c1..9f613c2 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 @@ -53,7 +53,6 @@ public BaseResponse getPostsController( @RequestParam(value="sortBy",required = true,defaultValue = "accuracy") String sortBy ){ - Sort.Direction direction = "asc".equalsIgnoreCase(order) ? Sort.Direction.ASC : Sort.Direction.DESC; return new BaseResponse<>(postsService.ViewAllPostService(category,page,direction,sortBy)); } @@ -127,13 +126,22 @@ public BaseResponse updatePostController(@PathVariable(value="postId",re @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)); } + @Operation(summary="해당 게시물 불가능한 날짜 조회",description = "해당 게시물의 불가능한 날짜 조회를 합니다. owner : 게시물을 등록할 때 작성한 게시물 대여 불가 기간입니다. user : 해당 채팅방에서, 논의중인 대여기간입니다. ") + @GetMapping("/{postId}/blocked") + public BaseResponse blockPostController(@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.ViewNoRentalPeriodsService(userId,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 0e7c760..57df653 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 @@ -2,10 +2,10 @@ import site.billbill.apiserver.api.borrowPosts.dto.request.PostsRequest; import site.billbill.apiserver.api.borrowPosts.dto.response.PostsResponse; +import site.billbill.apiserver.model.chat.ChatChannelJpaEntity; import site.billbill.apiserver.model.post.*; import site.billbill.apiserver.model.user.UserJpaEntity; import site.billbill.apiserver.model.user.UserSearchHistJpaEntity; -import site.billbill.apiserver.repository.borrowPosts.SearchKeywordStatRepository; import java.time.format.DateTimeFormatter; import java.util.List; @@ -66,7 +66,7 @@ public static PostsResponse.Post toPost(ItemsJpaEntity item,ItemsBorrowJpaEntity public static PostsResponse.ViewAllResultResponse toViewAllList(List posts){ return PostsResponse.ViewAllResultResponse.builder().result(posts).build(); } - public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem, List noRental, String status,UserJpaEntity user){ + public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem, String status,UserJpaEntity user){ return PostsResponse.ViewPostResponse.builder() .postId(item.getId()) .title(item.getTitle()) @@ -75,7 +75,6 @@ public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, Ite .price(borrowItem.getPrice()) .priceStandard(borrowItem.getPriceStandard()) .deposit(borrowItem.getDeposit()) - .noRentalPeriod(noRental) .itemStatus(status) .categoryId(item.getCategory().getId()) .categoryName(item.getCategory().getName()) @@ -83,12 +82,24 @@ public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, Ite .userName(user.getNickname()) .build(); } - public static PostsResponse.NoRentalPeriodResponse toNoRentalPeriod(ItemsBorrowStatusJpaEntity borrowStatus){ + public static PostsResponse.NoRentalPeriodResponse toOwnerNoRentalPeriod(ItemsBorrowStatusJpaEntity borrowStatus){ return PostsResponse.NoRentalPeriodResponse.builder() .startDate(borrowStatus.getStartDate().format(DATE_FORMATTER)) .endDate(borrowStatus.getEndDate().format(DATE_FORMATTER)) .build(); } + public static PostsResponse.NoRentalPeriodResponse toContactNoRentalPeriod(ChatChannelJpaEntity chat){ + return PostsResponse.NoRentalPeriodResponse.builder() + .startDate(chat.getStartedAt().format(DATE_FORMATTER)) + .endDate(chat.getEndedAt().format(DATE_FORMATTER)) + .build(); + } + public static PostsResponse.NoRentalPeriodsResponse toNoRentalPeriods(List owner, List user){ + return PostsResponse.NoRentalPeriodsResponse.builder() + .owner(owner) + .user(user) + .build(); + } public static UserSearchHistJpaEntity toUserSearch(UserJpaEntity user,String keyword){ return UserSearchHistJpaEntity.builder() .keyword(keyword) 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 5e0519b..f41a498 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 @@ -45,7 +45,6 @@ public static class ViewPostResponse{ private int price; private PriceStandard priceStandard; private int deposit; - private List noRentalPeriod; private String categoryId; private String categoryName; private String userId; @@ -76,6 +75,14 @@ public static class NoRentalPeriodResponse{ @Getter @Setter @Builder + public static class NoRentalPeriodsResponse{ + + private List owner; + private List user; + } + @Getter + @Setter + @Builder public static class ReviewIdResponse{ private String itemId; private String reviewId; 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 1d156e9..e9c831f 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 @@ -24,4 +24,6 @@ public interface PostsService { PostsResponse.ReviewIdResponse DoReviewPostService(String postId,String userId,PostsRequest.ReviewRequest request); List findRecommandService(); + PostsResponse.NoRentalPeriodsResponse ViewNoRentalPeriodsService(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 a5a3d8b..ec81598 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 @@ -14,10 +14,12 @@ import site.billbill.apiserver.common.enums.exception.ErrorCode; import site.billbill.apiserver.common.utils.ULID.ULIDUtil; import site.billbill.apiserver.exception.CustomException; +import site.billbill.apiserver.model.chat.ChatChannelJpaEntity; import site.billbill.apiserver.model.post.*; import site.billbill.apiserver.model.user.UserJpaEntity; import site.billbill.apiserver.model.user.UserSearchHistJpaEntity; import site.billbill.apiserver.repository.borrowPosts.*; +import site.billbill.apiserver.repository.chat.ChatRepository; import site.billbill.apiserver.repository.user.UserRepository; import site.billbill.apiserver.repository.user.UserSearchHistRepository; @@ -38,6 +40,8 @@ public class PostsServiceImpl implements PostsService { private final UserSearchHistRepository userSearchHistRepository; private final SearchKeywordStatRepository searchKeywordStatRepository; private final ItemsReivewRepository itemsReivewRepository; + private final ChatRepository chatRepository; + private final BorrowHistRepository borrowHistRepository; public PostsResponse.UploadResponse uploadPostService(PostsRequest.UploadRequest request,String userId){ //먼저 item 생성, Optional isUser=userRepository.findById(userId); @@ -81,8 +85,8 @@ public PostsResponse.ViewPostResponse ViewPostService(String postId,String userI ItemsBorrowJpaEntity borrowItem=itemsBorrowRepository.findById(postId).orElse(null); UserJpaEntity user = userRepository.findById(userId).orElse(null); - List borrowStatus=itemsBorrowStatusRepository.findAllByItemIdAndBorrowStatusCode(postId,"RENTAL_NOT_POSSIBLE"); - List noRentalPeriods=borrowStatus.stream().map(PostsConverter::toNoRentalPeriod).toList(); + + if(item==null){ throw new CustomException(ErrorCode.BadRequest, "올바른 게시물 아이디가 아닙니다.", HttpStatus.BAD_REQUEST); } @@ -105,7 +109,7 @@ public PostsResponse.ViewPostResponse ViewPostService(String postId,String userI break; } - return PostsConverter.toViewPost(item,borrowItem,noRentalPeriods,status,user); + return PostsConverter.toViewPost(item,borrowItem,status,user); } @Transactional @@ -199,12 +203,20 @@ public List findRecommandService(){ 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); + BorrowHistJapEntity borrwHist = borrowHistRepository.findBorrowHistByBorrower(user); String postsId = ULIDUtil.generatorULID("REVIEW"); if (item == null) { throw new CustomException(ErrorCode.BadRequest, "올바른 게시물 아이디가 아닙니다.", HttpStatus.BAD_REQUEST); - }else if(request.getRating()>=6||request.getRating()<=0){ + } + if(request.getRating()>=6||request.getRating()<=0){ throw new CustomException(ErrorCode.BadRequest, "평점이 올바르지 않습니다. 1~5 사이로 입력해주셔야합니다.", HttpStatus.BAD_REQUEST); } + if(user == item.getOwner()){ + throw new CustomException(ErrorCode.BadRequest, "자기 자신의 게시물에는 리뷰작성이 안됩니다.", HttpStatus.BAD_REQUEST); + } + if(borrwHist==null){ + throw new CustomException(ErrorCode.BadRequest,"해당 게시물에 대한 대여 기록이 없습니다.", HttpStatus.BAD_REQUEST); + } ItemsReviewJpaEntity review=PostsConverter.toItemsReview(user,item,request,postsId); itemsReivewRepository.save(review); @@ -212,6 +224,33 @@ public PostsResponse.ReviewIdResponse DoReviewPostService(String postId,String u } + public PostsResponse.NoRentalPeriodsResponse ViewNoRentalPeriodsService(String userId,String postId){ + UserJpaEntity user = userRepository.findById(userId).orElse(null); + ItemsJpaEntity item=itemsRepository.findById(postId).orElse(null); + List itemsBorrowStatus = itemsBorrowStatusRepository.findAllByItemIdAndBorrowStatusCode(postId, "RENTAL_NOT_POSSIBLE"); + + List ownerNoRentalPeriod=itemsBorrowStatus.stream().map(itemStatus->{ + return PostsConverter.toOwnerNoRentalPeriod(itemStatus); + }).toList(); + + List chatChannel = chatRepository.findAllByItemAndContactUser(item,user); + List contactNoRentalPeriod=chatChannel.stream().map(chat->{ + return PostsConverter.toContactNoRentalPeriod(chat); + }).toList(); + + return PostsConverter.toNoRentalPeriods(ownerNoRentalPeriod,contactNoRentalPeriod); + + } + + + + + + + + + + //모듈화 코드 diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/BorrowHistRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/BorrowHistRepository.java new file mode 100644 index 0000000..070f494 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/BorrowHistRepository.java @@ -0,0 +1,9 @@ +package site.billbill.apiserver.repository.borrowPosts; + +import org.springframework.data.jpa.repository.JpaRepository; +import site.billbill.apiserver.model.post.BorrowHistJapEntity; +import site.billbill.apiserver.model.user.UserJpaEntity; + +public interface BorrowHistRepository extends JpaRepository { + BorrowHistJapEntity findBorrowHistByBorrower(UserJpaEntity borrower); +} diff --git a/src/main/java/site/billbill/apiserver/repository/chat/ChatRepository.java b/src/main/java/site/billbill/apiserver/repository/chat/ChatRepository.java index bdd015b..85fe707 100644 --- a/src/main/java/site/billbill/apiserver/repository/chat/ChatRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/chat/ChatRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query; import site.billbill.apiserver.model.chat.ChatChannelJpaEntity; import site.billbill.apiserver.model.post.ItemsJpaEntity; +import site.billbill.apiserver.model.user.UserJpaEntity; public interface ChatRepository extends JpaRepository { // List findByItemAndCloYnFalseAndDelYnFalse(ItemsJpaEntity item); @@ -17,4 +18,11 @@ public interface ChatRepository extends JpaRepository findByItemAndStartAndEndDate(ItemsJpaEntity item, LocalDate startDate, LocalDate endDate); + + @Query("SELECT c FROM ChatChannelJpaEntity c "+ + "WHERE c.item = :item " + + "AND c.delYn = false " + + "And c.contact = :user " + ) + List findAllByItemAndContactUser(ItemsJpaEntity item, UserJpaEntity user); }