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 55e2962..6c92950 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 @@ -52,5 +52,11 @@ public BaseResponse getPostsController( Sort.Direction direction = "asc".equalsIgnoreCase(order) ? Sort.Direction.ASC : Sort.Direction.DESC; return new BaseResponse<>(postsService.ViewAllPostService(category,page,direction,sortBy)); } + @GetMapping("/{postId}") + public BaseResponse getPostController(@PathVariable(value = "postId",required = true)String postId){ + + return new BaseResponse<>(postsService.ViewPostService(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 3cfbbae..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,5 +64,26 @@ 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){ + return PostsResponse.ViewPostResponse.builder() + .postId(item.getId()) + .title(item.getTitle()) + .content(item.getContent()) + .images(item.getImages()) + .price(borrowItem.getPrice()) + .priceStandard(borrowItem.getPriceStandard()) + .deposit(borrowItem.getDeposit()) + .noRentalPeriod(noRental) + .itemStatus(status) + .categoryId(item.getCategory().getId()) + .categoryName(item.getCategory().getName()) + .build(); + } + 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/request/PostsRequest.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/request/PostsRequest.java index ea86cb9..f7922a5 100644 --- a/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/request/PostsRequest.java +++ b/src/main/java/site/billbill/apiserver/api/borrowPosts/dto/request/PostsRequest.java @@ -1,6 +1,7 @@ package site.billbill.apiserver.api.borrowPosts.dto.request; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; import lombok.Getter; import lombok.Setter; import site.billbill.apiserver.common.enums.items.PriceStandard; @@ -34,6 +35,7 @@ public static class UploadRequest { } @Getter @Setter + @Builder public static class NoRentalPeriod{ private LocalDate startDate; private LocalDate endDate; 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 cfe74e9..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 @@ -3,6 +3,8 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; +import site.billbill.apiserver.api.borrowPosts.dto.request.PostsRequest; +import site.billbill.apiserver.common.enums.items.PriceStandard; import java.time.LocalDate; import java.time.OffsetDateTime; @@ -31,4 +33,27 @@ public static class Post{ private String createdAt; private int likeCount; } + @Builder + @Getter + public static class ViewPostResponse{ + private String postId; + private String title; + private String content; + private String itemStatus; + private List images; + private int price; + private PriceStandard priceStandard; + private int deposit; + 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/PostsService.java b/src/main/java/site/billbill/apiserver/api/borrowPosts/service/PostsService.java index 45b2457..d707c99 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 @@ -8,4 +8,6 @@ public interface PostsService { PostsResponse.UploadResponse uploadPostService(PostsRequest.UploadRequest request,String userId); PostsResponse.ViewAllResultResponse ViewAllPostService(String category, int page, Sort.Direction direction, String orderType); + + PostsResponse.ViewPostResponse ViewPostService(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 4ea9691..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 @@ -110,4 +110,34 @@ public PostsResponse.ViewAllResultResponse ViewAllPostService( return PostsConverter.toViewAllList(borrowItems); } + + 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(); + String status=""; + switch(item.getItemStatus()){ + case 1: + status="상"; + break; + case 2: + status="중상"; + break; + case 3: + status="중"; + break; + case 4: + status="중하"; + break; + case 5: + status="하"; + break; + + } + return PostsConverter.toViewPost(item,borrowItem,noRentalPeriods,status); + + + + } } diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsBorrowStatusRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsBorrowStatusRepository.java index f01ff5f..6ad114c 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsBorrowStatusRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemsBorrowStatusRepository.java @@ -3,5 +3,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import site.billbill.apiserver.model.post.ItemsBorrowStatusJpaEntity; +import java.util.List; + public interface ItemsBorrowStatusRepository extends JpaRepository { + List findAllByItemIdAndBorrowStatusCode(String itemId,String borrowStatusCode); }