-
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.
Merge pull request #17 from Dae-Hwa/BE/preparation/mockup-api
[Be] preparation/mockup api
- Loading branch information
Showing
22 changed files
with
2,905 additions
and
548 deletions.
There are no files selected for viewing
58 changes: 54 additions & 4 deletions
58
be/sidedish-be/src/main/java/com/codesquad/sidedish/utils/SampleDataFactory.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,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); | ||
} | ||
} | ||
} |
216 changes: 216 additions & 0 deletions
216
be/sidedish-be/src/main/java/com/codesquad/sidedish/web/sidedish/DTO/DetailDTO.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,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); | ||
} | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.