Skip to content

Commit

Permalink
feat: Get ItemDetail from Item
Browse files Browse the repository at this point in the history
- Item 객체에서 ItemDetail 객체를 얻을 수 있습니다.

issue: #8
  • Loading branch information
kihyuk-sung committed Apr 21, 2021
1 parent e44e37c commit 6e8cb9d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
4 changes: 2 additions & 2 deletions BE/src/main/java/com/team10/banchan/dto/ItemDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public List<String> getDetailSection() {
return detailSection;
}

@JsonProperty("badges")
@JsonProperty("badge")
public List<String> getBadges() {
return detailSection;
return badges;
}
}

Expand Down
90 changes: 47 additions & 43 deletions BE/src/main/java/com/team10/banchan/model/Item.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.team10.banchan.model;

import com.team10.banchan.dto.ItemDetail;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Embedded;

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
Expand Down Expand Up @@ -56,49 +58,6 @@ public Long getId() {
return id;
}

public Long getSection() {
return section;
}

public Long getCategory() {
return category;
}

public TopImage getTopImage() {
return topImage;
}

public Description getDescription() {
return description;
}

public Prices getPrices() {
return prices;
}
public Integer getStock() {
return stock;
}

public List<DetailSection> getDetailSections() {
return detailSections;
}

public List<ThumbImage> getThumbImages() {
return thumbImages;
}

public Set<Badge> getBadges() {
return badges;
}

public Set<DeliveryType> getDeliveryTypes() {
return deliveryTypes;
}

public Set<DeliveryDay> getDeliveryDays() {
return deliveryDays;
}

public void addDetailSection (DetailSection detailSection) {
this.detailSections.add(detailSection);
}
Expand All @@ -119,6 +78,51 @@ public void addDeliveryDay(DeliveryDay deliveryDay) {
this.deliveryDays.add(deliveryDay);
}

public ItemDetail itemDetail() {
return ItemDetail.of(
topImage.getTopImage(),
thumbImagesUrl(),
description.getTitle(),
description.getDescription(),
prices.getPoints(),
deliveryInfo(),
prices.getDeliveryFee(),
prices.getnPrice(),
prices.getsPrice(),
detailSection(),
badge()
);
}

private List<String> 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<String> detailSection() {
return detailSections.stream()
.map(DetailSection::getUrl)
.collect(Collectors.toList());
}

private List<String> badge() {
return badges.stream()
.map(Badge::name)
.collect(Collectors.toList());
}

public static Item newItem(Long section, Long category,
TopImage topImage, Description description,
Prices prices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ItemRepositoryTest {
@Test
void getItem() {
Item item = itemRepository.findById(1L).orElseThrow(RuntimeException::new);
assertThat(item.getTopImage()).hasFieldOrPropertyWithValue("alt", "alt");
assertThat(item).hasFieldOrPropertyWithValue("stock", 3);
}
}

0 comments on commit 6e8cb9d

Please sign in to comment.