Skip to content

Commit

Permalink
[feat] 게시물 상세 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
jainefer committed Nov 22, 2024
1 parent ca2b178 commit d2f10eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -64,7 +64,7 @@ public static PostsResponse.Post toPost(ItemsJpaEntity item,ItemsBorrowJpaEntity
public static PostsResponse.ViewAllResultResponse toViewAllList(List<PostsResponse.Post> posts){
return PostsResponse.ViewAllResultResponse.builder().result(posts).build();
}
public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem,List<PostsRequest.NoRentalPeriod> noRental,String status){
public static PostsResponse.ViewPostResponse toViewPost(ItemsJpaEntity item, ItemsBorrowJpaEntity borrowItem, List<PostsResponse.NoRentalPeriodResponse> noRental, String status){
return PostsResponse.ViewPostResponse.builder()
.postId(item.getId())
.title(item.getTitle())
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ public static class ViewPostResponse{
private int price;
private PriceStandard priceStandard;
private int deposit;
private List<PostsRequest.NoRentalPeriod> noRentalPeriod;
private List<NoRentalPeriodResponse> noRentalPeriod;
private String categoryId;
private String categoryName;

}
@Getter
@Setter
@Builder
public static class NoRentalPeriodResponse{
private String startDate;
private String endDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsBorrowStatusJpaEntity> borrowStatus=itemsBorrowStatusRepository.findAllByItemIdAndBorrowStatusCode(postId,"RENTAL_NOT_POSSIBLE");
List<PostsRequest.NoRentalPeriod> noRentalPeriods=borrowStatus.stream().map(PostsConverter::toNoRentalPeriod).toList();
List<PostsResponse.NoRentalPeriodResponse> noRentalPeriods=borrowStatus.stream().map(PostsConverter::toNoRentalPeriod).toList();
String status="";
switch(item.getItemStatus()){
case 1:
Expand Down

0 comments on commit d2f10eb

Please sign in to comment.