Skip to content

Commit

Permalink
Merge pull request #17 from d-h-k/BE
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
moto6 committed Apr 22, 2021
2 parents 3cb8603 + c7ba9e8 commit c8a5c31
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
package com.codesquad.team14.domain;

import org.springframework.data.annotation.Id;

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

public class Category {

@Id
private Long id;

private String name;

private final Set<Item> items = new HashSet<>();

public Category(String name) {
this.name = name;
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

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

public void setName(String name) {
this.name = name;
}

public void addItem(Item item) {
items.add(item);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package com.codesquad.team14.domain;

public enum DeliveryType {
NEXT_DAY, NATIONAL_WIDE
NEXT_DAY("서울 경기 새벽배송"),
NATIONAL_WIDE("전국택배 (제주 및 도서산간 불가) [월, 화, 수, 목, 금, 토] 수령 가능한 상품입니다.");

final private String detail;

DeliveryType(String detail) {
this.detail = detail;
}

public String getDetail() {
return detail;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package com.codesquad.team14.domain;

import java.util.ArrayList;
import org.springframework.data.annotation.Id;

import java.util.List;
import java.util.Objects;

public class Item {
private static final String DELIVERY_FEE_POLICY = "2,500원 (40,000원 이상 구매 시 무료)";

@Id
private Long id;

private final Long id;
private String title;
private String description;
private int normalPrice;
private int salePrice;
private int nPrice;
private int sPrice;
private List<Badge> badges;
private List<DeliveryType> deliveryTypes;
private List<String> thumbImages;
private final Long categoryId;
private String images;
private Category category;

public Item(Long id, String title, String description, int normalPrice, Long categoryId) {
this.id = id;
public Item(String title, String description, int nPrice, int sPrice, Category category) {
this.title = title;
this.description = description;
this.normalPrice = normalPrice;
this.categoryId = categoryId;
this.nPrice = nPrice;
this.sPrice = sPrice;
this.category = category;
}

public Long getId() {
Expand All @@ -35,12 +40,12 @@ public String getDescription() {
return description;
}

public int getNormalPrice() {
return normalPrice;
public int getNPrice() {
return nPrice;
}

public int getSalePrice() {
return salePrice;
public int getSPrice() {
return sPrice;
}

public List<Badge> getBadges() {
Expand All @@ -51,27 +56,27 @@ public List<DeliveryType> getDeliveryTypes() {
return deliveryTypes;
}

public List<String> getThumbImages() {
return thumbImages;
public String getImages() {
return images;
}

public List<Integer> getPrices() {
List<Integer> prices = new ArrayList<>();

if (normalPrice != salePrice) {
prices.add(normalPrice);
}
prices.add(salePrice);

return prices;
public Category getCategory() {
return category;
}

public int getPoint() {
return salePrice / 100;
public String getDeliveryInfo() {
StringBuilder deliverInfo = new StringBuilder();
for (int i = 0; i < deliveryTypes.size(); i++) {
deliverInfo.append(deliveryTypes.get(i).getDetail());
if (i != deliveryTypes.size() - 1) {
deliverInfo.append(" / ");
}
}
return deliverInfo.toString();
}

public Long getCategoryId() {
return categoryId;
public String getDeliveryFeePolicy() {
return DELIVERY_FEE_POLICY;
}

public void setTitle(String title) {
Expand All @@ -82,12 +87,12 @@ public void setDescription(String description) {
this.description = description;
}

public void setNormalPrice(int normalPrice) {
this.normalPrice = normalPrice;
public void setnPrice(int nPrice) {
this.nPrice = nPrice;
}

public void setSalePrice(int salePrice) {
this.salePrice = salePrice;
public void setsPrice(int sPrice) {
this.sPrice = sPrice;
}

public void setBadges(List<Badge> badges) {
Expand All @@ -98,7 +103,24 @@ public void setDeliveryTypes(List<DeliveryType> deliveryTypes) {
this.deliveryTypes = deliveryTypes;
}

public void setThumbImages(List<String> thumbImages) {
this.thumbImages = thumbImages;
public void setImages(String images) {
this.images = images;
}

public void setCategory(Category category) {
this.category = category;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Item item = (Item) o;
return Objects.equals(id, item.id) && Objects.equals(category, item.category);
}

@Override
public int hashCode() {
return Objects.hash(id, category);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
package com.codesquad.team14.dto;

import com.codesquad.team14.domain.Item;

import java.util.Arrays;
import java.util.List;

public class DetailedItemDto {

private static class Response {
private final Long id;
private final String topImage;
private final List<String> thumbImages;
private final String description;
private final String deliveryInfo;
private final String deliveryFee;
private final int nPrice;
private final int sPrice;
private final int point;

public Response(Long id, String topImage, List<String> thumbImages, String description, String deliveryInfo,
String deliveryFee, int nPrice, int sPrice, int point) {
this.id = id;
this.topImage = topImage;
this.thumbImages = thumbImages;
this.description = description;
this.deliveryInfo = deliveryInfo;
this.deliveryFee = deliveryFee;
this.nPrice = nPrice;
this.sPrice = sPrice;
this.point = point;
}

public static Response from(Item item) {
return new Response(
item.getId(),
item.getImages().split(", ")[0],
Arrays.asList(item.getImages().split(", ")),
item.getDescription(),
item.getDeliveryInfo(),
item.getDeliveryFeePolicy(),
item.getNPrice(),
item.getSPrice(),
item.getSPrice() / 100
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
package com.codesquad.team14.dto;

import com.codesquad.team14.domain.Badge;
import com.codesquad.team14.domain.Item;

import java.util.List;

public class ItemDto {
private String temp;
public static class Response {
private final Long id;
private final String topImage;
private final String deliveryTypes;
private final String title;
private final String description;
private final int nPrice;
private final int sPrice;
private final List<Badge> badges;

public ItemDto(String s) {
temp = s;
}
private Response(Long id, String image, String deliveryTypes, String title,
String description, int nPrice, int sPrice, List<Badge> badges) {
this.id = id;
this.topImage = image;
this.deliveryTypes = deliveryTypes;
this.title = title;
this.description = description;
this.nPrice = nPrice;
this.sPrice = sPrice;
this.badges = badges;
}

public String getTemp() {
return temp;
}
public static Response from(Item item) {
return new Response(
item.getId(),
item.getImages().split(", ")[0],
item.getDeliveryTypes().toString(),
item.getTitle(),
item.getDescription(),
item.getNPrice(),
item.getSPrice(),
item.getBadges()
);
}

public Long getId() {
return id;
}

public String getTopImage() {
return topImage;
}

public String getDeliveryTypes() {
return deliveryTypes;
}

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public int getnPrice() {
return nPrice;
}

public int getsPrice() {
return sPrice;
}

public void setTemp(String temp) {
this.temp = temp;
public List<Badge> getBadges() {
return badges;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.codesquad.team14.repository;

import com.codesquad.team14.domain.Category;
import com.codesquad.team14.domain.Item;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryRepository extends CrudRepository<Category, Long> {
}
Loading

0 comments on commit c8a5c31

Please sign in to comment.