diff --git a/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java b/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java new file mode 100644 index 000000000..ec71723ab --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java @@ -0,0 +1,104 @@ +package com.team10.banchan.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class ItemDetail { + + private final String topImage; + private final List thumbImages; + + private final String title; + private final String productDescription; + + private final String point; + private final String deliveryInfo; + + private final String deliveryFee; + private final String nPrices; + private final String sPrices; + + private final List detailSection; + private final List badges; + + private ItemDetail(String topImage, List thumbImages, String title, String productDescription, String point, String deliveryInfo, String deliveryFee, String nPrices, String sPrices, List detailSection, List badges) { + this.topImage = topImage; + this.thumbImages = thumbImages; + this.title = title; + this.productDescription = productDescription; + this.point = point; + this.deliveryInfo = deliveryInfo; + this.deliveryFee = deliveryFee; + this.nPrices = nPrices; + this.sPrices = sPrices; + this.detailSection = detailSection; + this.badges = badges; + } + + public static ItemDetail of(String topImage, List thumbImages, + String title, String productDescription, + String point, String deliveryInfo, + String deliveryFee, String nPrices, String sPrices, + List detailSection, List badges) { + return new ItemDetail(topImage, thumbImages, title, productDescription, point, deliveryInfo, deliveryFee, nPrices, sPrices, detailSection, badges); + } + + @JsonProperty("top_image") + public String getTopImage() { + return topImage; + } + + @JsonProperty("thumb_image") + public List getThumbImages() { + return thumbImages; + } + + @JsonProperty("product_description") + public String getTitle() { + return title; + } + + @JsonProperty("product_description") + public String getProductDescription() { + return productDescription; + } + + @JsonProperty("point") + public String getPoint() { + return point; + } + + @JsonProperty("devliery_info") + public String getDeliveryInfo() { + return deliveryInfo; + } + + @JsonProperty("devliery_fee") + public String getDeliveryFee() { + return deliveryFee; + } + + @JsonProperty("n_prices") + public String getnPrices() { + return nPrices; + } + + + @JsonProperty("s_prices") + public String getsPrices() { + return sPrices; + } + + @JsonProperty("detail_section") + public List getDetailSection() { + return detailSection; + } + + @JsonProperty("badge") + public List getBadges() { + return badges; + } +} + + diff --git a/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java b/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java new file mode 100644 index 000000000..1d56e63ba --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java @@ -0,0 +1,28 @@ +package com.team10.banchan.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ItemDetailResponse { + + private final Long id; + private final ItemDetail itemDetail; + + private ItemDetailResponse(Long id, ItemDetail itemDetail) { + this.id = id; + this.itemDetail = itemDetail; + } + + public static ItemDetailResponse of(Long id, ItemDetail itemDetail) { + return new ItemDetailResponse(id, itemDetail); + } + + @JsonProperty("hash") + public Long getId() { + return id; + } + + @JsonProperty("data") + public ItemDetail getItemDetail() { + return itemDetail; + } +} diff --git a/BE/src/main/java/com/team10/banchan/dto/ItemSummary.java b/BE/src/main/java/com/team10/banchan/dto/ItemSummary.java new file mode 100644 index 000000000..892a404db --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/dto/ItemSummary.java @@ -0,0 +1,95 @@ +package com.team10.banchan.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class ItemSummary { + + private final Long id; + + private final String image; + private final String alt; + + private final List deliveryType; + + private final String title; + private final String description; + + private final String nPrice; + private final String sPrice; + + private final List badge; + + private ItemSummary(Long id, + String image, String alt, + List deliveryType, + String title, String description, + String nPrice, String sPrice, + List badge) { + this.id = id; + this.image = image; + this.alt = alt; + this.deliveryType = deliveryType; + this.title = title; + this.description = description; + this.nPrice = nPrice; + this.sPrice = sPrice; + this.badge = badge; + } + + public static ItemSummary of(Long id, + String image, String alt, + List deliveryType, + String title, String description, + String nPrice, String sPrice, + List badge) { + return new ItemSummary(id, image, alt, deliveryType, title, description, nPrice, sPrice, badge); + } + + @JsonProperty("detail_hash") + public Long getId() { + return id; + } + + @JsonProperty("image") + public String getImage() { + return image; + } + + @JsonProperty("alt") + public String getAlt() { + return alt; + } + + @JsonProperty("delivery_type") + public List getDeliveryType() { + return deliveryType; + } + + @JsonProperty("title") + public String getTitle() { + return title; + } + + @JsonProperty("description") + public String getDescription() { + return description; + } + + @JsonProperty("n_price") + public String getnPrice() { + return nPrice; + } + + @JsonProperty("s_price") + public String getsPrice() { + return sPrice; + } + + @JsonProperty("badge") + public List getBadge() { + return badge; + } + +} diff --git a/BE/src/main/java/com/team10/banchan/model/Badge.java b/BE/src/main/java/com/team10/banchan/model/Badge.java index 1f887f2a8..9f1a0eb29 100644 --- a/BE/src/main/java/com/team10/banchan/model/Badge.java +++ b/BE/src/main/java/com/team10/banchan/model/Badge.java @@ -1,16 +1,13 @@ package com.team10.banchan.model; public class Badge { + private final BadgeType badgeType; Badge(BadgeType badgeType) { this.badgeType = badgeType; } - public String name() { - return this.badgeType.name; - } - public static Badge event() { return new Badge(BadgeType.EVENT); } @@ -19,6 +16,10 @@ public static Badge launching() { return new Badge(BadgeType.LAUNCHING); } + public String getName() { + return this.badgeType.name; + } + enum BadgeType { EVENT("이벤트특가"), LAUNCHING("런칭특가"); diff --git a/BE/src/main/java/com/team10/banchan/model/Category.java b/BE/src/main/java/com/team10/banchan/model/Category.java index 223072af8..c22744277 100644 --- a/BE/src/main/java/com/team10/banchan/model/Category.java +++ b/BE/src/main/java/com/team10/banchan/model/Category.java @@ -2,34 +2,26 @@ import org.springframework.data.annotation.Id; -import java.util.HashSet; -import java.util.Set; - public class Category { + @Id private final Long id; private final String name; - private final Set items; - Category(Long id, String name, Set items) { + Category(Long id, String name) { this.id = id; this.name = name; - this.items = items; } - public Long getId() { - return id; + public static Category newCategory(String name) { + return new Category(null, name); } - public Set getItems() { - return items; + public Long getId() { + return id; } public String getName() { return name; } - - public static Category newCategory(String name) { - return new Category(null, name, new HashSet<>()); - } } diff --git a/BE/src/main/java/com/team10/banchan/model/DeliveryDay.java b/BE/src/main/java/com/team10/banchan/model/DeliveryDay.java index c8b31d05d..c2b5aa555 100644 --- a/BE/src/main/java/com/team10/banchan/model/DeliveryDay.java +++ b/BE/src/main/java/com/team10/banchan/model/DeliveryDay.java @@ -1,16 +1,13 @@ package com.team10.banchan.model; public class DeliveryDay { + private final TheDayOfWeek theDayOfWeek; DeliveryDay(TheDayOfWeek theDayOfWeek) { this.theDayOfWeek = theDayOfWeek; } - public String korean() { - return theDayOfWeek.korean; - } - public static DeliveryDay monday() { return new DeliveryDay(TheDayOfWeek.MON); } @@ -39,6 +36,10 @@ public static DeliveryDay sunday() { return new DeliveryDay(TheDayOfWeek.SUN); } + public String korean() { + return theDayOfWeek.korean; + } + enum TheDayOfWeek { MON("월"), TUE("화"), diff --git a/BE/src/main/java/com/team10/banchan/model/DeliveryType.java b/BE/src/main/java/com/team10/banchan/model/DeliveryType.java index 120238b2f..802fb584c 100644 --- a/BE/src/main/java/com/team10/banchan/model/DeliveryType.java +++ b/BE/src/main/java/com/team10/banchan/model/DeliveryType.java @@ -1,20 +1,13 @@ package com.team10.banchan.model; public class DeliveryType { + private final DeliveryTypeEnum deliveryTypeName; DeliveryType(DeliveryTypeEnum deliveryTypeName) { this.deliveryTypeName = deliveryTypeName; } - public String getName() { - return deliveryTypeName.name; - } - - public String getDetail() { - return deliveryTypeName.detail; - } - public static DeliveryType nationwide() { return new DeliveryType(DeliveryTypeEnum.NATIONWIDE); } @@ -23,6 +16,14 @@ public static DeliveryType dawn() { return new DeliveryType(DeliveryTypeEnum.DAWN); } + public String getName() { + return deliveryTypeName.name; + } + + public String getDetail() { + return deliveryTypeName.detail; + } + enum DeliveryTypeEnum { NATIONWIDE("전국택배", "전국택배 (제주 및 도서산간 불가)"), DAWN("새벽배송", "서울 경기 새벽배송"); diff --git a/BE/src/main/java/com/team10/banchan/model/Description.java b/BE/src/main/java/com/team10/banchan/model/Description.java new file mode 100644 index 000000000..84856e05d --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/model/Description.java @@ -0,0 +1,24 @@ +package com.team10.banchan.model; + +public class Description { + + private final String title; + private final String description; + + Description(String title, String description) { + this.title = title; + this.description = description; + } + + public static Description of(String title, String description) { + return new Description(title, description); + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } +} diff --git a/BE/src/main/java/com/team10/banchan/model/DetailSection.java b/BE/src/main/java/com/team10/banchan/model/DetailSection.java index 001a60a53..cac3e7d4e 100644 --- a/BE/src/main/java/com/team10/banchan/model/DetailSection.java +++ b/BE/src/main/java/com/team10/banchan/model/DetailSection.java @@ -1,17 +1,18 @@ package com.team10.banchan.model; public class DetailSection { + private final String url; DetailSection(String url) { this.url = url; } - public String getUrl() { - return url; - } - public static DetailSection of(String url) { return new DetailSection(url); } + + public String getUrl() { + return url; + } } diff --git a/BE/src/main/java/com/team10/banchan/model/Item.java b/BE/src/main/java/com/team10/banchan/model/Item.java index c00615943..66e0c80d7 100644 --- a/BE/src/main/java/com/team10/banchan/model/Item.java +++ b/BE/src/main/java/com/team10/banchan/model/Item.java @@ -1,26 +1,32 @@ package com.team10.banchan.model; +import com.team10.banchan.dto.ItemDetail; +import com.team10.banchan.dto.ItemSummary; import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Embedded; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class Item { + @Id private final Long id; private final Long section; private final Long category; - private final String alt; - private final String topImage; - private final String title; - private final String description; - private final BigDecimal nPrice; - private final BigDecimal sPrice; - private final BigDecimal deliveryFee; + @Embedded.Nullable + private final TopImage topImage; + + @Embedded.Nullable + private final Description description; + + @Embedded.Nullable + private final Prices prices; + private final Integer stock; private final List detailSections; @@ -29,17 +35,19 @@ public class Item { private final Set deliveryTypes; private final Set deliveryDays; - Item(Long id, Long section, Long category, String alt, String topImage, String title, String description, BigDecimal nPrice, BigDecimal sPrice, BigDecimal deliveryFee, Integer stock, List detailSections, List thumbImages, Set badges, Set deliveryTypes, Set deliveryDays) { + Item(Long id, Long section, Long category, + TopImage topImage, + Description description, + Prices prices, + Integer stock, + List detailSections, List thumbImages, + Set badges, Set deliveryTypes, Set deliveryDays) { this.id = id; this.section = section; this.category = category; - this.alt = alt; this.topImage = topImage; - this.title = title; this.description = description; - this.nPrice = nPrice; - this.sPrice = sPrice; - this.deliveryFee = deliveryFee; + this.prices = prices; this.stock = stock; this.detailSections = detailSections; this.thumbImages = thumbImages; @@ -48,75 +56,27 @@ public class Item { this.deliveryDays = deliveryDays; } - public Long getId() { - return id; - } - - public Long getSection() { - return section; - } - - public Long getCategory() { - return category; - } - - public String getAlt() { - return alt; - } - - public String getTopImage() { - return topImage; - } - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public BigDecimal getNPrice() { - return nPrice; - } - - public BigDecimal getSPrice() { - return sPrice; - } - - public BigDecimal getDeliveryFee() { - return deliveryFee; - } - - public Integer getStock() { - return stock; - } - - public List getDetailSections() { - return detailSections; - } - - public List getThumbImages() { - return thumbImages; - } - - public Set getBadges() { - return badges; - } - - public Set getDeliveryTypes() { - return deliveryTypes; + public static Item newItem(Long section, Long category, + TopImage topImage, Description description, + Prices prices, + Integer stock) { + return new Item(null, section, category, + topImage, + description, + prices, + stock, + new ArrayList<>(), new ArrayList<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()); } - public Set getDeliveryDays() { - return deliveryDays; + public Long getId() { + return id; } - public void addDetailSection (DetailSection detailSection) { + public void addDetailSection(DetailSection detailSection) { this.detailSections.add(detailSection); } - public void addThumbImage (ThumbImage thumbImage) { + public void addThumbImage(ThumbImage thumbImage) { this.thumbImages.add(thumbImage); } @@ -132,12 +92,68 @@ public void addDeliveryDay(DeliveryDay deliveryDay) { this.deliveryDays.add(deliveryDay); } - public static Item newItem(Long section, Long category, - String alt, String topImage, String title, String description, - BigDecimal nPrice, BigDecimal sPrice, BigDecimal deliveryFee, Integer stock) { - return new Item(null, section, category, - alt, topImage, title, description, - nPrice, sPrice, deliveryFee, stock, - new ArrayList<>(), new ArrayList<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()); + public ItemDetail itemDetail() { + return ItemDetail.of( + topImage.getUrl(), + thumbImagesUrl(), + description.getTitle(), + description.getDescription(), + prices.getPoints(), + deliveryInfo(), + prices.getDeliveryFee(), + prices.getnPrice(), + prices.getsPrice(), + detailSection(), + badge() + ); + } + + public ItemSummary itemSummary() { + return ItemSummary.of( + id, + topImage.getUrl(), + topImage.getAlt(), + deliveryType(), + description.getTitle(), + description.getDescription(), + prices.getnPrice(), + prices.getsPrice(), + badge() + ); + } + + private List thumbImagesUrl() { + return thumbImages.stream() + .map(ThumbImage::getUrl) + .collect(Collectors.toList()); + } + + private String deliveryInfo() { + return deliveryTypes.stream() + .map(DeliveryType::getDetail) + .reduce((x, y) -> String.join(" / ", x, y)) + + " [" + + deliveryDays.stream() + .map(DeliveryDay::korean) + .reduce((x, y) -> String.join(" · ", x, y)) + + "] 수령 가능한 상품입니다."; + } + + private List detailSection() { + return detailSections.stream() + .map(DetailSection::getUrl) + .collect(Collectors.toList()); + } + + private List deliveryType() { + return deliveryTypes.stream() + .map(DeliveryType::getName) + .collect(Collectors.toList()); + } + + private List badge() { + return badges.stream() + .map(Badge::getName) + .collect(Collectors.toList()); } } diff --git a/BE/src/main/java/com/team10/banchan/model/Prices.java b/BE/src/main/java/com/team10/banchan/model/Prices.java new file mode 100644 index 000000000..08b9d0176 --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/model/Prices.java @@ -0,0 +1,42 @@ +package com.team10.banchan.model; + +import org.springframework.data.annotation.Transient; + +import java.math.BigDecimal; +import java.text.DecimalFormat; + +public class Prices { + + @Transient + private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###원"); + + private final BigDecimal nPrice; + private final BigDecimal sPrice; + private final BigDecimal deliveryFee; + + Prices(BigDecimal nPrice, BigDecimal sPrice, BigDecimal deliveryFee) { + this.nPrice = nPrice; + this.sPrice = sPrice; + this.deliveryFee = deliveryFee; + } + + public static Prices of(BigDecimal nPrice, BigDecimal sPrice, BigDecimal deliveryFee) { + return new Prices(nPrice, sPrice, deliveryFee); + } + + public String getnPrice() { + return DECIMAL_FORMAT.format(nPrice); + } + + public String getsPrice() { + return DECIMAL_FORMAT.format(sPrice); + } + + public String getDeliveryFee() { + return DECIMAL_FORMAT.format(deliveryFee); + } + + public String getPoints() { + return DECIMAL_FORMAT.format(sPrice.movePointLeft(2)); + } +} diff --git a/BE/src/main/java/com/team10/banchan/model/Section.java b/BE/src/main/java/com/team10/banchan/model/Section.java index ac8c51d02..93e47ec3f 100644 --- a/BE/src/main/java/com/team10/banchan/model/Section.java +++ b/BE/src/main/java/com/team10/banchan/model/Section.java @@ -2,34 +2,26 @@ import org.springframework.data.annotation.Id; -import java.util.HashSet; -import java.util.Set; - public class Section { + @Id private final Long id; private final String name; - private final Set items; - Section(Long id, String name, Set items) { + Section(Long id, String name) { this.id = id; this.name = name; - this.items = items; } - public Long getId() { - return id; + public static Section newSection(String name) { + return new Section(null, name); } - public Set getItems() { - return items; + public Long getId() { + return id; } public String getName() { return name; } - - public static Section newSection(String name) { - return new Section(null, name, new HashSet<>()); - } } diff --git a/BE/src/main/java/com/team10/banchan/model/ThumbImage.java b/BE/src/main/java/com/team10/banchan/model/ThumbImage.java index ebe57da84..5590977b3 100644 --- a/BE/src/main/java/com/team10/banchan/model/ThumbImage.java +++ b/BE/src/main/java/com/team10/banchan/model/ThumbImage.java @@ -1,17 +1,18 @@ package com.team10.banchan.model; public class ThumbImage { + private final String url; ThumbImage(String url) { this.url = url; } - public String getUrl() { - return url; - } - public static ThumbImage of(String url) { return new ThumbImage(url); } + + public String getUrl() { + return url; + } } diff --git a/BE/src/main/java/com/team10/banchan/model/TopImage.java b/BE/src/main/java/com/team10/banchan/model/TopImage.java new file mode 100644 index 000000000..96eb3e744 --- /dev/null +++ b/BE/src/main/java/com/team10/banchan/model/TopImage.java @@ -0,0 +1,24 @@ +package com.team10.banchan.model; + +public class TopImage { + + private final String alt; + private final String topImage; + + TopImage(String alt, String topImage) { + this.alt = alt; + this.topImage = topImage; + } + + public static TopImage of(String alt, String topImage) { + return new TopImage(alt, topImage); + } + + public String getAlt() { + return alt; + } + + public String getUrl() { + return topImage; + } +} diff --git a/BE/src/test/java/com/team10/banchan/model/PricesTest.java b/BE/src/test/java/com/team10/banchan/model/PricesTest.java new file mode 100644 index 000000000..9a9dbf4b1 --- /dev/null +++ b/BE/src/test/java/com/team10/banchan/model/PricesTest.java @@ -0,0 +1,19 @@ +package com.team10.banchan.model; + +import org.junit.jupiter.api.Test; + +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.*; + +class PricesTest { + @Test + void formatTest() { + Prices prices = Prices.of(new BigDecimal(10000), new BigDecimal(1000000), new BigDecimal(2500) ); + assertThat(prices.getnPrice()).isEqualTo("10,000원"); + assertThat(prices.getsPrice()).isEqualTo("1,000,000원"); + assertThat(prices.getDeliveryFee()).isEqualTo("2,500원"); + + } + +} diff --git a/BE/src/test/java/com/team10/banchan/repository/ItemRepositoryTest.java b/BE/src/test/java/com/team10/banchan/repository/ItemRepositoryTest.java index 1b1f9f8ff..4d3de4eec 100644 --- a/BE/src/test/java/com/team10/banchan/repository/ItemRepositoryTest.java +++ b/BE/src/test/java/com/team10/banchan/repository/ItemRepositoryTest.java @@ -17,6 +17,6 @@ class ItemRepositoryTest { @Test void getItem() { Item item = itemRepository.findById(1L).orElseThrow(RuntimeException::new); - assertThat(item).hasFieldOrPropertyWithValue("alt", "alt"); + assertThat(item).hasFieldOrPropertyWithValue("stock", 3); } } diff --git a/BE/src/test/java/com/team10/banchan/repository/SectionRepositoryTest.java b/BE/src/test/java/com/team10/banchan/repository/SectionRepositoryTest.java index b3cf70801..842d48d53 100644 --- a/BE/src/test/java/com/team10/banchan/repository/SectionRepositoryTest.java +++ b/BE/src/test/java/com/team10/banchan/repository/SectionRepositoryTest.java @@ -17,6 +17,6 @@ public class SectionRepositoryTest { @Test void getSection() { Section section = sectionRepository.findById(1L).orElseThrow(RuntimeException::new); - assertThat(section.getItems()).hasSize(1); + assertThat(section).hasFieldOrPropertyWithValue("name", "main"); } }