Skip to content

Commit

Permalink
Enum 관련 응답 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomeo184 committed Dec 27, 2023
1 parent ab75c6c commit 0244701
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.offer.member.Member;
import com.offer.offer.domain.Offer;
import com.offer.post.domain.Post;
import com.offer.post.domain.TradeType;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -23,6 +24,6 @@ public OfferCreateRequest(Integer price, String tradeType, String location) {
}

public Offer toEntity(Member offerer, Post post) {
return new Offer(post, offerer, this.price, false, this.tradeType);
return new Offer(post, offerer, this.price, false, TradeType.from(this.tradeType));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.offer.offer.application.response;

import com.offer.offer.domain.Offer;
import com.offer.post.application.response.EnumResponse;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -29,7 +30,9 @@ public static OfferResponse from(Offer offer) {
offer.getOfferer().getNickname(),
offer.getPost().getLocation(),
String.valueOf(offer.getOfferer().getOfferLevel()),
offer.getTradeType(), offer.getOfferer().getProfileImageUrl()),
new EnumResponse(offer.getTradeType().name(),
offer.getTradeType().getDescription()),
offer.getOfferer().getProfileImageUrl()),
offer.getPrice(),
offer.getCreatedAt()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.offer.offer.application.response;

import com.offer.offer.domain.Offer;
import com.offer.post.application.response.EnumResponse;
import com.offer.post.domain.Post;
import com.offer.post.domain.TradeStatus;
import com.offer.review.application.response.ReviewInfoResponse;
Expand All @@ -18,7 +19,7 @@ public class OfferSummary {
private Long postId;
private int offerPrice;
private String thumbnailImageUrl;
private TradeStatus tradeStatus;
private EnumResponse tradeStatus;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
private boolean reviewAvailable;
Expand All @@ -27,7 +28,7 @@ public class OfferSummary {

@Builder
public OfferSummary(Long offerId, Long postId, int offerPrice, String thumbnailImageUrl,
TradeStatus tradeStatus, LocalDateTime createdAt, boolean reviewAvailable,
EnumResponse tradeStatus, LocalDateTime createdAt, boolean reviewAvailable,
boolean hasReview, ReviewInfoResponse review) {
this.offerId = offerId;
this.postId = postId;
Expand All @@ -47,7 +48,7 @@ public static OfferSummary from(Offer offer) {
.postId(post.getId())
.offerPrice(offer.getPrice())
.thumbnailImageUrl(post.getThumbnailImageUrl())
.tradeStatus(post.getTradeStatus())
.tradeStatus(new EnumResponse(post.getTradeStatus().name(), post.getTradeStatus().getDescription()))
.createdAt(offer.getCreatedAt())
.build();
}
Expand All @@ -59,7 +60,7 @@ public static OfferSummary from(Offer offer, boolean reviewAvailable, ReviewInfo
.postId(post.getId())
.offerPrice(offer.getPrice())
.thumbnailImageUrl(post.getThumbnailImageUrl())
.tradeStatus(post.getTradeStatus())
.tradeStatus(new EnumResponse(post.getTradeStatus().name(), post.getTradeStatus().getDescription()))
.createdAt(offer.getCreatedAt())
.reviewAvailable(reviewAvailable)
.hasReview(review != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.offer.offer.application.response;

import com.offer.post.application.response.EnumResponse;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -10,12 +11,12 @@ public class OffererResponse {
private String nickname;
private String location;
private String level;
private String tradeType;
private EnumResponse tradeType;
private String profileImageUrl;

@Builder
public OffererResponse(Long id, String nickname, String location, String level,
String tradeType, String profileImageUrl) {
EnumResponse tradeType, String profileImageUrl) {
this.id = id;
this.nickname = nickname;
this.location = location;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/offer/offer/domain/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.offer.member.Member;
import com.offer.post.domain.Post;
import com.offer.post.domain.TradeType;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand Down Expand Up @@ -38,12 +41,14 @@ public class Offer {

private Integer price;
private Boolean isSelected;
private String tradeType;

@Enumerated(EnumType.STRING)
private TradeType tradeType;

@CreatedDate
private LocalDateTime createdAt;

public Offer(Post post, Member offerer, Integer price, Boolean isSelected, String tradeType) {
public Offer(Post post, Member offerer, Integer price, Boolean isSelected, TradeType tradeType) {
this.post = post;
this.offerer = offerer;
this.price = price;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.offer.post.application.response;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class EnumResponse {

private String code;
private String name;

public EnumResponse(String code, String name) {
this.code = code;
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.offer.post.domain.Post;
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;
Expand All @@ -23,9 +21,9 @@ public class PostDetail {
private List<String> imageUrls;
private int price;
private String location;
private TradeType tradeType;
private TradeStatus tradeStatus;
private ProductCondition productCondition;
private EnumResponse tradeType;
private EnumResponse tradeStatus;
private EnumResponse productCondition;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
private SellerDetail seller;
Expand All @@ -35,7 +33,7 @@ public class PostDetail {

@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, EnumResponse tradeType, EnumResponse tradeStatus, EnumResponse productCondition, LocalDateTime createdAt,
SellerDetail seller, CategoryResponse category, boolean liked,
int totalLikeCount) {
this.id = id;
Expand All @@ -62,11 +60,11 @@ public static PostDetail from(Post post, Category category, boolean liked, int t
.description(post.getDescription())
.thumbnailImageUrl(post.getThumbnailImageUrl())
.imageUrls(post.getImageUrls())
.tradeStatus(post.getTradeStatus())
.tradeStatus(new EnumResponse(post.getTradeStatus().name(), post.getTradeStatus().getDescription()))
.price(post.getPrice())
.location(post.getLocation())
.tradeType(post.getTradeType())
.productCondition(post.getProductCondition())
.tradeType(new EnumResponse(post.getTradeType().name(), post.getTradeType().getDescription()))
.productCondition(new EnumResponse(post.getProductCondition().name(), post.getProductCondition().getDescription()))
.createdAt(post.getCreatedAt())
.seller(SellerDetail.from(post.getSeller()))
.category(CategoryResponse.from(category))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PostSummary {
private String location;
private String thumbnailImageUrl;
private boolean liked;
private TradeStatus tradeStatus;
private EnumResponse tradeStatus;
private int likeCount;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime createdAt;
Expand All @@ -36,7 +36,7 @@ public class PostSummary {

@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, EnumResponse tradeStatus, int likeCount, LocalDateTime createdAt,
SellerDetail seller, CategoryResponse category, ReviewInfoResponse review,
boolean hasReview) {
this.id = id;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static PostSummary from(Post post, Set<Long> likePostIds, int likeCount,
.location(post.getLocation())
.thumbnailImageUrl(post.getThumbnailImageUrl())
.liked(liked)
.tradeStatus(post.getTradeStatus())
.tradeStatus(new EnumResponse(post.getTradeStatus().name(), post.getTradeStatus().getDescription()))
.likeCount(likeCount)
.createdAt(post.getCreatedAt())
.review(review)
Expand All @@ -84,7 +84,7 @@ public static PostSummary from(Post post, boolean isLiked) {
.location(post.getLocation())
.thumbnailImageUrl(post.getThumbnailImageUrl())
.liked(isLiked)
.tradeStatus(post.getTradeStatus())
.tradeStatus(new EnumResponse(post.getTradeStatus().name(), post.getTradeStatus().getDescription()))
.createdAt(post.getCreatedAt())
.seller(SellerDetail.from(post.getSeller()))
.build();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/offer/post/domain/ProductCondition.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.offer.post.domain;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum ProductCondition {
NEW,
SECONDHAND
;
NEW("새상품"),
SECONDHAND("중고상품");

private final String description;

ProductCondition(String description) {
this.description = description;
}

public static ProductCondition from(String name) {
return Arrays.stream(values())
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/offer/post/domain/TradeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

@Getter
public enum TradeStatus {
SELLING,
SOLD,
UNKNOWN
;
SELLING("판매중"),
SOLD("판매완료"),
UNKNOWN("");

private final String description;

TradeStatus(String description) {
this.description = description;
}

public static TradeStatus from(String name) {
if (name == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/offer/post/domain/TradeType.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.offer.post.domain;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum TradeType {
FACE_TO_FACE("직거래"),
SHIPPING("택배거래"),
Expand Down

0 comments on commit 0244701

Please sign in to comment.