Skip to content

Commit

Permalink
Merge pull request #17 from Dae-Hwa/BE/preparation/mockup-api
Browse files Browse the repository at this point in the history
[Be] preparation/mockup api
  • Loading branch information
Dae-Hwa committed Apr 23, 2021
2 parents 767f965 + 535cdec commit c812856
Show file tree
Hide file tree
Showing 22 changed files with 2,905 additions and 548 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,67 @@
package com.codesquad.sidedish.utils;

import com.codesquad.sidedish.web.sidedish.SidedishDTO;
import com.codesquad.sidedish.web.sidedish.DTO.ItemDTO;
import com.codesquad.sidedish.web.sidedish.DTO.SidedishDTO;
import com.codesquad.sidedish.web.sidedish.DTO.DetailDTO;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SampleDataFactory {
public static List<SidedishDTO> createBestMenus() {

private SampleDataFactory() {

}

public static List<SidedishDTO> createBestSidedishes() {
return jsonToObject("sample-data/best-sidedishes.json", new TypeReference<List<SidedishDTO>>() {
});
}

public static List<ItemDTO> createMainSidedishes() {
return jsonToObject("sample-data/main-sidedishes.json", new TypeReference<List<ItemDTO>>() {
});
}

public static List<ItemDTO> createCourseSidedishes() {
return jsonToObject("sample-data/course-sidedishes.json", new TypeReference<List<ItemDTO>>() {
});
}

public static List<ItemDTO> createSoupSidedishes() {
return jsonToObject("sample-data/soup-sidedishes.json", new TypeReference<List<ItemDTO>>() {
});
}

public static List<ItemDTO> createSideSidedishes() {
return jsonToObject("sample-data/side-sidedishes.json", new TypeReference<List<ItemDTO>>() {
});
}

public static Map<String, DetailDTO> createDetails() {
List<DetailDTO> detailDTOs = jsonToObject("sample-data/details.json", new TypeReference<List<DetailDTO>>() {
});

return detailDTOs.stream().collect(Collectors.toMap(DetailDTO::getHash, detailDTO -> detailDTO));
}

private static <E> E jsonToObject(String jsonFilePath, TypeReference<E> typeReference) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

try {
return SidedishDTO.listFrom(new ClassPathResource("sample-data/best-sidedishes.json").getFile());
File file = new ClassPathResource(jsonFilePath).getFile();

return objectMapper.readValue(file, typeReference);
} catch (IOException e) {
throw new IllegalStateException("경로가 올바르지 않습니다.");
throw new IllegalStateException("경로가 올바르지 않습니다. 경로: " + jsonFilePath, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
package com.codesquad.sidedish.web.sidedish.DTO;

import com.codesquad.sidedish.web.sidedish.Price;

import java.util.List;
import java.util.stream.Collectors;

public class DetailDTO {
private String hash;
private Data data;

public DetailDTO() {
}

public DetailDTO(String hash, Data data) {
this.hash = hash;
this.data = data;
}

public String getHash() {
return hash;
}

public void setHash(String hash) {
this.hash = hash;
}

public Data getData() {
return data;
}

public void setData(Data data) {
this.data = data;
}


public static final class DetailDTOBuilder {
private String hash;
private Data data;

private DetailDTOBuilder() {
}

public static DetailDTOBuilder create() {
return new DetailDTOBuilder();
}

public DetailDTOBuilder hash(String hash) {
this.hash = hash;
return this;
}

public DetailDTOBuilder data(Data data) {
this.data = data;
return this;
}

public DetailDTO build() {
return new DetailDTO(hash, data);
}
}

public static class Data {
private String topImage;
private List<String> thumbImages;
private String productDescription;
private Price point;
private String deliveryInfo;
private Price deliveryFee;
private List<Price> prices;
private List<String> detailSection;

public Data() {
}

public Data(String topImage, List<String> thumbImages, String productDescription, Price point, String deliveryInfo, Price deliveryFee, List<Price> prices, List<String> detailSection) {
this.topImage = topImage;
this.thumbImages = thumbImages;
this.productDescription = productDescription;
this.point = point;
this.deliveryInfo = deliveryInfo;
this.deliveryFee = deliveryFee;
this.prices = prices;
this.detailSection = detailSection;
}

public String getTopImage() {
return topImage;
}

public void setTopImage(String topImage) {
this.topImage = topImage;
}

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

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

public String getProductDescription() {
return productDescription;
}

public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}

public String getPoint() {
return point.getFormattedPrice();
}

public void setPoint(Price point) {
this.point = point;
}

public String getDeliveryInfo() {
return deliveryInfo;
}

public void setDeliveryInfo(String deliveryInfo) {
this.deliveryInfo = deliveryInfo;
}

public String getDeliveryFee() {
return deliveryFee.getFormattedPrice() + " (40,000원 이상 구매 시 무료)";
}

public void setDeliveryFee(Price deliveryFee) {
this.deliveryFee = deliveryFee;
}

public List<String> getPrices() {
return prices.stream()
.map(Price::getFormattedPrice)
.collect(Collectors.toList());
}

public void setPrices(List<Price> prices) {
this.prices = prices;
}

public List<String> getDetailSection() {
return detailSection;
}

public void setDetailSection(List<String> detailSection) {
this.detailSection = detailSection;
}

public static final class DataBuilder {
private String topImage;
private List<String> thumbImages;
private String productDescription;
private Price point;
private String deliveryInfo;
private Price deliveryFee;
private List<Price> prices;
private List<String> detailSection;

private DataBuilder() {
}

public static DataBuilder create() {
return new DataBuilder();
}

public DataBuilder topImage(String topImage) {
this.topImage = topImage;
return this;
}

public DataBuilder thumbImages(List<String> thumbImages) {
this.thumbImages = thumbImages;
return this;
}

public DataBuilder productDescription(String productDescription) {
this.productDescription = productDescription;
return this;
}

public DataBuilder point(Price point) {
this.point = point;
return this;
}

public DataBuilder deliveryInfo(String deliveryInfo) {
this.deliveryInfo = deliveryInfo;
return this;
}

public DataBuilder deliveryFee(Price deliveryFee) {
this.deliveryFee = deliveryFee;
return this;
}

public DataBuilder prices(List<Price> prices) {
this.prices = prices;
return this;
}

public DataBuilder detailSection(List<String> detailSection) {
this.detailSection = detailSection;
return this;
}

public Data build() {
return new Data(topImage, thumbImages, productDescription, point, deliveryInfo, deliveryFee, prices, detailSection);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.codesquad.sidedish.web.sidedish;
package com.codesquad.sidedish.web.sidedish.DTO;

import com.codesquad.sidedish.web.sidedish.Price;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.List;

public class ItemDTO {
Expand All @@ -11,14 +11,14 @@ public class ItemDTO {
private List<String> deliveryType;
private String title;
private String description;
private long nPrice;
private long sPrice;
private Price nPrice;
private Price sPrice;
private List<String> badge;

public ItemDTO() {
}

public ItemDTO(String detailHash, String image, String alt, List<String> deliveryType, String title, String description, long nPrice, long sPrice, List<String> badge) {
public ItemDTO(String detailHash, String image, String alt, List<String> deliveryType, String title, String description, Price nPrice, Price sPrice, List<String> badge) {
this.detailHash = detailHash;
this.image = image;
this.alt = alt;
Expand Down Expand Up @@ -79,19 +79,19 @@ public void setDescription(String description) {
}

public String getnPrice() {
return NumberFormat.getInstance().format(nPrice);
return nPrice != null ? nPrice.getFormattedPrice() : "";
}

public void setnPrice(String nPrice) throws ParseException {
this.nPrice = NumberFormat.getInstance().parse(nPrice).longValue();
public void setnPrice(Price nPrice) {
this.nPrice = nPrice;
}

public String getsPrice() {
return NumberFormat.getInstance().format(sPrice);
return sPrice != null ? sPrice.getFormattedPrice() : "";
}

public void setsPrice(String sPrice) throws ParseException {
this.sPrice = NumberFormat.getInstance().parse(sPrice).longValue();
public void setsPrice(Price sPrice) {
this.sPrice = sPrice;
}

public List<String> getBadge() {
Expand All @@ -109,8 +109,8 @@ public static final class ItemDTOBuilder {
private List<String> deliveryType;
private String title;
private String description;
private long nPrice;
private long sPrice;
private Price nPrice;
private Price sPrice;
private List<String> badge;

private ItemDTOBuilder() {
Expand Down Expand Up @@ -150,12 +150,12 @@ public ItemDTOBuilder description(String description) {
return this;
}

public ItemDTOBuilder nPrice(long nPrice) {
public ItemDTOBuilder nPrice(Price nPrice) {
this.nPrice = nPrice;
return this;
}

public ItemDTOBuilder sPrice(long sPrice) {
public ItemDTOBuilder sPrice(Price sPrice) {
this.sPrice = sPrice;
return this;
}
Expand Down
Loading

0 comments on commit c812856

Please sign in to comment.