From d2f10eb667694401fa086e8586051020f6bcdbe4 Mon Sep 17 00:00:00 2001 From: jainefer Date: Fri, 22 Nov 2024 13:34:37 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../borrowPosts/converter/PostsConverter.java | 16 +++++++++------- .../borrowPosts/dto/response/PostsResponse.java | 11 ++++++++++- .../borrowPosts/service/PostsServiceImpl.java | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) 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 b3ef46e..ce16992 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,17 +2,17 @@ import site.billbill.apiserver.api.borrowPosts.dto.request.PostsRequest; import site.billbill.apiserver.api.borrowPosts.dto.response.PostsResponse; -import site.billbill.apiserver.common.enums.items.PriceStandard; import site.billbill.apiserver.model.post.ItemsBorrowJpaEntity; import site.billbill.apiserver.model.post.ItemsBorrowStatusJpaEntity; import site.billbill.apiserver.model.post.ItemsJpaEntity; import site.billbill.apiserver.model.user.UserJpaEntity; -import site.billbill.apiserver.repository.borrowPosts.ItemsBorrowStatusRepository; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; +import static com.mysql.cj.util.TimeUtil.DATE_FORMATTER; + public class PostsConverter { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); public static PostsResponse.UploadResponse toUploadResponse(String id){ @@ -64,7 +64,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){ + public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem, List noRental, String status){ return PostsResponse.ViewPostResponse.builder() .postId(item.getId()) .title(item.getTitle()) @@ -75,12 +75,14 @@ public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, Ite .deposit(borrowItem.getDeposit()) .noRentalPeriod(noRental) .itemStatus(status) + .categoryId(item.getCategory().getId()) + .categoryName(item.getCategory().getName()) .build(); } - public static PostsRequest.NoRentalPeriod toNoRentalPeriod(ItemsBorrowStatusJpaEntity borrowStatus){ - return PostsRequest.NoRentalPeriod.builder() - .startDate(borrowStatus.getStartDate()) - .endDate(borrowStatus.getEndDate()) + public static PostsResponse.NoRentalPeriodResponse toNoRentalPeriod(ItemsBorrowStatusJpaEntity borrowStatus){ + return PostsResponse.NoRentalPeriodResponse.builder() + .startDate(borrowStatus.getStartDate().format(DATE_FORMATTER)) + .endDate(borrowStatus.getEndDate().format(DATE_FORMATTER)) .build(); } 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 a68bd40..24b172c 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 @@ -44,7 +44,16 @@ public static class ViewPostResponse{ private int price; private PriceStandard priceStandard; private int deposit; - private List noRentalPeriod; + private List noRentalPeriod; + private String categoryId; + private String categoryName; } + @Getter + @Setter + @Builder + public static class NoRentalPeriodResponse{ + private String startDate; + private String endDate; + } } 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 cb9531c..82bf12c 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 @@ -115,7 +115,7 @@ public PostsResponse.ViewPostResponse ViewPostService(String postId){ ItemsJpaEntity item=itemsRepository.findById(postId).orElse(null); ItemsBorrowJpaEntity borrowItem=itemsBorrowRepository.findById(postId).orElse(null); List borrowStatus=itemsBorrowStatusRepository.findAllByItemIdAndBorrowStatusCode(postId,"RENTAL_NOT_POSSIBLE"); - List noRentalPeriods=borrowStatus.stream().map(PostsConverter::toNoRentalPeriod).toList(); + List noRentalPeriods=borrowStatus.stream().map(PostsConverter::toNoRentalPeriod).toList(); String status=""; switch(item.getItemStatus()){ case 1: