From 596da222dc1217f959c67bd5063f7f46225af56f Mon Sep 17 00:00:00 2001 From: Jihun-Hwang Date: Sat, 16 Dec 2023 22:27:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91=EB=8B=B5=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EB=B3=B4=EA=B0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offer/post/application/PostService.java | 4 +- .../post/application/response/PostDetail.java | 38 ++++++++++++------- .../application/response/SellerDetail.java | 30 +++++++++++++++ 3 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/offer/post/application/response/SellerDetail.java diff --git a/src/main/java/com/offer/post/application/PostService.java b/src/main/java/com/offer/post/application/PostService.java index 64072fd..11f6d05 100644 --- a/src/main/java/com/offer/post/application/PostService.java +++ b/src/main/java/com/offer/post/application/PostService.java @@ -63,7 +63,7 @@ public PostSummaries getPosts(PostReadParams params, LoginMember loginMember) { @Transactional(readOnly = true) public PostDetail getPost(Long postId) { Post post = postRepository.getById(postId); - return PostDetail.from(post); + return PostDetail.from(post, categoryRepository.findByName(post.getCategory())); } @Transactional(readOnly = true) @@ -106,7 +106,7 @@ public PostDetail updatePost(Long postId, PostUpdateRequest request, Long member .getId()); } post.update(request); - return PostDetail.from(post); + return PostDetail.from(post, categoryRepository.findByName(post.getCategory())); } @Transactional diff --git a/src/main/java/com/offer/post/application/response/PostDetail.java b/src/main/java/com/offer/post/application/response/PostDetail.java index cd65c66..3d55150 100644 --- a/src/main/java/com/offer/post/application/response/PostDetail.java +++ b/src/main/java/com/offer/post/application/response/PostDetail.java @@ -4,8 +4,11 @@ import com.offer.post.domain.ProductCondition; import com.offer.post.domain.TradeStatus; import com.offer.post.domain.TradeType; + import java.time.LocalDateTime; import java.util.List; + +import com.offer.post.domain.category.Category; import lombok.Builder; import lombok.Getter; import org.springframework.format.annotation.DateTimeFormat; @@ -25,10 +28,13 @@ public class PostDetail { private ProductCondition productCondition; @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") private LocalDateTime createdAt; + private SellerDetail seller; + private CategoryResponse category; @Builder public PostDetail(Long id, String title, String description, String thumbnailImageUrl, List imageUrls, int price, - String location, TradeType tradeType, TradeStatus tradeStatus, ProductCondition productCondition, LocalDateTime createdAt) { + String location, TradeType tradeType, TradeStatus tradeStatus, ProductCondition productCondition, LocalDateTime createdAt, + SellerDetail seller, CategoryResponse category) { this.id = id; this.title = title; this.description = description; @@ -40,21 +46,25 @@ public PostDetail(Long id, String title, String description, String thumbnailIma this.tradeStatus = tradeStatus; this.productCondition = productCondition; this.createdAt = createdAt; + this.seller = seller; + this.category = category; } - public static PostDetail from(Post post) { + public static PostDetail from(Post post, Category category) { return PostDetail.builder() - .id(post.getId()) - .title(post.getTitle()) - .description(post.getDescription()) - .thumbnailImageUrl(post.getThumbnailImageUrl()) - .imageUrls(post.getImageUrls()) - .tradeStatus(post.getTradeStatus()) - .price(post.getPrice()) - .location(post.getLocation()) - .tradeType(post.getTradeType()) - .productCondition(post.getProductCondition()) - .createdAt(post.getCreatedAt()) - .build(); + .id(post.getId()) + .title(post.getTitle()) + .description(post.getDescription()) + .thumbnailImageUrl(post.getThumbnailImageUrl()) + .imageUrls(post.getImageUrls()) + .tradeStatus(post.getTradeStatus()) + .price(post.getPrice()) + .location(post.getLocation()) + .tradeType(post.getTradeType()) + .productCondition(post.getProductCondition()) + .createdAt(post.getCreatedAt()) + .seller(SellerDetail.from(post.getSeller())) + .category(CategoryResponse.from(category)) + .build(); } } diff --git a/src/main/java/com/offer/post/application/response/SellerDetail.java b/src/main/java/com/offer/post/application/response/SellerDetail.java new file mode 100644 index 0000000..960ef5a --- /dev/null +++ b/src/main/java/com/offer/post/application/response/SellerDetail.java @@ -0,0 +1,30 @@ +package com.offer.post.application.response; + +import com.offer.member.Member; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class SellerDetail { + private Long id; + private String profileImageUrl; + private String nickname; + private int offerLevel; + + @Builder + public SellerDetail(Long id, String profileImageUrl, String nickname, int offerLevel) { + this.id = id; + this.profileImageUrl = profileImageUrl; + this.nickname = nickname; + this.offerLevel = offerLevel; + } + + public static SellerDetail from(Member seller) { + return SellerDetail.builder() + .id(seller.getId()) + .profileImageUrl(seller.getProfileImageUrl()) + .nickname(seller.getNickname()) + .offerLevel(seller.getOfferLevel()) + .build(); + } +} From 042cc4f453c0f98d0a3aaa96cd1983802005dbd5 Mon Sep 17 00:00:00 2001 From: Jihun-Hwang Date: Sat, 16 Dec 2023 22:48:43 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/response/PostSummary.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/offer/post/application/response/PostSummary.java b/src/main/java/com/offer/post/application/response/PostSummary.java index d166f24..7311a16 100644 --- a/src/main/java/com/offer/post/application/response/PostSummary.java +++ b/src/main/java/com/offer/post/application/response/PostSummary.java @@ -2,8 +2,10 @@ import com.offer.post.domain.Post; import com.offer.post.domain.TradeStatus; + import java.time.LocalDateTime; import java.util.Set; + import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -23,10 +25,13 @@ public class PostSummary { private int likeCount; @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") private LocalDateTime createdAt; + private SellerDetail seller; + private CategoryResponse category; @Builder(toBuilder = true) public PostSummary(Long id, String title, int price, String location, String thumbnailImageUrl, - boolean liked, TradeStatus tradeStatus, int likeCount, LocalDateTime createdAt) { + boolean liked, TradeStatus tradeStatus, int likeCount, LocalDateTime createdAt, + SellerDetail seller, CategoryResponse category) { this.id = id; this.title = title; this.price = price; @@ -36,6 +41,8 @@ public PostSummary(Long id, String title, int price, String location, String thu this.tradeStatus = tradeStatus; this.likeCount = likeCount; this.createdAt = createdAt; + this.seller = seller; + this.category = category; } public static PostSummary from(Post post, Set likePostIds, int likeCount) { @@ -45,16 +52,16 @@ public static PostSummary from(Post post, Set likePostIds, int likeCount) } return PostSummary.builder() - .id(post.getId()) - .title(post.getTitle()) - .price(post.getPrice()) - .location(post.getLocation()) - .thumbnailImageUrl(post.getThumbnailImageUrl()) - .liked(liked) // TODO: 2023/09/24 NOT IMPLEMENTED - .tradeStatus(post.getTradeStatus()) - .likeCount(likeCount) - .createdAt(post.getCreatedAt()) - .build(); + .id(post.getId()) + .title(post.getTitle()) + .price(post.getPrice()) + .location(post.getLocation()) + .thumbnailImageUrl(post.getThumbnailImageUrl()) + .liked(liked) // TODO: 2023/09/24 NOT IMPLEMENTED + .tradeStatus(post.getTradeStatus()) + .likeCount(likeCount) + .createdAt(post.getCreatedAt()) + .build(); } public static PostSummary from(Post post, boolean isLiked) { @@ -67,6 +74,7 @@ public static PostSummary from(Post post, boolean isLiked) { .liked(isLiked) .tradeStatus(post.getTradeStatus()) .createdAt(post.getCreatedAt()) + .seller(SellerDetail.from(post.getSeller())) .build(); } }