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 3d1a26f commit 50629de
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ public BaseResponse<PostsResponse.ViewAllResultResponse> 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<PostsResponse.ViewPostResponse> getPostController(@PathVariable(value = "postId",required = true)String postId){

return new BaseResponse<>(postsService.ViewPostService(postId));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,24 @@ 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){
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();
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +35,7 @@ public static class UploadRequest {
}
@Getter
@Setter
@Builder
public static class NoRentalPeriod{
private LocalDate startDate;
private LocalDate endDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> images;
private int price;
private PriceStandard priceStandard;
private int deposit;
private List<PostsRequest.NoRentalPeriod> noRentalPeriod;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsBorrowStatusJpaEntity> borrowStatus=itemsBorrowStatusRepository.findAllByItemIdAndBorrowStatusCode(postId,"RENTAL_NOT_POSSIBLE");
List<PostsRequest.NoRentalPeriod> 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);



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsBorrowStatusJpaEntity,Long> {
List<ItemsBorrowStatusJpaEntity> findAllByItemIdAndBorrowStatusCode(String itemId,String borrowStatusCode);
}

0 comments on commit 50629de

Please sign in to comment.