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/#61 게시글 정보 조회 관련 API 보강 #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/main/java/com/offer/post/application/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/com/offer/post/application/response/PostDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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;
Expand All @@ -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();
}
}
30 changes: 19 additions & 11 deletions src/main/java/com/offer/post/application/response/PostSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<Long> likePostIds, int likeCount) {
Expand All @@ -45,16 +52,16 @@ public static PostSummary from(Post post, Set<Long> 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) {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}