Skip to content

Commit

Permalink
feat: Add Constructor and useful methods
Browse files Browse the repository at this point in the history
- Spring Data JDBC의 추천에 따라 생성자와 팩토리 메서드
와 get메서드 추가

issue: #4
  • Loading branch information
bong6981 committed Apr 20, 2021
1 parent 1ac9d01 commit 21be2b7
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 27 deletions.
29 changes: 26 additions & 3 deletions BE/src/main/java/com/team10/banchan/model/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

import org.springframework.data.annotation.Id;

import java.util.HashSet;
import java.util.Set;

public class Category {
@Id
private Long id;
private Set<Item> items;
private String name;
private final Long id;
private final String name;
private final Set<Item> items;

Category(Long id, String name, Set<Item> items) {
this.id = id;
this.name = name;
this.items = items;
}

public Long getId() {
return id;
}

public Set<Item> getItems() {
return items;
}

public String getName() {
return name;
}

public static Category newCategory(String name) {
return new Category(null, name, new HashSet<>());
}
}
14 changes: 13 additions & 1 deletion BE/src/main/java/com/team10/banchan/model/DetailSection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package com.team10.banchan.model;

public class DetailSection {
private String url;
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);
}
}
151 changes: 132 additions & 19 deletions BE/src/main/java/com/team10/banchan/model/Item.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,143 @@
package com.team10.banchan.model;


import org.springframework.data.annotation.Id;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Item {
@Id
private Long id;
private Long section;
private Long category;

private String alt;
private String topImage;
private String title;
private String description;
private BigDecimal nPrice;
private BigDecimal sPrice;
private BigDecimal deliveryFee;
private Integer stock;

private List<DetailSection> detailSections;
private List<ThumbImage> thumbImages;
private Set<Badge> badges;
private Set<DeliveryType> deliveryTypes;
private Set<DeliveryDay> deliveryDays;
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;
private final Integer stock;

private final List<DetailSection> detailSections;
private final List<ThumbImage> thumbImages;
private final Set<Badge> badges;
private final Set<DeliveryType> deliveryTypes;
private final Set<DeliveryDay> 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<DetailSection> detailSections, List<ThumbImage> thumbImages, Set<Badge> badges, Set<DeliveryType> deliveryTypes, Set<DeliveryDay> 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.stock = stock;
this.detailSections = detailSections;
this.thumbImages = thumbImages;
this.badges = badges;
this.deliveryTypes = deliveryTypes;
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<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);
}

public void addThumbImage (ThumbImage thumbImage) {
this.thumbImages.add(thumbImage);
}

public void addBadge(Badge badge) {
this.badges.add(badge);
}

public void addDeliveryType(DeliveryType deliveryType) {
this.deliveryTypes.add(deliveryType);
}

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<>());
}
}
29 changes: 26 additions & 3 deletions BE/src/main/java/com/team10/banchan/model/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

import org.springframework.data.annotation.Id;

import java.util.HashSet;
import java.util.Set;

public class Section {
@Id
private Long id;
private Set<Item> items;
private String name;
private final Long id;
private final String name;
private final Set<Item> items;

Section(Long id, String name, Set<Item> items) {
this.id = id;
this.name = name;
this.items = items;
}

public Long getId() {
return id;
}

public Set<Item> getItems() {
return items;
}

public String getName() {
return name;
}

public static Section newSection(String name) {
return new Section(null, name, new HashSet<>());
}
}
14 changes: 13 additions & 1 deletion BE/src/main/java/com/team10/banchan/model/ThumbImage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package com.team10.banchan.model;

public class ThumbImage {
private String url;
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.team10.banchan.repository;

import com.team10.banchan.model.Section;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import static org.assertj.core.api.Assertions.*;

@SpringBootTest
@Transactional
public class SectionRepositoryTest {
@Autowired
private SectionRepository sectionRepository;

@Test
void getSection() {
Section section = sectionRepository.findById(1L).orElseThrow(RuntimeException::new);
assertThat(section.getItems()).hasSize(1);
}
}

0 comments on commit 21be2b7

Please sign in to comment.