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 0b26855..d52ab2b 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 @@ -39,5 +39,11 @@ public BaseResponse getPostsController(@Req 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..b3ef46e 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 @@ -64,5 +64,24 @@ 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) + .build(); + } + public static PostsRequest.NoRentalPeriod toNoRentalPeriod(ItemsBorrowStatusJpaEntity borrowStatus){ + return PostsRequest.NoRentalPeriod.builder() + .startDate(borrowStatus.getStartDate()) + .endDate(borrowStatus.getEndDate()) + .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..a68bd40 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,18 @@ 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; + + } } 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..cb9531c 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); }