Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/borrow posts #62

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@ public BaseResponse<PostsResponse.ViewAllResultResponse> 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<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 @@ -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,5 +64,26 @@ 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<PostsResponse.NoRentalPeriodResponse> 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();
}

}
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,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<String> images;
private int price;
private PriceStandard priceStandard;
private int deposit;
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 @@ -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<PostsResponse.NoRentalPeriodResponse> 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);
}
Loading