-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Constructor and useful methods
- Spring Data JDBC의 추천에 따라 생성자와 팩토리 메서드 와 get메서드 추가 issue: #4
- Loading branch information
Showing
6 changed files
with
232 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
BE/src/main/java/com/team10/banchan/model/DetailSection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BE/src/test/java/com/team10/banchan/repository/SectionRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |