diff --git a/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java b/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java index ef9be3705..ec71723ab 100644 --- a/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java +++ b/BE/src/main/java/com/team10/banchan/dto/ItemDetail.java @@ -5,18 +5,22 @@ 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 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; diff --git a/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java b/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java index e26c352ab..1d56e63ba 100644 --- a/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java +++ b/BE/src/main/java/com/team10/banchan/dto/ItemDetailResponse.java @@ -3,14 +3,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class ItemDetailResponse { - private Long id; - private ItemDetail itemDetail; - public ItemDetailResponse(Long id, ItemDetail itemDetail) { + 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; 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 index 4b4a498d2..84856e05d 100644 --- a/BE/src/main/java/com/team10/banchan/model/Description.java +++ b/BE/src/main/java/com/team10/banchan/model/Description.java @@ -1,6 +1,7 @@ package com.team10.banchan.model; public class Description { + private final String title; private final String 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 e7e60613c..66e0c80d7 100644 --- a/BE/src/main/java/com/team10/banchan/model/Item.java +++ b/BE/src/main/java/com/team10/banchan/model/Item.java @@ -12,6 +12,7 @@ import java.util.stream.Collectors; public class Item { + @Id private final Long id; private final Long section; @@ -55,15 +56,27 @@ public class Item { this.deliveryDays = deliveryDays; } + 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 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); } @@ -81,7 +94,7 @@ public void addDeliveryDay(DeliveryDay deliveryDay) { public ItemDetail itemDetail() { return ItemDetail.of( - topImage.getTopImage(), + topImage.getUrl(), thumbImagesUrl(), description.getTitle(), description.getDescription(), @@ -98,7 +111,7 @@ public ItemDetail itemDetail() { public ItemSummary itemSummary() { return ItemSummary.of( id, - topImage.getTopImage(), + topImage.getUrl(), topImage.getAlt(), deliveryType(), description.getTitle(), @@ -140,19 +153,7 @@ private List deliveryType() { private List badge() { return badges.stream() - .map(Badge::name) + .map(Badge::getName) .collect(Collectors.toList()); } - - 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<>()); - } } diff --git a/BE/src/main/java/com/team10/banchan/model/Prices.java b/BE/src/main/java/com/team10/banchan/model/Prices.java index 1d54454b6..08b9d0176 100644 --- a/BE/src/main/java/com/team10/banchan/model/Prices.java +++ b/BE/src/main/java/com/team10/banchan/model/Prices.java @@ -6,6 +6,7 @@ import java.text.DecimalFormat; public class Prices { + @Transient private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###원"); @@ -20,7 +21,7 @@ public class Prices { } public static Prices of(BigDecimal nPrice, BigDecimal sPrice, BigDecimal deliveryFee) { - return new Prices(nPrice,sPrice, deliveryFee); + return new Prices(nPrice, sPrice, deliveryFee); } public String getnPrice() { 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 index 277ae2d0a..96eb3e744 100644 --- a/BE/src/main/java/com/team10/banchan/model/TopImage.java +++ b/BE/src/main/java/com/team10/banchan/model/TopImage.java @@ -1,6 +1,7 @@ package com.team10.banchan.model; public class TopImage { + private final String alt; private final String topImage; @@ -17,7 +18,7 @@ public String getAlt() { return alt; } - public String getTopImage() { + public String getUrl() { return topImage; } } 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"); } }