code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,41 @@
+package christmas.domain;
+
+import christmas.message.ExceptionMessage;
+import java.util.List;
+
+public record DecemberDate(int dateAmount) {
+ private static final List<Integer> WEEKEND_DATES = List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final int MINIMUM_DATE_AMOUNT = 1;
+ private static final int MAXIMUM_DATE_AMOUNT = 31;
+
+ public DecemberDate {
+ validateDate(dateAmount);
+ }
+
+ private void validateDate(int dateAmount) {
+ if (isOutOfDateRange(dateAmount)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_DATE);
+ }
+ }
+
+ private boolean isOutOfDateRange(int dateAmount) {
+ return dateAmount < MINIMUM_DATE_AMOUNT || dateAmount > MAXIMUM_DATE_AMOUNT;
+ }
+
+ public boolean isLessThan(DecemberDate date) {
+ return dateAmount < date.dateAmount();
+ }
+
+ public boolean isMoreThan(DecemberDate date) {
+ return dateAmount > date.dateAmount();
+ }
+
+ public boolean isWeekend() {
+ return WEEKEND_DATES.contains(dateAmount);
+ }
+
+ public boolean isWeekday() {
+ return !isWeekend();
+ }
+
+} | Java | ๋๋ฆ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์ด์๋๋ฐ ์ญ์ ํผ๋๋ฐฑ ํด์ฃผ์
จ๋ค์! ใ
ใ
๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,27 @@
+package christmas;
+
+import christmas.domain.Money;
+import christmas.message.ExceptionMessage;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+public class MoneyTest {
+ @DisplayName("๊ธ์ก์ 0์ ์ด์์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์๋๋ค.")
+ @ParameterizedTest
+ @ValueSource(ints = {0, 10, 100, 1000, 999999, 1000000})
+ void moneySuccessTest(int amount) {
+ Assertions.assertThatNoException()
+ .isThrownBy(() -> new Money(amount));
+ }
+
+ @DisplayName("๊ธ์ก์ 0์ ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @ParameterizedTest
+ @ValueSource(ints = {-10, -100, -1000, -999999, -1000000})
+ void moneyFailTest(int amount) {
+ Assertions.assertThatThrownBy(() -> new Money(amount))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ExceptionMessage.INVALID_MONEY);
+ }
+} | Java | ์,, ์ด๋ฐ ๊ธฐ๋ฅ๋ ์์๊ตฐ์! ๊ฐ์ฌํฉ๋๋ค! ใ
ใ
|
@@ -0,0 +1,33 @@
+package christmas.domain;
+
+public enum EventBadge {
+ SANTA("์ฐํ", new Money( 20000)),
+ TREE("ํธ๋ฆฌ", new Money( 10000)),
+ STAR("๋ณ", new Money(5000)),
+ NONE("์์", new Money(0));
+
+ private final String name;
+ private final Money price;
+
+ EventBadge(String name, Money price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public static EventBadge findByTotalDiscountPrice(Money totalDiscountMoney) {
+ if (totalDiscountMoney.isMoreOrEqualThan(SANTA.price)) {
+ return SANTA;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(TREE.price)) {
+ return TREE;
+ }
+ if (totalDiscountMoney.isMoreOrEqualThan(STAR.price)) {
+ return STAR;
+ }
+ return NONE;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | enum์์ ๊ฐ์ฒด๋ฅผ ๋ฃ๊ณ ์ถ์๋๋ฐ ๋ฐฉ๋ฒ์ด ์์๊ตฐ์ ๋ฐฐ์๊ฐ๋๋ค! |
@@ -0,0 +1,41 @@
+package christmas.domain;
+
+import christmas.message.ExceptionMessage;
+import java.util.List;
+
+public record DecemberDate(int dateAmount) {
+ private static final List<Integer> WEEKEND_DATES = List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final int MINIMUM_DATE_AMOUNT = 1;
+ private static final int MAXIMUM_DATE_AMOUNT = 31;
+
+ public DecemberDate {
+ validateDate(dateAmount);
+ }
+
+ private void validateDate(int dateAmount) {
+ if (isOutOfDateRange(dateAmount)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_DATE);
+ }
+ }
+
+ private boolean isOutOfDateRange(int dateAmount) {
+ return dateAmount < MINIMUM_DATE_AMOUNT || dateAmount > MAXIMUM_DATE_AMOUNT;
+ }
+
+ public boolean isLessThan(DecemberDate date) {
+ return dateAmount < date.dateAmount();
+ }
+
+ public boolean isMoreThan(DecemberDate date) {
+ return dateAmount > date.dateAmount();
+ }
+
+ public boolean isWeekend() {
+ return WEEKEND_DATES.contains(dateAmount);
+ }
+
+ public boolean isWeekday() {
+ return !isWeekend();
+ }
+
+} | Java | 7๋ก ๋๋ ๋๋จธ์ง๊ฐ 1,2์ธ์ ์ ์ด์ฉํด์ ๊ตฌํ๋ ๋ฐฉ๋ฒ์ ๋ณ๋ก์ผ๊น์! ๊ทธ๋ ๊ฒ ํ๋ฉด ์์๊ฐ ํ์์์ด์ง๊ฒ๊ฐ์์! |
@@ -0,0 +1,59 @@
+package christmas.domain;
+
+import christmas.domain.discount.DiscountRepository;
+import christmas.domain.discount.GiftDiscount;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.OrderRepository;
+
+public class Reservation {
+ private final DiscountRepository discountRepository;
+ private final DecemberDate decemberDate;
+ private final OrderRepository orderRepository;
+
+ private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) {
+ this.decemberDate = decemberDate;
+ this.orderRepository = orderRepository;
+ this.discountRepository = DiscountRepository.of(decemberDate, orderRepository);
+ }
+
+ public static Reservation of(DecemberDate decemberDate, OrderRepository menus) {
+ return new Reservation(decemberDate, menus);
+ }
+
+ public Menu calculateGift() {
+ return discountRepository.calculateGift();
+ }
+
+ public Money calculateTotalOriginalMoney() {
+ return orderRepository.calculateTotalPrice();
+ }
+
+ public Money calculateTotalDiscountMoney() {
+ return discountRepository.calculateTotalDiscountMoney();
+ }
+
+ public Money calculateTotalFinalMoney() {
+ Money discountMoney = calculateTotalDiscountMoney();
+ if (discountRepository.hasGiftDiscount()) {
+ discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice());
+ }
+ return calculateTotalOriginalMoney().minus(discountMoney);
+ }
+
+ public EventBadge calculateEventBadge() {
+ Money totalDiscountMoney = calculateTotalDiscountMoney();
+ return EventBadge.findByTotalDiscountPrice(totalDiscountMoney);
+ }
+
+ public DiscountRepository getDiscountRepository() {
+ return discountRepository;
+ }
+
+ public DecemberDate getDecemberDate() {
+ return decemberDate;
+ }
+
+ public OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+} | Java | ํด๋์ค ์ด๋ฆ์ ์ง์๋ Repository๋ผ๋ ๋จ์ด๊ฐ ๊ฐ์ง๋ ๊ด๋ก์ ์ธ ๊ตญ๋ฃฐ(?)์ด ์์ด์ ํด๋น ๋จ์ด๋ฅผ ์ฐ์ ๊ฑด๊ฐ์? ์๋๋ฉด ๊ฐ์ธ์ ์ธ ์๊ฐ์์ ์ง์ผ์ ๊ฑด๊ฐ์! (์์ ๊ถ๊ธ์ฆ์
๋๋ค!) |
@@ -0,0 +1,59 @@
+package christmas.domain;
+
+import christmas.domain.discount.DiscountRepository;
+import christmas.domain.discount.GiftDiscount;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.OrderRepository;
+
+public class Reservation {
+ private final DiscountRepository discountRepository;
+ private final DecemberDate decemberDate;
+ private final OrderRepository orderRepository;
+
+ private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) {
+ this.decemberDate = decemberDate;
+ this.orderRepository = orderRepository;
+ this.discountRepository = DiscountRepository.of(decemberDate, orderRepository);
+ }
+
+ public static Reservation of(DecemberDate decemberDate, OrderRepository menus) {
+ return new Reservation(decemberDate, menus);
+ }
+
+ public Menu calculateGift() {
+ return discountRepository.calculateGift();
+ }
+
+ public Money calculateTotalOriginalMoney() {
+ return orderRepository.calculateTotalPrice();
+ }
+
+ public Money calculateTotalDiscountMoney() {
+ return discountRepository.calculateTotalDiscountMoney();
+ }
+
+ public Money calculateTotalFinalMoney() {
+ Money discountMoney = calculateTotalDiscountMoney();
+ if (discountRepository.hasGiftDiscount()) {
+ discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice());
+ }
+ return calculateTotalOriginalMoney().minus(discountMoney);
+ }
+
+ public EventBadge calculateEventBadge() {
+ Money totalDiscountMoney = calculateTotalDiscountMoney();
+ return EventBadge.findByTotalDiscountPrice(totalDiscountMoney);
+ }
+
+ public DiscountRepository getDiscountRepository() {
+ return discountRepository;
+ }
+
+ public DecemberDate getDecemberDate() {
+ return decemberDate;
+ }
+
+ public OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+} | Java | ๋ถ๋ฆฌ๊ฐ ์๋์ ๊ทธ๋ฐ๊ฐ ํ ์ธ ๋ ์ง ์ฃผ๋ฌธ์ ํ๊ณณ์ ๋ฃ์ด๋ ๊ฐ๋
์ฑ์ด ๋งค์ฐ ๊น๋ํ๋ค์,, ๊ฐํํ๊ณ ๊ฐ๋๋ค |
@@ -0,0 +1,45 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public record Order(Menu menu, int count) {
+ private static final String FORMAT_MENU_ORDER = "([๊ฐ-ํฃ]+)-(\\d+)";
+ private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER);
+ private static final int NAME_INDEX = 1;
+ private static final int COUNT_INDEX = 2;
+
+ public Order {
+ validateNotNull(menu);
+ validateCount(count);
+ }
+
+ public static Order createByString(String menuString) {
+ Matcher matcher = PATTERN_MENU.matcher(menuString);
+ validateFormat(matcher);
+ Menu menu = Menu.findByName(matcher.group(NAME_INDEX));
+ int count = Integer.parseInt(matcher.group(COUNT_INDEX));
+ return new Order(menu, count);
+ }
+
+ private static void validateFormat(Matcher matcher) {
+ if (matcher.matches()) {
+ return;
+ }
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+
+ private static void validateNotNull(Menu menu) {
+ if (Objects.isNull(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateCount(int count) {
+ if (count <= 0) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | ์์์ Matcher๋ฅผ ํตํด ์ ๊ท์์ ๊ฐ๋จํ๊ฒ ํํํ๊ฒ ์ธ์๊น์ด์ ! |
@@ -0,0 +1,45 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public record Order(Menu menu, int count) {
+ private static final String FORMAT_MENU_ORDER = "([๊ฐ-ํฃ]+)-(\\d+)";
+ private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER);
+ private static final int NAME_INDEX = 1;
+ private static final int COUNT_INDEX = 2;
+
+ public Order {
+ validateNotNull(menu);
+ validateCount(count);
+ }
+
+ public static Order createByString(String menuString) {
+ Matcher matcher = PATTERN_MENU.matcher(menuString);
+ validateFormat(matcher);
+ Menu menu = Menu.findByName(matcher.group(NAME_INDEX));
+ int count = Integer.parseInt(matcher.group(COUNT_INDEX));
+ return new Order(menu, count);
+ }
+
+ private static void validateFormat(Matcher matcher) {
+ if (matcher.matches()) {
+ return;
+ }
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+
+ private static void validateNotNull(Menu menu) {
+ if (Objects.isNull(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateCount(int count) {
+ if (count <= 0) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | ์๋ Matcher์ Pattern์ผ๋ก ์ ๊ท์์ ๊ด๋ฆฌํ๋๊ฒ ์ ์์ธ๊ฐ์? ์ด๋ฐ๋ฐฉ๋ฒ์ด ์์๋์ง ์ฒ์์์์ต๋๋ค! ๊ต์ฅํ ๊น๋ํ๊ฒ๊ฐ์์ |
@@ -0,0 +1,41 @@
+package christmas.domain;
+
+import christmas.message.ExceptionMessage;
+import java.util.List;
+
+public record DecemberDate(int dateAmount) {
+ private static final List<Integer> WEEKEND_DATES = List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30);
+ private static final int MINIMUM_DATE_AMOUNT = 1;
+ private static final int MAXIMUM_DATE_AMOUNT = 31;
+
+ public DecemberDate {
+ validateDate(dateAmount);
+ }
+
+ private void validateDate(int dateAmount) {
+ if (isOutOfDateRange(dateAmount)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_DATE);
+ }
+ }
+
+ private boolean isOutOfDateRange(int dateAmount) {
+ return dateAmount < MINIMUM_DATE_AMOUNT || dateAmount > MAXIMUM_DATE_AMOUNT;
+ }
+
+ public boolean isLessThan(DecemberDate date) {
+ return dateAmount < date.dateAmount();
+ }
+
+ public boolean isMoreThan(DecemberDate date) {
+ return dateAmount > date.dateAmount();
+ }
+
+ public boolean isWeekend() {
+ return WEEKEND_DATES.contains(dateAmount);
+ }
+
+ public boolean isWeekday() {
+ return !isWeekend();
+ }
+
+} | Java | ์ํ ๊ทธ๋ฐ ๋ฐฉ๋ฒ๋ ์๊ตฐ์! ๋ฐฐ์๊ฐ๋๋ค!๐ |
@@ -0,0 +1,59 @@
+package christmas.domain;
+
+import christmas.domain.discount.DiscountRepository;
+import christmas.domain.discount.GiftDiscount;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.OrderRepository;
+
+public class Reservation {
+ private final DiscountRepository discountRepository;
+ private final DecemberDate decemberDate;
+ private final OrderRepository orderRepository;
+
+ private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) {
+ this.decemberDate = decemberDate;
+ this.orderRepository = orderRepository;
+ this.discountRepository = DiscountRepository.of(decemberDate, orderRepository);
+ }
+
+ public static Reservation of(DecemberDate decemberDate, OrderRepository menus) {
+ return new Reservation(decemberDate, menus);
+ }
+
+ public Menu calculateGift() {
+ return discountRepository.calculateGift();
+ }
+
+ public Money calculateTotalOriginalMoney() {
+ return orderRepository.calculateTotalPrice();
+ }
+
+ public Money calculateTotalDiscountMoney() {
+ return discountRepository.calculateTotalDiscountMoney();
+ }
+
+ public Money calculateTotalFinalMoney() {
+ Money discountMoney = calculateTotalDiscountMoney();
+ if (discountRepository.hasGiftDiscount()) {
+ discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice());
+ }
+ return calculateTotalOriginalMoney().minus(discountMoney);
+ }
+
+ public EventBadge calculateEventBadge() {
+ Money totalDiscountMoney = calculateTotalDiscountMoney();
+ return EventBadge.findByTotalDiscountPrice(totalDiscountMoney);
+ }
+
+ public DiscountRepository getDiscountRepository() {
+ return discountRepository;
+ }
+
+ public DecemberDate getDecemberDate() {
+ return decemberDate;
+ }
+
+ public OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+} | Java | ๊ด๋ก๊ฐ ์๋์ง๋ ๋ชจ๋ฅด๊ฒ ๋๋ฐ ๋๋ถ๋ถ๋ค Repository ๋ผ๊ณ ํ๋๋ผ๊ณ ์! ํน์ ๊ท์น์ด ์๋์ง๋ ์ ๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค์! ๐ |
@@ -0,0 +1,45 @@
+package christmas.domain.menu;
+
+import christmas.message.ExceptionMessage;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public record Order(Menu menu, int count) {
+ private static final String FORMAT_MENU_ORDER = "([๊ฐ-ํฃ]+)-(\\d+)";
+ private static final Pattern PATTERN_MENU = Pattern.compile(FORMAT_MENU_ORDER);
+ private static final int NAME_INDEX = 1;
+ private static final int COUNT_INDEX = 2;
+
+ public Order {
+ validateNotNull(menu);
+ validateCount(count);
+ }
+
+ public static Order createByString(String menuString) {
+ Matcher matcher = PATTERN_MENU.matcher(menuString);
+ validateFormat(matcher);
+ Menu menu = Menu.findByName(matcher.group(NAME_INDEX));
+ int count = Integer.parseInt(matcher.group(COUNT_INDEX));
+ return new Order(menu, count);
+ }
+
+ private static void validateFormat(Matcher matcher) {
+ if (matcher.matches()) {
+ return;
+ }
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+
+ private static void validateNotNull(Menu menu) {
+ if (Objects.isNull(menu)) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+
+ private static void validateCount(int count) {
+ if (count <= 0) {
+ throw new IllegalArgumentException(ExceptionMessage.INVALID_ORDER);
+ }
+ }
+} | Java | ๋ค๋ฅธ๋ถ๋ค์ ์ ๊ทํํ์์ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ์ ๋ชจ๋ฅด๊ฒ ๋๋ฐ ์ ๋ ์ด๋ฌํ ๋ฐฉ์๋๋ก ์ฌ์ฉํฉ๋๋ค! ใ
ใ
|
@@ -0,0 +1,54 @@
+package christmas;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.menu.OrderRepository;
+import christmas.domain.Reservation;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.function.Supplier;
+
+public class ChristmasController {
+ public static void run() {
+ Reservation reservation = initReservation();
+ printOrderInformation(reservation);
+ printDiscountInformation(reservation);
+ }
+
+ private static Reservation initReservation() {
+ OutputView.printWelcomeMessage();
+ DecemberDate date = initDecemberDate();
+ OrderRepository orderRepository = initOrderRepository();
+ return Reservation.of(date, orderRepository);
+ }
+
+ private static DecemberDate initDecemberDate() {
+ return receiveValidatedValue(() -> new DecemberDate(InputView.readDate()));
+ }
+
+ private static OrderRepository initOrderRepository() {
+ return receiveValidatedValue(() -> OrderRepository.createByString(InputView.readOrders()));
+ }
+
+ private static <T> T receiveValidatedValue(Supplier<T> inputMethod) {
+ try {
+ return inputMethod.get();
+ } catch (IllegalArgumentException exception) {
+ OutputView.printException(exception);
+ return receiveValidatedValue(inputMethod);
+ }
+ }
+
+ private static void printOrderInformation(Reservation reservation) {
+ OutputView.printEventPreMessage(reservation.getDecemberDate());
+ OutputView.printOrderMenus(reservation.getOrderRepository());
+ }
+
+ private static void printDiscountInformation(Reservation reservation) {
+ OutputView.printOriginalPrice(reservation.calculateTotalOriginalMoney());
+ OutputView.printGiftMenu(reservation.calculateGift());
+ OutputView.printDiscountLogs(reservation.getDiscountRepository());
+ OutputView.printTotalDiscountMoney(reservation.calculateTotalDiscountMoney());
+ OutputView.printToTalFinalPrice(reservation.calculateTotalFinalMoney());
+ OutputView.printEventBadge(reservation.calculateEventBadge());
+ }
+} | Java | ๋๋ค์์ ํ์ฉํ์ฌ ๋ฐ๋ณต์
๋ ฅ ์์ธ์ฒ๋ฆฌ๋ฅผ ํ ๋ฒ๋ง ํ๋ ๋ฐฉ์๋ ์๊ตฐ์. ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค. ์ข์ ๋ฐฉ์์ธ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,59 @@
+package christmas.domain;
+
+import christmas.domain.discount.DiscountRepository;
+import christmas.domain.discount.GiftDiscount;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.OrderRepository;
+
+public class Reservation {
+ private final DiscountRepository discountRepository;
+ private final DecemberDate decemberDate;
+ private final OrderRepository orderRepository;
+
+ private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) {
+ this.decemberDate = decemberDate;
+ this.orderRepository = orderRepository;
+ this.discountRepository = DiscountRepository.of(decemberDate, orderRepository);
+ }
+
+ public static Reservation of(DecemberDate decemberDate, OrderRepository menus) {
+ return new Reservation(decemberDate, menus);
+ }
+
+ public Menu calculateGift() {
+ return discountRepository.calculateGift();
+ }
+
+ public Money calculateTotalOriginalMoney() {
+ return orderRepository.calculateTotalPrice();
+ }
+
+ public Money calculateTotalDiscountMoney() {
+ return discountRepository.calculateTotalDiscountMoney();
+ }
+
+ public Money calculateTotalFinalMoney() {
+ Money discountMoney = calculateTotalDiscountMoney();
+ if (discountRepository.hasGiftDiscount()) {
+ discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice());
+ }
+ return calculateTotalOriginalMoney().minus(discountMoney);
+ }
+
+ public EventBadge calculateEventBadge() {
+ Money totalDiscountMoney = calculateTotalDiscountMoney();
+ return EventBadge.findByTotalDiscountPrice(totalDiscountMoney);
+ }
+
+ public DiscountRepository getDiscountRepository() {
+ return discountRepository;
+ }
+
+ public DecemberDate getDecemberDate() {
+ return decemberDate;
+ }
+
+ public OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+} | Java | ์ ๊ฐ ์๊ธฐ๋ก๋ Repositoy๋ ์ฃผ๋ก ๋ฐ์ดํฐ ๋ฒ ์ด์ค ์ฐ๊ฒฐ๊ณผ ๊ด๋ จํ ๊ฐ์ฒด๋ก ๋ง์ด ์ฌ์ฉํ๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค. ์ธ๋ถ์ ์์คํ
๊ณผ ์ฐ๊ฒฐํ๋ ์ฌ์ฌ์ฉ๋๋ ๋ก์ง์ ์ฃผ๋ก ์ฒ๋ฆฌํ๋ ์ญํ ์ ํฉ๋๋ค. |
@@ -0,0 +1,59 @@
+package christmas.domain;
+
+import christmas.domain.discount.DiscountRepository;
+import christmas.domain.discount.GiftDiscount;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.OrderRepository;
+
+public class Reservation {
+ private final DiscountRepository discountRepository;
+ private final DecemberDate decemberDate;
+ private final OrderRepository orderRepository;
+
+ private Reservation(DecemberDate decemberDate, OrderRepository orderRepository) {
+ this.decemberDate = decemberDate;
+ this.orderRepository = orderRepository;
+ this.discountRepository = DiscountRepository.of(decemberDate, orderRepository);
+ }
+
+ public static Reservation of(DecemberDate decemberDate, OrderRepository menus) {
+ return new Reservation(decemberDate, menus);
+ }
+
+ public Menu calculateGift() {
+ return discountRepository.calculateGift();
+ }
+
+ public Money calculateTotalOriginalMoney() {
+ return orderRepository.calculateTotalPrice();
+ }
+
+ public Money calculateTotalDiscountMoney() {
+ return discountRepository.calculateTotalDiscountMoney();
+ }
+
+ public Money calculateTotalFinalMoney() {
+ Money discountMoney = calculateTotalDiscountMoney();
+ if (discountRepository.hasGiftDiscount()) {
+ discountMoney = discountMoney.minus(GiftDiscount.getGift().getPrice());
+ }
+ return calculateTotalOriginalMoney().minus(discountMoney);
+ }
+
+ public EventBadge calculateEventBadge() {
+ Money totalDiscountMoney = calculateTotalDiscountMoney();
+ return EventBadge.findByTotalDiscountPrice(totalDiscountMoney);
+ }
+
+ public DiscountRepository getDiscountRepository() {
+ return discountRepository;
+ }
+
+ public DecemberDate getDecemberDate() {
+ return decemberDate;
+ }
+
+ public OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+} | Java | ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์
จ๋๋ฐ ํน์ ์ด ๋ฉ์๋์ ์ฅ์ ์ด ์ด๋ค ์ ์ธ์ง ์ ์ ์์๊น์? (๊ถ๊ธ์ฆ ์
๋๋ค.) |
@@ -0,0 +1,29 @@
+package christmas.domain.discount;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.Money;
+import java.util.List;
+
+public class SpecialDiscount {
+ public static final String NAME = "ํน๋ณ ํ ์ธ";
+ private static final int DISCOUNT_AMOUNT = 1000;
+ private static final List<DecemberDate> specialDates = List.of(
+ new DecemberDate(3),
+ new DecemberDate(10),
+ new DecemberDate(17),
+ new DecemberDate(24),
+ new DecemberDate(25),
+ new DecemberDate(31)
+ );
+
+ public static Money calculateDiscountAmount(DecemberDate date) {
+ if (isSpecialDate(date)) {
+ return new Money(DISCOUNT_AMOUNT);
+ }
+ return new Money(0);
+ }
+
+ private static boolean isSpecialDate(DecemberDate date) {
+ return specialDates.contains(date);
+ }
+} | Java | 7๋ก ๋๋์ด์ 3์ด ๋๋ ๊ฒฝ์ฐ๋ก ํํํ๋ฉด ์ฝ๋์ ๊ธธ์ด๋ฅผ ์ค์ผ ์ ์์๊ฒ ๊ฐ์ต๋๋ค. ๊ฐ ๋๋จธ์ง ๊ฐ์ด ํ๋์ ์์ผ์ ๋์๋๋ฏ๋ก, ๋๋จธ์ง ๊ฐ์ ๊ฐ๊ฐ์ ์์ผ๊ณผ ๋์์ํค๋ ๋ฐฉ๋ฒ๋ ํจ๊ณผ์ ์ผ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,133 @@
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+
+- [X] ํ๋ก๊ทธ๋จ ์์ ์, "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค." ์ถ๋ ฅ
+
+- [X] ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)" ์ถ๋ ฅ
+ - [X] ์ซ์๋ก๋ง ์
๋ ฅ ๋ฐ์๋์ง ํ์ธ
+ - [X] ์ซ์๊ฐ ์๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐ, NumberFormatException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] 1 ~ 31 ๋ฒ์ ๋ด์ธ์ง ํ์ธ
+ - [X] ๋ฒ์ ์ธ์ ๊ฐ ์
๋ ฅํ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ๋ฉ์์ง ์ถ๋ ฅํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+
+- [X] ๋ฉ๋ด ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] enum์ผ๋ก ๋ฉ๋ด ๊ตฌํ
+ - [X] "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)" ์ถ๋ ฅ
+ - [] ์ฌ๋ฐ๋ฅธ ๋ฉ๋ด๋ฅผ ์
๋ ฅ ๋ฐ์๋์ง ํ์ธ
+ - [X] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅ๋ฐ์ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] ๋ฉ๋ด์ ๊ฐ์๊ฐ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, NumberFormatException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] ๋ฉ๋ด์ ๊ฐ์๊ฐ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] ์๋ฃ ๋ฉ๋ด๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ, IllegalArgumentException ๋ฐ์
+ - [X] "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅ ํ ๋ค์ ์
๋ ฅ ๋ฐ๊ธฐ
+
+- [X] "12์ n์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!" ์ถ๋ ฅ
+
+- [X] ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ ํ๊ธฐ
+ - [X] "<์ฃผ๋ฌธ ๋ฉ๋ด>" ์ถ๋ ฅ
+ - [X] "๋ฉ๋ด๋ช
n๊ฐ" ํ์์ผ๋ก ์ถ๋ ฅ
+
+- [X] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅํ๊ธฐ
+ - [X] "<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>" ์ถ๋ ฅ
+ - [X] ์ด์ฃผ๋ฌธ ๊ธ์ก ๊ณ์ฐ ํ ์ถ๋ ฅ
+
+- [X] ์ด๋ฒคํธ ์์ธ์ฒ๋ฆฌํ๊ธฐ
+ - [X] ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+ - [X] ์๋ฃ๋ง ์ฃผ๋ฌธํ ๊ฒฝ์ฐ, ์ฃผ๋ฌธํ ์ ์์
+ - [X] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธ ๊ฐ๋ฅ
+
+- [X] ์ด๋ฒคํธ ์ ์ฉํ๊ธฐ
+ - [X] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ํด๋น ์ฌ๋ถ ํ์ธ ๋ฐ ์ ์ฉํ๊ธฐ
+ - [X] ํ์ผ ํ ์ธ ํด๋น ์ฌ๋ถ ํ์ธ ๋ฐ ์ ์ฉํ๊ธฐ
+ - [X] ์ฃผ๋ง ํ ์ธ ํด๋น ์ฌ๋ถ ํ์ธ ๋ฐ ์ ์ฉํ๊ธฐ
+ - [X] ํน๋ณ ํ ์ธ ํด๋น ์ฌ๋ถ ํ์ธ ๋ฐ ์ ์ฉํ๊ธฐ
+ - [X] ์ฆ์ ์ด๋ฒคํธ ํด๋น ์ฌ๋ถ ํ์ธ ๋ฐ ์ ์ฉํ๊ธฐ
+
+- [X] ์ฆ์ ๋ฉ๋ด ์ถ๋ ฅํ๊ธฐ
+ - [X] ๋ง์ฝ ์ดํ์ธ ์ฆ์ ์ด ํด๋น๋๋ฉด "์ดํ์ธ 1๊ฐ" ์ถ๋ ฅ
+ - [X] ์๋๋ฉด "์์" ์ถ๋ ฅ
+
+- [X] ํํ ๋ด์ญ ์ถ๋ ฅํ๊ธฐ
+ - [X] ๊ณ ๊ฐ์๊ฒ ์ ์ฉ๋ ์ด๋ฒคํธ ๋ด์ญ๋ง ์ถ๋ ฅ
+ - [X] ์ ์ฉ๋ ์ด๋ฒคํธ๊ฐ ํ๋๋ ์๋ค๋ฉด "์์" ์ถ๋ ฅ
+
+- [X] ์ดํํ ๊ธ์ก ์ถ๋ ฅํ๊ธฐ
+ - [X] ์ดํํ ๊ธ์ก ๊ณ์ฐ ํ "-n์" ์ถ๋ ฅ
+
+- [X] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅํ๊ธฐ
+ - [X] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ ํ "n์" ์ถ๋ ฅ
+
+- [X] ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅํ๊ธฐ
+ - [X] ํํ๊ธ์ก์ ๋ฐ๋ผ "๋ณ, ํธ๋ฆฌ, ์ฐํ" ์ถ๋ ฅ
+ - [X] ์์ผ๋ฉด "์์" ์ถ๋ ฅ
+
+## ๐ฏ ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ
+
+- JDK 17 ๋ฒ์ ์์ ์คํ ๊ฐ๋ฅํด์ผ ํ๋ค. **JDK 17์์ ์ ์์ ์ผ๋ก ๋์ํ์ง ์์ ๊ฒฝ์ฐ 0์ ์ฒ๋ฆฌํ๋ค.**
+- ํ๋ก๊ทธ๋จ ์คํ์ ์์์ ์ `Application`์ `main()`์ด๋ค.
+- `build.gradle` ํ์ผ์ ๋ณ๊ฒฝํ ์ ์๊ณ , ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค.
+- [Java ์ฝ๋ ์ปจ๋ฒค์
](https://github.com/woowacourse/woowacourse-docs/tree/master/styleguide/java) ๊ฐ์ด๋๋ฅผ ์ค์ํ๋ฉฐ ํ๋ก๊ทธ๋๋ฐํ๋ค.
+- ํ๋ก๊ทธ๋จ ์ข
๋ฃ ์ `System.exit()`๋ฅผ ํธ์ถํ์ง ์๋๋ค.
+- ํ๋ก๊ทธ๋จ ๊ตฌํ์ด ์๋ฃ๋๋ฉด `ApplicationTest`์ ๋ชจ๋ ํ
์คํธ๊ฐ ์ฑ๊ณตํด์ผ ํ๋ค. **ํ
์คํธ๊ฐ ์คํจํ ๊ฒฝ์ฐ 0์ ์ฒ๋ฆฌํ๋ค.**
+- ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ์์ ๋ฌ๋ฆฌ ๋ช
์ํ์ง ์๋ ํ ํ์ผ, ํจํค์ง ์ด๋ฆ์ ์์ ํ๊ฑฐ๋ ์ด๋ํ์ง ์๋๋ค.
+- indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ 3์ด ๋์ง ์๋๋ก ๊ตฌํํ๋ค. 2๊น์ง๋ง ํ์ฉํ๋ค.
+ - ์๋ฅผ ๋ค์ด while๋ฌธ ์์ if๋ฌธ์ด ์์ผ๋ฉด ๋ค์ฌ์ฐ๊ธฐ๋ 2์ด๋ค.
+ - ํํธ: indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ ์ค์ด๋ ์ข์ ๋ฐฉ๋ฒ์ ํจ์(๋๋ ๋ฉ์๋)๋ฅผ ๋ถ๋ฆฌํ๋ฉด ๋๋ค.
+- 3ํญ ์ฐ์ฐ์๋ฅผ ์ฐ์ง ์๋๋ค.
+- ํจ์(๋๋ ๋ฉ์๋)์ ๊ธธ์ด๊ฐ 15๋ผ์ธ์ ๋์ด๊ฐ์ง ์๋๋ก ๊ตฌํํ๋ค.
+ - ํจ์(๋๋ ๋ฉ์๋)๊ฐ ํ ๊ฐ์ง ์ผ๋ง ํ๋๋ก ์ต๋ํ ์๊ฒ ๋ง๋ค์ด๋ผ.
+- JUnit 5์ AssertJ๋ฅผ ์ด์ฉํ์ฌ ๋ณธ์ธ์ด ์ ๋ฆฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก์ด ์ ์ ๋์ํจ์ ํ
์คํธ ์ฝ๋๋ก ํ์ธํ๋ค.
+- else ์์ฝ์ด๋ฅผ ์ฐ์ง ์๋๋ค.
+ - ํํธ: if ์กฐ๊ฑด์ ์์ ๊ฐ์ return ํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ฉด else๋ฅผ ์ฌ์ฉํ์ง ์์๋ ๋๋ค.
+ - else๋ฅผ ์ฐ์ง ๋ง๋ผ๊ณ ํ๋ switch/case๋ก ๊ตฌํํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ switch/case๋ ํ์ฉํ์ง ์๋๋ค.
+- ๋๋ฉ์ธ ๋ก์ง์ ๋จ์ ํ
์คํธ๋ฅผ ๊ตฌํํด์ผ ํ๋ค. ๋จ, UI(System.out, System.in, Scanner) ๋ก์ง์ ์ ์ธํ๋ค.
+ - ํต์ฌ ๋ก์ง์ ๊ตฌํํ๋ ์ฝ๋์ UI๋ฅผ ๋ด๋นํ๋ ๋ก์ง์ ๋ถ๋ฆฌํด ๊ตฌํํ๋ค.
+- ์ฌ์ฉ์๊ฐ ์๋ชป๋ ๊ฐ์ ์
๋ ฅํ ๊ฒฝ์ฐ `IllegalArgumentException`๋ฅผ ๋ฐ์์ํค๊ณ , "[ERROR]"๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅ ํ ๊ทธ ๋ถ๋ถ๋ถํฐ ์
๋ ฅ์ ๋ค์ ๋ฐ๋๋ค.
+ - `Exception`์ด ์๋ `IllegalArgumentException`, `IllegalStateException` ๋ฑ๊ณผ ๊ฐ์ ๋ช
ํํ ์ ํ์ ์ฒ๋ฆฌํ๋ค.
+
+### ์ถ๊ฐ๋ ์๊ตฌ ์ฌํญ
+
+- ์๋ ์๋ `InputView`, `OutputView` ํด๋์ค๋ฅผ ์ฐธ๊ณ ํ์ฌ ์
์ถ๋ ฅ ํด๋์ค๋ฅผ ๊ตฌํํ๋ค.
+ - ์
๋ ฅ๊ณผ ์ถ๋ ฅ์ ๋ด๋นํ๋ ํด๋์ค๋ฅผ ๋ณ๋๋ก ๊ตฌํํ๋ค.
+ - ํด๋น ํด๋์ค์ ํจํค์ง, ํด๋์ค๋ช
, ๋ฉ์๋์ ๋ฐํ ํ์
๊ณผ ์๊ทธ๋์ฒ๋ ์์ ๋กญ๊ฒ ๊ตฌํํ ์ ์๋ค.
+ ```java
+ public class InputView {
+ public int readDate() {
+ System.out.println("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)");
+ String input = Console.readLine();
+ // ...
+ }
+ // ...
+ }
+ ```
+ ```java
+ public class OutputView {
+ public void printMenu() {
+ System.out.println("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ // ...
+ }
+ // ...
+ }
+ ```
+
+### ๋ผ์ด๋ธ๋ฌ๋ฆฌ
+
+- `camp.nextstep.edu.missionutils`์์ ์ ๊ณตํ๋ `Console` API๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌํํด์ผ ํ๋ค.
+ - ์ฌ์ฉ์๊ฐ ์
๋ ฅํ๋ ๊ฐ์ `camp.nextstep.edu.missionutils.Console`์ `readLine()`์ ํ์ฉํ๋ค.
+
+---
+
+## โ๏ธ ๊ณผ์ ์งํ ์๊ตฌ ์ฌํญ
+
+- ๋ฏธ์
์ [java-christmas-6](https://github.com/woowacourse-precourse/java-christmas-6) ์ ์ฅ์๋ฅผ ๋น๊ณต๊ฐ ์ ์ฅ์๋ก ์์ฑํด ์์ํ๋ค.
+- **๊ธฐ๋ฅ์ ๊ตฌํํ๊ธฐ ์ `docs/README.md`์ ๊ตฌํํ ๊ธฐ๋ฅ ๋ชฉ๋ก์ ์ ๋ฆฌ**ํด ์ถ๊ฐํ๋ค.
+- **Git์ ์ปค๋ฐ ๋จ์๋ ์ ๋จ๊ณ์์ `docs/README.md`์ ์ ๋ฆฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก ๋จ์**๋ก ์ถ๊ฐํ๋ค.
+ - [์ปค๋ฐ ๋ฉ์์ง ์ปจ๋ฒค์
](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) ๊ฐ์ด๋๋ฅผ ์ฐธ๊ณ ํด ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ์์ฑํ๋ค.
+- ๊ณผ์ ์งํ ๋ฐ ์ ์ถ ๋ฐฉ๋ฒ์ [ํ๋ฆฌ์ฝ์ค ๊ณผ์ ์ ์ถ](https://docs.google.com/document/d/1cmg0VpPkuvdaetxwp4hnyyFC_G-1f2Gr8nIDYIWcKC8/edit?usp=sharing) ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๋ค. | Unknown | ๊ผผ๊ผผํ ๊ธฐ๋ฅ๋ชฉ๋ก ์ ๋ฆฌ ๐๐
PR ๋ณธ๋ฌธ์ ํด๋น ์ฝ๋๋ฅผ ๋ฆฌ๋ทฐํ๋ ์ฌ๋์ด ์์์ผํ ์ ์ด๋
์ ๊ฒฝ์จ์ ๋ด์ผํ ์ ์ ๋ํด ์ธ๊ธํด์ฃผ์๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ใ
ใ
|
@@ -0,0 +1,23 @@
+package christmas.constant;
+
+public class Number {
+ public static final int ZERO = 0;
+ public static final int ONE = 1;
+ public static final int TWO = 2;
+ public static final int THREE = 3;
+ public static final int SEVEN = 7;
+ public static final int TWENTY = 20;
+ public static final int HUNDRED = 100;
+ public static final int THOUSAND = 1000;
+ public static final int TEN_THOUSAND = 10000;
+ public static final int MIN_DATE = 1;
+ public static final int MAX_DATE = 31;
+ public static final int CHRISTMAS = 25;
+ public static final int YEAR = 2023;
+ public static final int FREE_GIFT = 120000;
+ public static final int STAR = 5000;
+ public static final int TREE = 10000;
+ public static final int SANTA = 20000;
+
+
+} | Java | ํน์ ํด๋น ํด๋์ค๋ฅผ ๋ง๋์ ์ด์ ๋ ๋ญ๊น์?
`์ฐ๊ด์ฑ์ด ์๋ ์์๋ static final ๋์ enum์ ํ์ฉํ๋ค`
ํด๋น ๋ฌธ๊ตฌ ๋๋ฌธ์ด๋ผ๋ฉด, ์์๋ผ๋ฆฌ ์ฐ๊ด์ฑ๋ ๋ฎ๊ณ , Enum๋ ์๋๊ตฐ์...
3์ THREE๋ผ๊ณ ๋ค์ด๋ฐํ๋ ๊ฒ๋ ๋ค์ ์์ฝ์ต๋๋ค. ๋งฅ๋ฝ์ ์ด๋ค ์ญํ ์ ํ๋์ง ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด ๋ ์ข๊ฒ ๋ค์ |
@@ -0,0 +1,6 @@
+package christmas.constant.message;
+
+public class InputMessage {
+ public static final String DATE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ public static final String ORDER = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+} | Java | ์ ์๊ฐ์ ๋ฉ์ธ์ง๋ค์ ๊ตณ์ด ์์ํ ์ํค์ง ์์๋
ํ๋์ ๋ฉ์๋์๋ง ์ฐ์ด๊ณ , ๋ฉ์ธ์ง๋ฅผ ์ฝ์์ ๋ ์ด๋ค ์ฉ๋์ธ์ง ์ถฉ๋ถํ ์ ์ ์๋ค๊ณ ์๊ฐํด์
์ง๊ธ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ์ ๊ตณ์ด ์์ํ ์ํค์ง ์๋ ํธ์ธ๋ฐ
์น์ฒ ๋์ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
(OutputMessage๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค ใ
ใ
) |
@@ -0,0 +1,87 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.domain.calculator.PriceCalculator;
+import christmas.view.*;
+
+public class EventController {
+ public void event() {
+ printStart();
+ Date date = getDate();
+ Order order = getOrder();
+ printPreview(date);
+ printOrder(order);
+ Price price = getBeforeDiscount(order);
+ printBeforeDiscount(price);
+ Event event = applyEvent(date, order, price);
+ printGift(event);
+ printEvent(event);
+ printAllBenefit(event);
+ printAfterDiscount(event, price);
+ printEventBadge(event);
+ }
+
+ public void printStart() {
+ OutputHelloView outputHello = new OutputHelloView();
+ outputHello.outputHello();
+ }
+
+ public Date getDate() {
+ InputDateView inputDateView = new InputDateView();
+ return inputDateView.inputDate();
+ }
+
+ public Order getOrder() {
+ InputOrderView inputOrderView = new InputOrderView();
+ return inputOrderView.inputOrder();
+ }
+
+ public void printPreview(Date date) {
+ OutputPreviewView outputPreviewView = new OutputPreviewView();
+ outputPreviewView.outputPreview(date);
+ }
+
+ public void printOrder(Order order) {
+ OutputOrderView outputOrderView = new OutputOrderView();
+ outputOrderView.outputOrder(order);
+ }
+
+ public Price getBeforeDiscount(Order order) {
+ PriceCalculator priceCalculator = new PriceCalculator();
+ return priceCalculator.calculatePrice(order);
+ }
+
+ public void printBeforeDiscount(Price price) {
+ OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView();
+ outputBeforeDiscountView.outputBeforeDiscount(price);
+ }
+
+ public Event applyEvent(Date date, Order order, Price price) {
+ return new Event(date, order, price);
+ }
+
+ public void printGift(Event event) {
+ OutputGiftView outputGiftView = new OutputGiftView();
+ outputGiftView.outputGift(event);
+ }
+
+ public void printEvent(Event event) {
+ OutputEventView outputEventView = new OutputEventView();
+ outputEventView.outputEvent(event);
+ }
+
+ public void printAllBenefit(Event event) {
+ OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView();
+ outputAllBenefitView.outputAllBenefit(event);
+ }
+
+ public void printAfterDiscount(Event event, Price price) {
+ OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView();
+ outputAfterDiscountView.outputAfterDiscount(event, price);
+ }
+
+ public void printEventBadge(Event event) {
+ OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView();
+ outputEventBadgeView.outputEventBadge(event);
+ }
+} | Java | View ํด๋์ค๋ฅผ ๊ต์ฅํ ์๊ฒ ๋๋์ด์ฃผ์
จ๋ค์
์์ ๋ฉ์๋๋ค์ด ํ๋๋ฐ์ ์๋ ๊ฒฝ์ฐ๋ ์๋๋ฐ ์ด๋ ๊ฒ ์๊ฒ ๋๋ ์ฃผ์ ์ด์ ๊ฐ ๋ญ๊น์? |
@@ -0,0 +1,87 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.domain.calculator.PriceCalculator;
+import christmas.view.*;
+
+public class EventController {
+ public void event() {
+ printStart();
+ Date date = getDate();
+ Order order = getOrder();
+ printPreview(date);
+ printOrder(order);
+ Price price = getBeforeDiscount(order);
+ printBeforeDiscount(price);
+ Event event = applyEvent(date, order, price);
+ printGift(event);
+ printEvent(event);
+ printAllBenefit(event);
+ printAfterDiscount(event, price);
+ printEventBadge(event);
+ }
+
+ public void printStart() {
+ OutputHelloView outputHello = new OutputHelloView();
+ outputHello.outputHello();
+ }
+
+ public Date getDate() {
+ InputDateView inputDateView = new InputDateView();
+ return inputDateView.inputDate();
+ }
+
+ public Order getOrder() {
+ InputOrderView inputOrderView = new InputOrderView();
+ return inputOrderView.inputOrder();
+ }
+
+ public void printPreview(Date date) {
+ OutputPreviewView outputPreviewView = new OutputPreviewView();
+ outputPreviewView.outputPreview(date);
+ }
+
+ public void printOrder(Order order) {
+ OutputOrderView outputOrderView = new OutputOrderView();
+ outputOrderView.outputOrder(order);
+ }
+
+ public Price getBeforeDiscount(Order order) {
+ PriceCalculator priceCalculator = new PriceCalculator();
+ return priceCalculator.calculatePrice(order);
+ }
+
+ public void printBeforeDiscount(Price price) {
+ OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView();
+ outputBeforeDiscountView.outputBeforeDiscount(price);
+ }
+
+ public Event applyEvent(Date date, Order order, Price price) {
+ return new Event(date, order, price);
+ }
+
+ public void printGift(Event event) {
+ OutputGiftView outputGiftView = new OutputGiftView();
+ outputGiftView.outputGift(event);
+ }
+
+ public void printEvent(Event event) {
+ OutputEventView outputEventView = new OutputEventView();
+ outputEventView.outputEvent(event);
+ }
+
+ public void printAllBenefit(Event event) {
+ OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView();
+ outputAllBenefitView.outputAllBenefit(event);
+ }
+
+ public void printAfterDiscount(Event event, Price price) {
+ OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView();
+ outputAfterDiscountView.outputAfterDiscount(event, price);
+ }
+
+ public void printEventBadge(Event event) {
+ OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView();
+ outputEventBadgeView.outputEventBadge(event);
+ }
+} | Java | MVC ํจํด์ ์ ์ฉํ๋ ์ด์ ๋ ๋ญ๊น์?
ํ์ฌ ์ฝ๋์์์ View๊ฐ model์ ๊ฐ์ฒด๋ฅผ ์์ฑํด์ฃผ๊ณ ์๋๋ฐ
์ ๋ง MVC ํจํด์ด ์ ์ ์ฉ๋ ๊ฑด ๋ง์๊น์? |
@@ -0,0 +1,17 @@
+package christmas.domain;
+
+import static christmas.constant.Number.MAX_DATE;
+import static christmas.constant.Number.MIN_DATE;
+import static christmas.constant.message.ErrorMessage.INVALID_DATE;
+
+public record Date(int date) {
+ public Date {
+ validate(date);
+ }
+
+ private void validate(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw new IllegalArgumentException(INVALID_DATE);
+ }
+ }
+} | Java | ๋ฌด์์ ๊ฒ์ฆํ๋์ง ์ข ๋ ๋ช
ํํ๊ฒ ๋ํ๋ด๋ ๋ค์ด๋ฐ์ด ์ข๊ฒ ๊ตฐ์ |
@@ -0,0 +1,87 @@
+package christmas.controller;
+
+import christmas.domain.*;
+import christmas.domain.calculator.PriceCalculator;
+import christmas.view.*;
+
+public class EventController {
+ public void event() {
+ printStart();
+ Date date = getDate();
+ Order order = getOrder();
+ printPreview(date);
+ printOrder(order);
+ Price price = getBeforeDiscount(order);
+ printBeforeDiscount(price);
+ Event event = applyEvent(date, order, price);
+ printGift(event);
+ printEvent(event);
+ printAllBenefit(event);
+ printAfterDiscount(event, price);
+ printEventBadge(event);
+ }
+
+ public void printStart() {
+ OutputHelloView outputHello = new OutputHelloView();
+ outputHello.outputHello();
+ }
+
+ public Date getDate() {
+ InputDateView inputDateView = new InputDateView();
+ return inputDateView.inputDate();
+ }
+
+ public Order getOrder() {
+ InputOrderView inputOrderView = new InputOrderView();
+ return inputOrderView.inputOrder();
+ }
+
+ public void printPreview(Date date) {
+ OutputPreviewView outputPreviewView = new OutputPreviewView();
+ outputPreviewView.outputPreview(date);
+ }
+
+ public void printOrder(Order order) {
+ OutputOrderView outputOrderView = new OutputOrderView();
+ outputOrderView.outputOrder(order);
+ }
+
+ public Price getBeforeDiscount(Order order) {
+ PriceCalculator priceCalculator = new PriceCalculator();
+ return priceCalculator.calculatePrice(order);
+ }
+
+ public void printBeforeDiscount(Price price) {
+ OutputBeforeDiscountView outputBeforeDiscountView = new OutputBeforeDiscountView();
+ outputBeforeDiscountView.outputBeforeDiscount(price);
+ }
+
+ public Event applyEvent(Date date, Order order, Price price) {
+ return new Event(date, order, price);
+ }
+
+ public void printGift(Event event) {
+ OutputGiftView outputGiftView = new OutputGiftView();
+ outputGiftView.outputGift(event);
+ }
+
+ public void printEvent(Event event) {
+ OutputEventView outputEventView = new OutputEventView();
+ outputEventView.outputEvent(event);
+ }
+
+ public void printAllBenefit(Event event) {
+ OutputAllBenefitView outputAllBenefitView = new OutputAllBenefitView();
+ outputAllBenefitView.outputAllBenefit(event);
+ }
+
+ public void printAfterDiscount(Event event, Price price) {
+ OutputAfterDiscountView outputAfterDiscountView = new OutputAfterDiscountView();
+ outputAfterDiscountView.outputAfterDiscount(event, price);
+ }
+
+ public void printEventBadge(Event event) {
+ OutputEventBadgeView outputEventBadgeView = new OutputEventBadgeView();
+ outputEventBadgeView.outputEventBadge(event);
+ }
+} | Java | ์ถ๊ฐ์ ์ผ๋ก, ๋ชจ๋ View ๊ด๋ จ ๊ฐ์ฒด๋ค์ ์ธ์คํด์ค ๋ณ์๊ฐ ์์ด์
์ ํธ์ฑ ํด๋์ค๋ก ๋ง๋ค์ด๋ ๋์ ๊ฒ ๊ฐ์๋ฐ ์ง๊ธ์ฒ๋ผ ๋งค ํด๋์ค๋ง๋ค ๊ฐ์ฒด๋ฅผ ์์ฑํด์ฃผ์๋ ์ด์ ๋ ๋ญ๊น์? |
@@ -0,0 +1,91 @@
+package christmas.domain;
+
+import christmas.domain.menu.Dessert;
+import christmas.domain.menu.Drink;
+import christmas.domain.menu.Entree;
+import christmas.domain.menu.Menu;
+
+import java.util.Map;
+
+import static christmas.constant.Number.*;
+import static christmas.constant.message.OutputMessage.*;
+
+public record Event(Date date, Order order, Price price) {
+ public int d_Day() {
+ if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) {
+ return ZERO;
+ }
+ return THOUSAND + (date.date() - MIN_DATE) * HUNDRED;
+ }
+
+ public int weekday() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Dessert.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int weekend() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Entree.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int special() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) {
+ return ZERO;
+ }
+ return THOUSAND;
+ }
+
+ public int freeGift() {
+ if (price.price() > FREE_GIFT) {
+ return Drink.์ดํ์ธ.getPrice();
+ }
+ return ZERO;
+ }
+
+ public String badge() {
+ if (allBenefit() >= SANTA) {
+ return SANTA_BADGE;
+ }
+ if (allBenefit() >= TREE) {
+ return TREE_BADGE;
+ }
+ if (allBenefit() >= STAR) {
+ return STAR_BADGE;
+ }
+ return NOTHING;
+ }
+
+ public int allBenefit() {
+ return d_Day() + weekday() + weekend() + special() + freeGift();
+ }
+
+ public int afterDiscount() {
+ return d_Day() + weekday() + weekend() + special();
+ }
+} | Java | ์๋ฐ ์ปจ๋ฒค์
์ ๋ฉ์๋๋ ๋์ฌํ์ผ๋ก ์์ฑํ๋ ๊ฑธ ๊ถ์ฅ๋๋ฆฝ๋๋ค |
@@ -0,0 +1,91 @@
+package christmas.domain;
+
+import christmas.domain.menu.Dessert;
+import christmas.domain.menu.Drink;
+import christmas.domain.menu.Entree;
+import christmas.domain.menu.Menu;
+
+import java.util.Map;
+
+import static christmas.constant.Number.*;
+import static christmas.constant.message.OutputMessage.*;
+
+public record Event(Date date, Order order, Price price) {
+ public int d_Day() {
+ if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) {
+ return ZERO;
+ }
+ return THOUSAND + (date.date() - MIN_DATE) * HUNDRED;
+ }
+
+ public int weekday() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Dessert.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int weekend() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Entree.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int special() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) {
+ return ZERO;
+ }
+ return THOUSAND;
+ }
+
+ public int freeGift() {
+ if (price.price() > FREE_GIFT) {
+ return Drink.์ดํ์ธ.getPrice();
+ }
+ return ZERO;
+ }
+
+ public String badge() {
+ if (allBenefit() >= SANTA) {
+ return SANTA_BADGE;
+ }
+ if (allBenefit() >= TREE) {
+ return TREE_BADGE;
+ }
+ if (allBenefit() >= STAR) {
+ return STAR_BADGE;
+ }
+ return NOTHING;
+ }
+
+ public int allBenefit() {
+ return d_Day() + weekday() + weekend() + special() + freeGift();
+ }
+
+ public int afterDiscount() {
+ return d_Day() + weekday() + weekend() + special();
+ }
+} | Java | ํด๋น ํด๋์ค์์ ๋๋ฌด ๋ง์ ๊ฑธ ํ๊ณ ์๋ค์
ํ ์ธ์จ์ ๊ณ์ฐํ๊ณ , ์ฆ์ ํ์ ์ค์ง ๊ฒฐ์ ํ๊ณ , ๋ฐฐ์ง๋ฅผ ์ค์ง ๊ฒฐ์ ํ๊ณ ...
Event๋ผ๋ ๋ค์ด๋ฐ๋ง ๋ค์์ ๋, ์ ๋ชจ๋ ์ผ์ ํ๋ ๊ฒ์ ์์ธกํ๊ธฐ ์ฝ์ง ์์๊ฒ๊ฐ์ต๋๋ค.
๊ฐ์ฒด์งํฅ ์ค๊ณ์ 5๊ฐ์ง ์์น(SOLID) ์ค [๋จ์ผ ์ฑ
์์ ์์น(SRP, Single Responsibility Principle)](https://mangkyu.tistory.com/194)์ ๋ํด ์์๋ณผ๊น์? |
@@ -0,0 +1,91 @@
+package christmas.domain;
+
+import christmas.domain.menu.Dessert;
+import christmas.domain.menu.Drink;
+import christmas.domain.menu.Entree;
+import christmas.domain.menu.Menu;
+
+import java.util.Map;
+
+import static christmas.constant.Number.*;
+import static christmas.constant.message.OutputMessage.*;
+
+public record Event(Date date, Order order, Price price) {
+ public int d_Day() {
+ if (price.price() < TEN_THOUSAND || date.date() > CHRISTMAS) {
+ return ZERO;
+ }
+ return THOUSAND + (date.date() - MIN_DATE) * HUNDRED;
+ }
+
+ public int weekday() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN == ONE || date.date() % SEVEN == TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Dessert.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int weekend() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != ONE && date.date() % SEVEN != TWO)) {
+ return ZERO;
+ }
+ int count = ZERO;
+ for (Map.Entry<Menu, Integer> entry : order.order().entrySet()) {
+ Menu menu = entry.getKey();
+ Integer i = entry.getValue();
+ try {
+ Entree.valueOf(menu.name());
+ } catch (IllegalArgumentException e) {
+ continue;
+ }
+ count += i;
+ }
+ return YEAR * count;
+ }
+
+ public int special() {
+ if (price.price() < TEN_THOUSAND || (date.date() % SEVEN != THREE && date.date() != CHRISTMAS)) {
+ return ZERO;
+ }
+ return THOUSAND;
+ }
+
+ public int freeGift() {
+ if (price.price() > FREE_GIFT) {
+ return Drink.์ดํ์ธ.getPrice();
+ }
+ return ZERO;
+ }
+
+ public String badge() {
+ if (allBenefit() >= SANTA) {
+ return SANTA_BADGE;
+ }
+ if (allBenefit() >= TREE) {
+ return TREE_BADGE;
+ }
+ if (allBenefit() >= STAR) {
+ return STAR_BADGE;
+ }
+ return NOTHING;
+ }
+
+ public int allBenefit() {
+ return d_Day() + weekday() + weekend() + special() + freeGift();
+ }
+
+ public int afterDiscount() {
+ return d_Day() + weekday() + weekend() + special();
+ }
+} | Java | Date, Event, Order, Price ๋ชจ๋ Record๋ก ๋ง๋ค์ด์ฃผ์ ์ด์ ๋ ๋ญ๊น์? |
@@ -0,0 +1,52 @@
+import React, { Component } from 'react';
+
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { faHeart } from '@fortawesome/free-regular-svg-icons';
+
+import './LikeBtn.scss';
+
+class LikeBtn extends Component {
+ constructor(props) {
+ super(props);
+ const { isLiked } = this.props;
+ this.state = { isLikeBtnClicked: isLiked };
+ }
+
+ handleLikeBtnColor = () => {
+ const { isLikeBtnClicked } = this.state;
+ const { whoseBtn, handler, userId, categoryTitle, coffeeName } = this.props;
+ this.setState({ isLikeBtnClicked: !isLikeBtnClicked });
+
+ switch (whoseBtn) {
+ case 'product':
+ handler(!isLikeBtnClicked);
+ break;
+ case 'review':
+ handler(userId, !isLikeBtnClicked);
+ break;
+ case 'coffeeCard':
+ handler(categoryTitle, coffeeName, !isLikeBtnClicked);
+ break;
+ default:
+ break;
+ }
+ };
+
+ render() {
+ const { isLikeBtnClicked } = this.state;
+ const { handleLikeBtnColor } = this;
+ return (
+ <div className="like-btn-wrap">
+ <button
+ className={isLikeBtnClicked ? 'like-wrap clicked' : 'like-wrap'}
+ id="product-like"
+ onClick={handleLikeBtnColor}
+ >
+ <FontAwesomeIcon icon={faHeart} />
+ </button>
+ </div>
+ );
+ }
+}
+
+export default LikeBtn; | JavaScript | react๋ถํฐ wecode์์๋ ํด๋์ค๋ช
๋ ์นด๋ฉ์ผ์ด์ค๋ก ํต์ผํ์๊ณ ํ๋ ๊ฒ ๊ฐ์ต๋๋ค...? |
@@ -0,0 +1,103 @@
+{
+ "footerList": [
+ {
+ "id": 1,
+ "title": "COMPANY",
+ "contents": [
+ {
+ "id": 1,
+ "contentName": "ํ๋์ ๋ณด๊ธฐ"
+ },
+ {
+ "id": 2,
+ "contentName": "์๋ฒ
์ค ์ฌ๋ช
"
+ },
+ {
+ "id": 3,
+ "contentName": "์๋ฒ
์ค ์๊ฐ"
+ },
+ {
+ "id": 4,
+ "contentName": "๊ตญ๋ด ๋ด์ค๋ฃธ"
+ },
+ {
+ "id": 5,
+ "contentName": "์ธ๊ณ์ ์๋ฒ
์ค"
+ },
+ {
+ "id": 6,
+ "contentName": "๊ธ๋ก๋ฒ ๋ด์ค๋ฃธ"
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "title": "CORPORATE_SALES",
+ "contents": [
+ {
+ "id": 1,
+ "contentName": "๋จ์ฒด ๋ฐ ๊ธฐ์
๊ตฌ๋งค ์๋ด"
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "title": "PARTNERSHIP",
+ "contents": [
+ {
+ "id": 1,
+ "contentName": "๊ธ๋ก๋ฒ ๋ด์ค๋ฃธ"
+ },
+ {
+ "id": 2,
+ "contentName": "์ ๊ท ์
์ ์ ์"
+ }
+ ]
+ },
+ {
+ "id": 4,
+ "title": "ONLINE COMMUNITY",
+ "contents": [
+ {
+ "id": 1,
+ "contentName": "ํ์ด์ค๋ถ"
+ },
+ {
+ "id": 2,
+ "contentName": "ํธ์ํฐ"
+ },
+ {
+ "id": 3,
+ "contentName": "์ ํ๋ธ"
+ },
+ {
+ "id": 4,
+ "contentName": "๋ธ๋ก๊ทธ"
+ },
+ {
+ "id": 5,
+ "contentName": "์ธ์คํ๊ทธ๋จ"
+ },
+ {
+ "id": 6,
+ "contentName": "ํ์ด์ค๋ถ"
+ }
+ ]
+ },
+ {
+ "id": 5,
+ "title": "RECRUIT",
+ "contents": [
+ {
+ "id": 1,
+ "contentName": "์ฑ์ฉ ์๊ฐ"
+ },
+ {
+ "id": 2,
+ "contentName": "์ฑ์ฉ ์ง์ํ๊ธฐ"
+ }
+ ]
+ },
+ { "id": 6, "title": "WEBUKCS", "contents": [] }
+ ]
+}
\ No newline at end of file | Unknown | footer๊น์ง json์ผ๋ก ํ์
จ๋ค์! ๋ถ์ง๋ฐํ์ญ๋๋ค,,๐๐ผ |
@@ -0,0 +1,44 @@
+{
+ "menus": [
+ {
+ "id": 1,
+ "parentId": 0,
+ "level": 1,
+ "name": "ํ",
+ "path": "/",
+ "children": null
+ },
+ {
+ "id": 2,
+ "parentId": 1,
+ "level": 2,
+ "name": "MENU",
+ "path": "/menu/",
+ "children": null
+ },
+ {
+ "id": 3,
+ "parentId": 2,
+ "level": 3,
+ "name": "์๋ฃ",
+ "path": "/list-junbeom",
+ "children": null
+ },
+ {
+ "id": 4,
+ "parentId": 3,
+ "level": 4,
+ "name": "์ฝ๋๋ธ๋ฃจ",
+ "path": "/menu/drink/coldbrew/",
+ "children": null
+ },
+ {
+ "id": 5,
+ "parentId": 4,
+ "level": 5,
+ "name": "์๊ทธ๋์ฒ ๋ ๋ธ๋ ์ฝ๋ ๋ธ๋ฃจ",
+ "path": "/detail-junbeom",
+ "children": null
+ }
+ ]
+}
\ No newline at end of file | Unknown | ์ ๋ ์ ๊ฐ list๋ก ๋์๊ฐ๊ณ ์ถ์ด์ menu์๋ง Link ์ฒ๋ฆฌ๋ฅผ ํด๋์๋๋ฐ path๊น์ง ๋ํ
์ผ๊น์ง ์ค์ ํ์
จ๋ค์! ์ ๋ ์ข๋ ๋ํ
์ผํ๊ฒ ์์ ํด๋ด์ผ๊ฒ ์ต๋๋ค. ์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,48 @@
+import React, { Component } from 'react';
+
+import FooterMenuTitle from './FooterMenuTitle';
+import FooterMenuContent from './FooterMenuContent';
+
+import './Footer.scss';
+
+class Footer extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { footerList: [] };
+ }
+
+ componentDidMount() {
+ fetch('http://localhost:3000/data/footerListMockData.json')
+ .then(res => res.json())
+ .then(data => {
+ this.setState({ footerList: data.footerList });
+ });
+ }
+
+ render() {
+ const { footerList } = this.state;
+ return (
+ <footer className="Footer">
+ <div className="footer-menus">
+ {footerList.map(data => {
+ return (
+ <ul key={data.id}>
+ <FooterMenuTitle title={data.title} />
+ {data.contents.map(content => {
+ return (
+ <FooterMenuContent
+ key={content.id}
+ content={content.contentName}
+ />
+ );
+ })}
+ </ul>
+ );
+ })}
+ </div>
+ </footer>
+ );
+ }
+}
+
+export default Footer; | JavaScript | import ์ฝ๋ฉ ์ปจ๋ฒค์
์ด ๋ฐ๋ก ์๋์ง ๋ชจ๋ฅด๊ฒ ์ผ๋, ํ๋ผ๋ฆฌ ์๋
ผํด์ ๋ ๊ฐ๋
์ฑ ์ข์ ์ชฝ์ผ๋ก ์ค๋ฐ๊ฟ์ ์ ์ฉํ๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์
๋๋ค :) |
@@ -0,0 +1,35 @@
+@import '../../Styles/variables.scss';
+
+.Footer {
+ width: 100%;
+ background-color: #2c2a29;
+
+ .footer-menus {
+ display: flex;
+ justify-content: space-around;
+ flex-wrap: wrap;
+ margin: 20px auto;
+ padding: 10px 50px;
+ color: white;
+
+ li {
+ list-style: none;
+ }
+
+ a {
+ color: $theme-color;
+ text-decoration: none;
+ }
+
+ .footer-menu-title {
+ margin-bottom: 15px;
+ font-size: 15px;
+ font-weight: 100;
+ }
+
+ .footer-menu-content {
+ margin-bottom: 6px;
+ font-size: 12px;
+ }
+ }
+} | Unknown | sass variable์ ์ด๋์ ์ ์ฉํด์ผ ํ ์ง ๋ชฐ๋ผ ๊ณ ๋ฏผํ๊ณ ์์๋๋ฐ ์ฐธ๊ณ ๋ง์ด ํ๊ฒ ์ต๋๋ค!! ๊ฐ์ฌํฉ๋๋ค :) |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ์ ๋ ๋ฐ์ธ๋๋ฅผ ํ์ง ์์๋๋ฐ, ํน์ ์ด๋ค ๊ฒฝ์ฐ์ ๋ฐ์ธ๋๋ฅผ ํด์ผํ๋์ง ๊ฐ๋จํ ์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค :) |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | promise์ all์ ์ฌ์ฉํ์
จ๊ตฐ์!!!! ์์์ ๋ดค๋๋ฐ ๋ฌด์์์ ์ ์ฉ์ ๋ชปํ๊ณ ์์๋๋ฐ ์ ๋ ์ฉ๊ธฐ ์ป๊ณ ์๋ํด๋ด
๋๋ค!!! |
@@ -0,0 +1,164 @@
+@import '../../../Styles/variables.scss';
+@import '../../../Styles/font.scss';
+
+.Detail {
+ @extend %flex-column;
+ align-items: center;
+ flex-wrap: wrap;
+ padding-top: 3rem;
+
+ .detail-section {
+ @extend %flex-column;
+ width: 60%;
+ margin-top: 30px;
+
+ .category-title {
+ font-size: 25px;
+ font-weight: 700;
+ }
+ }
+
+ .detail-category {
+ position: relative;
+ height: 80px;
+ margin-bottom: 20px;
+ padding: 10px;
+
+ .category-nav {
+ position: absolute;
+ right: 0;
+ bottom: 0;
+ width: 400px;
+ }
+ }
+
+ .detail-content {
+ @extend %flex-between;
+ flex-wrap: wrap;
+ }
+
+ .detail-img-wrap {
+ max-width: 45%;
+ min-width: 300px;
+ padding: 10px;
+
+ img {
+ width: 100%;
+ }
+ }
+
+ .detail-text-wrap {
+ max-width: 55%;
+ padding: 10px;
+ }
+
+ .detail-text {
+ position: relative;
+
+ .product-name-kr {
+ padding-bottom: 18px;
+ margin-bottom: 20px;
+ color: #222;
+ border-bottom: 2px solid #333;
+ font-size: 25px;
+ font-weight: 400;
+ }
+
+ .product-name-en {
+ color: #666;
+ font-size: 16px;
+ }
+
+ .like-btn-wrap {
+ position: absolute;
+ top: 0;
+ right: 0;
+
+ .like-wrap {
+ font-size: 25px;
+ }
+ }
+
+ .product-description {
+ margin-bottom: 20px;
+ font-size: 16px;
+ white-space: pre-wrap;
+ }
+ }
+
+ .product-info {
+ @extend %flex-column;
+
+ .product-info-head {
+ @extend %flex-between;
+ border-top: 1px solid $division-color;
+ border-bottom: 1px solid $division-color;
+
+ .info-head-text {
+ color: #222;
+ font-size: 18px;
+ padding: 10px;
+ margin: 10px;
+ }
+ }
+
+ .product-info-content {
+ @extend %flex-center;
+ margin: 10px;
+ padding: 10px;
+
+ table {
+ width: 100%;
+
+ tr {
+ height: 30px;
+ }
+
+ td {
+ width: 25%;
+ }
+
+ .align-right {
+ text-align: right;
+ }
+
+ .padding-right {
+ padding-right: 10px;
+ }
+
+ .dashed-border {
+ padding-left: 10px;
+ border-left: 1px dashed $division-color;
+ }
+ }
+ }
+
+ .allergens-wrap {
+ margin: 10px;
+ padding: 10px;
+ font-size: 18px;
+ background-color: $division-color;
+ }
+ }
+
+ .detail-review {
+ margin-bottom: 30px;
+
+ .review-title {
+ padding: 20px 0px;
+ border-bottom: 1px solid $division-color;
+ }
+
+ ul {
+ padding: 20px 0px;
+ list-style: none;
+ }
+
+ .review-input {
+ width: 100%;
+ padding: 10px;
+ background-color: $division-color;
+ border: none;
+ }
+ }
+} | Unknown | ๋ํ
์ผ ํ์ด์ง์๋ ๋๋ถ๋ถ camelCase์ด ์ ์ฉ์ด ๋์ด ์์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ์ด ๋ถ๋ถ์ ๋ค๋น๋ ๋ฆฌ๋ทฐ ์ฝ๋ฉํธ์ ์ถ๊ฐํ์์ต๋๋ค! ์ ๊ฐ ์๋ชป ์๊ณ ์๋ ๋ถ๋ถ์ด ์์ด์ ํ์ฌ ์ ์ฝ๋์๋ ๋ฌธ์ ๊ฐ ์ข ์๋ค์! ์ ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๋ฅผ ์ ์ธ ๋ฐ ์ ์ํ ๋ ํด๋์ค ํ๋ ๋ฌธ๋ฒ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก .bind()๋ฅผ ์ ํด๋ ๋๋๊ฒ ๋ง์ต๋๋ค! ๊ด๋ จ ๋ด์ฉ์ ๋ค๋น๋ ๋ฆฌ๋ทฐ์ ๋งํฌ๋ก ์ฌ๋ ธ์ผ๋ ํ์ธํด๋ณด์์์ ~ |
@@ -0,0 +1,44 @@
+{
+ "menus": [
+ {
+ "id": 1,
+ "parentId": 0,
+ "level": 1,
+ "name": "ํ",
+ "path": "/",
+ "children": null
+ },
+ {
+ "id": 2,
+ "parentId": 1,
+ "level": 2,
+ "name": "MENU",
+ "path": "/menu/",
+ "children": null
+ },
+ {
+ "id": 3,
+ "parentId": 2,
+ "level": 3,
+ "name": "์๋ฃ",
+ "path": "/list-junbeom",
+ "children": null
+ },
+ {
+ "id": 4,
+ "parentId": 3,
+ "level": 4,
+ "name": "์ฝ๋๋ธ๋ฃจ",
+ "path": "/menu/drink/coldbrew/",
+ "children": null
+ },
+ {
+ "id": 5,
+ "parentId": 4,
+ "level": 5,
+ "name": "์๊ทธ๋์ฒ ๋ ๋ธ๋ ์ฝ๋ ๋ธ๋ฃจ",
+ "path": "/detail-junbeom",
+ "children": null
+ }
+ ]
+}
\ No newline at end of file | Unknown | ์์ฒญ ๊ผผ๊ผผํ ์์ฑํ์
จ๋ค์. ๋๋จํฉ๋๋ค!! :) |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ์ค์ฐ~~ ์ง๋ ๋๋ฌด ๋๊ฐ์
จ๋๋ฐ์??ใ
ใ
๋ฒ์จ Promise๊น์ง ์ ์ฉํ์๋ค๋ ์ต๊ณ ์
๋๋ค!! :) |
@@ -1,3 +0,0 @@
-.logo {
- margin: 0;
-} | Unknown | ์ด๋ฐ ์ด๊ธฐํ๋ reset์ ๋ฃ์ด ์ฃผ์ธ์! |
@@ -0,0 +1,10 @@
+.like-wrap {
+ color: #666;
+ background-color: white;
+ border: none;
+ cursor: pointer;
+
+ &.clicked {
+ color: tomato;
+ }
+} | Unknown | ์ ์ฒด nesting ํด์ฃผ์ธ์! |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ์ด๋ ๊ฒ ํ๋๋ผ๋ ์ฃผ์๊ฐ ๋ณต์ฌ๋๊ธฐ ๋๋ฌธ์ state๋ฅผ ์ง์ ๊ฑด๋๋ฆฌ๊ณ ์์ต๋๋ค.
์ฃผ์๋ฅผ ๋์ด ์ฃผ์ธ์! |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ๊ตฌ์กฐ๋ถํด ํ ๋น์ด ์๋ชป๋์ state๋ฅผ ์ ์ฒด ๋ค returnํ๊ณ ์์ต๋๋ค.
์ด ํจ์์ ๋ชฉ์ ์ ๋ฌด์์ธ๊ฐ์? |
@@ -0,0 +1,52 @@
+import React, { Component } from 'react';
+
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { faHeart } from '@fortawesome/free-regular-svg-icons';
+
+import './LikeBtn.scss';
+
+class LikeBtn extends Component {
+ constructor(props) {
+ super(props);
+ const { isLiked } = this.props;
+ this.state = { isLikeBtnClicked: isLiked };
+ }
+
+ handleLikeBtnColor = () => {
+ const { isLikeBtnClicked } = this.state;
+ const { whoseBtn, handler, userId, categoryTitle, coffeeName } = this.props;
+ this.setState({ isLikeBtnClicked: !isLikeBtnClicked });
+
+ switch (whoseBtn) {
+ case 'product':
+ handler(!isLikeBtnClicked);
+ break;
+ case 'review':
+ handler(userId, !isLikeBtnClicked);
+ break;
+ case 'coffeeCard':
+ handler(categoryTitle, coffeeName, !isLikeBtnClicked);
+ break;
+ default:
+ break;
+ }
+ };
+
+ render() {
+ const { isLikeBtnClicked } = this.state;
+ const { handleLikeBtnColor } = this;
+ return (
+ <div className="like-btn-wrap">
+ <button
+ className={isLikeBtnClicked ? 'like-wrap clicked' : 'like-wrap'}
+ id="product-like"
+ onClick={handleLikeBtnColor}
+ >
+ <FontAwesomeIcon icon={faHeart} />
+ </button>
+ </div>
+ );
+ }
+}
+
+export default LikeBtn; | JavaScript | ๋ฒํผ์ ์ข์์ ์ํ๋ฅผ ๋ฒํผ์ด ๊ฐ์ง๊ณ ์์ผ๋ฉด ํญ์ ์ข์์๊ฐ false๊ฒ ์ฃ ? ์ด๋ฏธ ์ข์์ ํ ์ปดํฌ๋ํธ๋ฅผ ํํํ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ props๋ก ๋ฐ์์์ผ ํฉ๋๋ค.
์ด๋ ๊ฒ ๋ฐ๋๋ฉด ๋ฉ์๋ ๋ค๋ ์กฐ๊ธ ์์ ํ์
์ผ ํ ๊ฒ๋๋ค! |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | review์ valid๋ ๋ฌด์์ ์๋ฏธํ๋์? |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | Promise.all๋ฅผ ์ฌ์ฉํ์
จ๊ตฐ์! ๊ตฟ!
๋ฐ์ดํฐ๊ฐ ๋จผ์ ์ค๋๊ฒ๋ถํฐ setState๋ฅผ ํด์ ํ๋ฉด์ ๋น ๋ฅด๊ฒ ๋ณด์ฌ์ค์ผ ํ๋๋ฐ ์ง๊ธ์ ์ธ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ ๋ฐ์์์ ๋๋ง ํ๋ฉด์ ๋ณด์ฌ์ฃผ๊ธฐ ๋๋ฌธ์ ์กฐ๊ธ ๋๋ฆด๊ฒ๋๋ค. ์ด๋ฐ ์ด์ ๋ก Promise.all์๋ fetch์ setState๋ฅผ ๋ชจ๋ ํ๊ณ ์๋ ํ๋์ ํจ์๋ฅผ ๊ฐ๊ฐ ๋ฃ์ด์ฃผ์๋๊ฒ ๋ ์ข์ต๋๋ค. |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | ํด๋์ค์ด๋ฆ ๋ค์ ํ๋ก์ ํธ ๋ถํฐ๋ ๊ผญ camelCase๋ก ์ฌ์ฉํด ์ฃผ์ธ์. |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | table ํ์์ด๋ผ์ table ๊ด๋ จ ํ๊ทธ๋ฅผ ์ฌ์ฉํด ์ฃผ์ธ์ |
@@ -1 +1,245 @@
-console.log("์์ฌ์ข ํฉ์๋ค.");
+import React, { Component } from 'react';
+
+import { getProducts, getReviews, getMenus } from '../api';
+
+import TopMenuNav from './TopMenuNav';
+import LikeBtn from '../../../components/LikeBtn/LikeBtn';
+import Review from './Review';
+
+import './Detail.scss';
+
+class Detail extends Component {
+ testIdNum = 1;
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ product: {},
+ reviewList: [],
+ menuList: [],
+ reviewInputVal: '',
+ };
+ }
+
+ handleReviewInput = event => {
+ const { key } = event;
+ const { value } = event.target;
+ const { reviewList } = this.state;
+
+ if (key === 'Enter' && value !== '') {
+ let newReview = {
+ userId: 'test' + this.testIdNum,
+ text: value,
+ isDeleted: false,
+ isLiked: false,
+ };
+ const newReviewList = [...reviewList];
+ newReviewList.push(newReview);
+
+ this.setState({
+ reviewInputVal: '',
+ reviewList: newReviewList,
+ });
+ this.testIdNum++;
+ }
+ };
+
+ getReviewInputVal = event => {
+ const { value } = event.target;
+ this.setState({ reviewInputVal: value });
+ };
+
+ handleDelReviewBtn = userId => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isDeleted = true;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ getNotDeletedReviews = () => {
+ const { reviewList } = this.state;
+ const notDelReviewList = [];
+ for (let review of reviewList) {
+ if (!review.isDeleted) {
+ notDelReviewList.push(review);
+ }
+ }
+ return notDelReviewList;
+ };
+
+ isProductLiked = isLiked => {
+ const { product } = this.state;
+ const updatedProduct = { ...product };
+ updatedProduct.isLiked = isLiked;
+ this.setState({ product: updatedProduct });
+ };
+
+ isReviewLiked = (userId, isLiked) => {
+ const { reviewList } = this.state;
+ const updatedReviewList = [...reviewList];
+ for (let review of updatedReviewList) {
+ if (userId === review.userId) {
+ review.isLiked = isLiked;
+ }
+ }
+ this.setState({ reviewList: updatedReviewList });
+ };
+
+ async componentDidMount() {
+ // console.time('์์์๊ฐ');
+ // Promise.all([
+ // fetch('http://localhost:3000/data/detailMockData.json'),
+ // fetch('http://localhost:3000/data/reviewListMockData.json'),
+ // fetch('http://localhost:3000/data/menuListMockData.json'),
+ // ])
+ // .then(([res1, res2, res3]) =>
+ // Promise.all([res1.json(), res2.json(), res3.json()])
+ // )
+ // .then(([data1, data2, data3]) => {
+ // this.setState({
+ // product: data1.data[0],
+ // reviewList: data2.reviews,
+ // menuList: data3.menus,
+ // });
+ // });
+ // console.timeEnd('์์์๊ฐ');
+ try {
+ const jsonData = await Promise.all([
+ getProducts(),
+ getReviews(),
+ getMenus(),
+ ]);
+ this.setState({ product: jsonData[0].data[0] });
+ this.setState({ reviewList: jsonData[1].reviews });
+ this.setState({ menuList: jsonData[2].menus });
+ } catch (err) {
+ new Error('Failed to set state');
+ }
+ }
+
+ render() {
+ const {
+ handleReviewInput,
+ getReviewInputVal,
+ handleDelReviewBtn,
+ getNotDeletedReviews,
+ isProductLiked,
+ isReviewLiked,
+ } = this;
+ const { product, menuList, reviewInputVal } = this.state;
+
+ let currentMenu;
+ for (let menu of menuList) {
+ if (menu.name === product.name) {
+ currentMenu = menu;
+ }
+ }
+
+ return (
+ <div className="Detail">
+ {/* <TopNav /> */}
+ <section className="detail-section">
+ <article>
+ <div className="detail-category">
+ <h2 className="category-title">{product.catecory}</h2>
+ <div className="category-nav">
+ <TopMenuNav {...currentMenu} menuList={menuList} />
+ </div>
+ </div>
+ <div className="detail-content">
+ <div className="detail-img-wrap">
+ <img alt={product.name} src={product.imgUrl} />
+ </div>
+ <div className="detail-text-wrap">
+ <div className="detail-text">
+ <h3 className="product-name-kr">
+ {product.name}
+ <br />
+ <span className="product-name-en">{product.engName}</span>
+ </h3>
+ <LikeBtn
+ whoseBtn="product"
+ handler={isProductLiked}
+ isLiked={product.isLiked}
+ />
+ <p className="product-description">{product.summary}</p>
+ </div>
+ <div className="product-info">
+ <div className="product-info-head">
+ <p className="info-head-text">์ ํ ์์ ์ ๋ณด</p>
+ <p className="info-head-text">{product.servingSize}</p>
+ </div>
+ <div className="product-info-content">
+ <table>
+ <tbody>
+ <tr>
+ <td>1ํ ์ ๊ณต๋ (kcal)</td>
+ <td className="align-right padding-right">
+ {product.kcal}
+ </td>
+ <td className="dashed-border">๋ํธ๋ฅจ (mg)</td>
+ <td className="align-right">{product.natrium}</td>
+ </tr>
+ <tr>
+ <td>ํฌํ์ง๋ฐฉ (g)</td>
+ <td className="align-right padding-right">
+ {product.fat}
+ </td>
+ <td className="dashed-border">๋น๋ฅ (g)</td>
+ <td className="align-right">{product.sugars}</td>
+ </tr>
+ <tr>
+ <td>๋จ๋ฐฑ์ง (g)</td>
+ <td className="align-right padding-right">
+ {product.protein}
+ </td>
+ <td className="dashed-border">์นดํ์ธ (mg)</td>
+ <td className="align-right">{product.caffeine}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div className="allergens-wrap">
+ <p>์๋ ๋ฅด๊ธฐ ์ ๋ฐ ์์ธ : {product.allergen}</p>
+ </div>
+ </div>
+ <div className="detail-review">
+ <h2 className="category-title review-title">๋ฆฌ๋ทฐ</h2>
+ <ul className="review-list">
+ {getNotDeletedReviews().map(review => {
+ return (
+ <Review
+ key={review.userId}
+ {...review}
+ isReviewLiked={isReviewLiked}
+ handleDelReviewBtn={handleDelReviewBtn}
+ />
+ );
+ })}
+ </ul>
+ <div className="review-input-wrap">
+ <input
+ className="review-input"
+ placeholder="๋ฆฌ๋ทฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
+ type="text"
+ value={reviewInputVal}
+ onChange={getReviewInputVal}
+ onKeyPress={handleReviewInput}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </article>
+ </section>
+ {/* <Footer /> */}
+ </div>
+ );
+ }
+}
+
+export default Detail; | JavaScript | null์ returnํ๋๊ฒ ์กฐ๊ธ ๊ฑธ๋ ค์ ์๋ก์ด ๋ฐฐ์ด์ ๋ง๋์ ๋ค์์ ์กฐ๊ฑด์ ๋ถํฉํ๋ ์์๋ฅผ push ํด์ ๊ทธ ๋ฐฐ์ด์ ์ฌ์ฉํ์๋ ๊ฒ ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,93 @@
+import Util from './util/Util.js';
+import MenuValidation from './validation/MenuValidation.js';
+import { PRICE, APPETIZER, MAIN, DESSERT, BEVERAGE, PRICE_CONSTANT } from './constants/constant.js';
+
+class Menu {
+ #main = { ...MAIN };
+
+ #dessert = { ...DESSERT };
+
+ #beverage = { ...BEVERAGE };
+
+ #appetizer = { ...APPETIZER };
+
+ #totalPrice = 0;
+
+ constructor(menu) {
+ const data = Util.countMethod(menu);
+ this.#validate(data);
+ this.#calculateMenuAndPrice(data);
+ }
+
+ #validate(data) {
+ MenuValidation.validateMenuAndMenuCount(data);
+ MenuValidation.validateDuplicate(data);
+ MenuValidation.validateOnlyBeverage({ ...this.#appetizer, ...this.#main, ...this.#dessert }, data);
+ }
+
+ #calculateMenuAndPrice(data) {
+ data.forEach(([food, count]) => {
+ if (this.#appetizer[food] !== undefined) this.#appetizer[food] += count;
+ if (this.#dessert[food] !== undefined) this.#dessert[food] += count;
+ if (this.#main[food] !== undefined) this.#main[food] += count;
+ if (this.#beverage[food] !== undefined) this.#beverage[food] += count;
+ this.#totalPrice += PRICE[food] * count;
+ });
+ }
+
+ /**
+ * ์ด ์ฃผ๋ฌธํ ๋์ ํธ์ ๊ฐ์
+ * @returns {number} totalDessert
+ */
+ calcultaeTotalDessert() {
+ return Util.extractValuesAndSum(this.#dessert);
+ }
+
+ /**
+ * ์ด ์ฃผ๋ฌธํ ๋ฉ์ธ ๋ฉ๋ด์ ๊ฐ์
+ * @returns {number} totalMainMenu
+ */
+ calcultaeTotalMain() {
+ return Util.extractValuesAndSum(this.#main);
+ }
+
+ /**
+ * ์ํผํ์ด์ , ๋ฉ์ธ๋ฉ๋ด, ๋์ ํธ, ์๋ฃ ์ค 1๊ฐ์ด์ ์ฃผ๋ฌธํ ๋ฉ๋ด๋ง ์ถ๋ ค์ ๋ฐํ
+ * @returns {{[key:string]: number}} buyingMenu
+ */
+ calculateBuyingMenu() {
+ const totalFood = { ...this.#appetizer, ...this.#main, ...this.#dessert, ...this.#beverage };
+ const foodNames = Util.extractKeys(totalFood);
+ const buyingMenu = {};
+ foodNames.forEach((food) => {
+ if (totalFood[food]) buyingMenu[food] = totalFood[food];
+ });
+ return buyingMenu;
+ }
+
+ /**
+ * 12๋ง์ ์ด์ ๊ตฌ๋งค ์ฌ๋ถ ๋ฐํ
+ * @returns {boolean} isPresentedAmount
+ */
+ isPresentedAmount() {
+ return this.#totalPrice >= PRICE_CONSTANT.presentedAmountPrice;
+ }
+
+ /**
+ * ์ด ๊ตฌ์
๊ธ์ก์ด ๊ธฐ์ค ๊ธ์ก ์ด์ ์ฌ๋ถ์ ๋ฐ๋ผ์ ์ด๋ฒคํธ ํํ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
+ * @returns {boolean} ์ด๋ฒคํธ ๋์ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
+ */
+ isEvent() {
+ return this.#totalPrice >= 10000;
+ }
+
+ /**
+ * ํ ์ธ์ ์ด ๊ธ์ก ๋ฐํ
+ * @returns {number} totalPrice
+ */
+ getTotalPrice() {
+ return this.#totalPrice;
+ }
+}
+
+export default Menu; | JavaScript | ํ๋์ ๊ฐ์๊ฐ ๋ง์๋ฐ ์ด๋ ๊ฒ ๋์ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,93 @@
+import Util from './util/Util.js';
+import MenuValidation from './validation/MenuValidation.js';
+import { PRICE, APPETIZER, MAIN, DESSERT, BEVERAGE, PRICE_CONSTANT } from './constants/constant.js';
+
+class Menu {
+ #main = { ...MAIN };
+
+ #dessert = { ...DESSERT };
+
+ #beverage = { ...BEVERAGE };
+
+ #appetizer = { ...APPETIZER };
+
+ #totalPrice = 0;
+
+ constructor(menu) {
+ const data = Util.countMethod(menu);
+ this.#validate(data);
+ this.#calculateMenuAndPrice(data);
+ }
+
+ #validate(data) {
+ MenuValidation.validateMenuAndMenuCount(data);
+ MenuValidation.validateDuplicate(data);
+ MenuValidation.validateOnlyBeverage({ ...this.#appetizer, ...this.#main, ...this.#dessert }, data);
+ }
+
+ #calculateMenuAndPrice(data) {
+ data.forEach(([food, count]) => {
+ if (this.#appetizer[food] !== undefined) this.#appetizer[food] += count;
+ if (this.#dessert[food] !== undefined) this.#dessert[food] += count;
+ if (this.#main[food] !== undefined) this.#main[food] += count;
+ if (this.#beverage[food] !== undefined) this.#beverage[food] += count;
+ this.#totalPrice += PRICE[food] * count;
+ });
+ }
+
+ /**
+ * ์ด ์ฃผ๋ฌธํ ๋์ ํธ์ ๊ฐ์
+ * @returns {number} totalDessert
+ */
+ calcultaeTotalDessert() {
+ return Util.extractValuesAndSum(this.#dessert);
+ }
+
+ /**
+ * ์ด ์ฃผ๋ฌธํ ๋ฉ์ธ ๋ฉ๋ด์ ๊ฐ์
+ * @returns {number} totalMainMenu
+ */
+ calcultaeTotalMain() {
+ return Util.extractValuesAndSum(this.#main);
+ }
+
+ /**
+ * ์ํผํ์ด์ , ๋ฉ์ธ๋ฉ๋ด, ๋์ ํธ, ์๋ฃ ์ค 1๊ฐ์ด์ ์ฃผ๋ฌธํ ๋ฉ๋ด๋ง ์ถ๋ ค์ ๋ฐํ
+ * @returns {{[key:string]: number}} buyingMenu
+ */
+ calculateBuyingMenu() {
+ const totalFood = { ...this.#appetizer, ...this.#main, ...this.#dessert, ...this.#beverage };
+ const foodNames = Util.extractKeys(totalFood);
+ const buyingMenu = {};
+ foodNames.forEach((food) => {
+ if (totalFood[food]) buyingMenu[food] = totalFood[food];
+ });
+ return buyingMenu;
+ }
+
+ /**
+ * 12๋ง์ ์ด์ ๊ตฌ๋งค ์ฌ๋ถ ๋ฐํ
+ * @returns {boolean} isPresentedAmount
+ */
+ isPresentedAmount() {
+ return this.#totalPrice >= PRICE_CONSTANT.presentedAmountPrice;
+ }
+
+ /**
+ * ์ด ๊ตฌ์
๊ธ์ก์ด ๊ธฐ์ค ๊ธ์ก ์ด์ ์ฌ๋ถ์ ๋ฐ๋ผ์ ์ด๋ฒคํธ ํํ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
+ * @returns {boolean} ์ด๋ฒคํธ ๋์ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
+ */
+ isEvent() {
+ return this.#totalPrice >= 10000;
+ }
+
+ /**
+ * ํ ์ธ์ ์ด ๊ธ์ก ๋ฐํ
+ * @returns {number} totalPrice
+ */
+ getTotalPrice() {
+ return this.#totalPrice;
+ }
+}
+
+export default Menu; | JavaScript | Data๋ ๋ถ์ฉ์ด๋ผ๊ณ ๋ค์๋๋ฐ ์ ๋ถ ์๋ฌธ์์ด๋ฉด ์๊ด์ด ์๋์? |
@@ -0,0 +1,70 @@
+import ReservationDateValidation from './validation/ReservationDateValidation.js';
+import { DAY_CONSTANT, PRICE_CONSTANT } from './constants/constant.js';
+
+class ReservationDate {
+ #date;
+
+ constructor(date) {
+ const dateToNumber = Number(date);
+ this.#validate(dateToNumber);
+ this.#date = dateToNumber;
+ }
+
+ #validate(date) {
+ ReservationDateValidation.validateNumber(date);
+ ReservationDateValidation.validateUnderAndOver(date);
+ }
+
+ #getDate() {
+ const index = this.#date % DAY_CONSTANT.days.length;
+ const day = DAY_CONSTANT.days[index];
+ return day;
+ }
+
+ /**
+ * ํด๋น ์์ผ ์ด๋ฒคํธ ํํ ์์ ๋ฌธ๊ตฌ ๋ฐํ
+ * @returns {string} dateString
+ */
+ makeDateString() {
+ return `12์ ${this.#date}์ผ์ ์ฐํ
์ฝ ์์ฅ์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!`;
+ }
+
+ /**
+ * ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+ * @returns {number} christmasDiscount
+ */
+ calculateChristmasDiscount() {
+ if (this.#date <= DAY_CONSTANT.christmas) {
+ return (this.#date - DAY_CONSTANT.startDay) * 100 + PRICE_CONSTANT.christmasBaseDiscountPrice;
+ }
+ return 0;
+ }
+
+ /**
+ * ์ฃผ๋ง ์ฌ๋ถ ํ์ธ
+ * @returns {boolean} isWeekend
+ */
+ isWeekend() {
+ const day = this.#getDate();
+ return day === DAY_CONSTANT.days[1] || day === DAY_CONSTANT.days[2];
+ }
+
+ /**
+ * ํ์ผ ์ฌ๋ถ ํ์ธ
+ * @returns {boolean} isWeekday
+ */
+ isWeekday() {
+ const day = this.#getDate();
+ return !(day === DAY_CONSTANT.days[1]) && !(day === DAY_CONSTANT.days[2]);
+ }
+
+ /**
+ * ํด๋น ์์ผ์ด ์คํ์
ํ ์ธ์ด ํฌํจ๋๋ ์์ผ์ธ์ง ํ์ธ
+ * @returns {boolean} isSpecialDiscount
+ */
+ isSpecialDiscount() {
+ return DAY_CONSTANT.specialDiscountDays.includes(this.#date);
+ }
+}
+
+export default ReservationDate; | JavaScript | ์ด ํด๋์ค๋ ๋๋ฉ์ธ์ธ๊ฐ์..?
getDate() ๋ฉ์๋๋ ์ ๊ทผ์ ํ์ ๋์๊ณ ์ด ๋ฉ์๋์์๋ ๊ฐ์ฒด์ ์ํ๊ฐ์ ๊ทธ๋๋ก ๋ด๋ณด๋ด์๋ ์ด์ ๊ฐ ๊ถ๊ธํด์..๐ค |
@@ -0,0 +1,58 @@
+package com.codesquad.dust4.api;
+
+import com.codesquad.dust4.domain.DustForecast;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import com.codesquad.dust4.dto.ForecastResponseDto;
+import com.codesquad.dust4.dto.LocationReturnDto;
+import com.codesquad.dust4.service.DustStatusPublicApi;
+import com.codesquad.dust4.service.ForecastPublicApi;
+import com.codesquad.dust4.utils.DustMockDataUtil;
+import com.codesquad.dust4.utils.LocationConverterUtil;
+
+import java.net.URISyntaxException;
+import java.util.concurrent.ExecutionException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+@RestController
+public class DustAPIController {
+
+ private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class);
+
+ @GetMapping("/dust-status")
+
+ public ResponseEntity<DustInfoByStationDto> getDustInfo(@RequestParam("latitude") String EPSGlatitude, @RequestParam("longitude") String EPSGlongitude)
+ throws IOException, ExecutionException, InterruptedException {
+ logger.info("longitude: {}, latitude: {}", EPSGlongitude, EPSGlatitude);
+
+ LocationReturnDto locationReturnDto = LocationConverterUtil.locationConverter(EPSGlongitude, EPSGlatitude);
+
+ String tmX = locationReturnDto.getLongitude();
+ String tmY = locationReturnDto.getLatitude();
+
+ DustInfoByStationDto dustInfoByStationDto = DustStatusPublicApi.dustStatus(tmX, tmY);
+
+ return new ResponseEntity<>(dustInfoByStationDto, HttpStatus.OK);
+ }
+
+ @GetMapping("/forecast")
+ public ResponseEntity<ForecastResponseDto> enlistDustForecast() throws URISyntaxException, JsonProcessingException {
+
+ logger.info("dust forecast");
+
+ DustForecast forecast = ForecastPublicApi.forecast();
+ ForecastResponseDto responseDto = new ForecastResponseDto();
+ responseDto.setContent(forecast);
+
+ return new ResponseEntity<>(responseDto, HttpStatus.OK);
+ }
+} | Java | ๋ถํ์ํ ๊ฐํ์ด ์๋ค์! |
@@ -0,0 +1,58 @@
+package com.codesquad.dust4.api;
+
+import com.codesquad.dust4.domain.DustForecast;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import com.codesquad.dust4.dto.ForecastResponseDto;
+import com.codesquad.dust4.dto.LocationReturnDto;
+import com.codesquad.dust4.service.DustStatusPublicApi;
+import com.codesquad.dust4.service.ForecastPublicApi;
+import com.codesquad.dust4.utils.DustMockDataUtil;
+import com.codesquad.dust4.utils.LocationConverterUtil;
+
+import java.net.URISyntaxException;
+import java.util.concurrent.ExecutionException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+@RestController
+public class DustAPIController {
+
+ private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class);
+
+ @GetMapping("/dust-status")
+
+ public ResponseEntity<DustInfoByStationDto> getDustInfo(@RequestParam("latitude") String EPSGlatitude, @RequestParam("longitude") String EPSGlongitude)
+ throws IOException, ExecutionException, InterruptedException {
+ logger.info("longitude: {}, latitude: {}", EPSGlongitude, EPSGlatitude);
+
+ LocationReturnDto locationReturnDto = LocationConverterUtil.locationConverter(EPSGlongitude, EPSGlatitude);
+
+ String tmX = locationReturnDto.getLongitude();
+ String tmY = locationReturnDto.getLatitude();
+
+ DustInfoByStationDto dustInfoByStationDto = DustStatusPublicApi.dustStatus(tmX, tmY);
+
+ return new ResponseEntity<>(dustInfoByStationDto, HttpStatus.OK);
+ }
+
+ @GetMapping("/forecast")
+ public ResponseEntity<ForecastResponseDto> enlistDustForecast() throws URISyntaxException, JsonProcessingException {
+
+ logger.info("dust forecast");
+
+ DustForecast forecast = ForecastPublicApi.forecast();
+ ForecastResponseDto responseDto = new ForecastResponseDto();
+ responseDto.setContent(forecast);
+
+ return new ResponseEntity<>(responseDto, HttpStatus.OK);
+ }
+} | Java | ํ๋ผ๋ฏธํฐ ๋ณ์๋ช
์ฒซ ๊ธ์์ ๋๋ฌธ์ ์ฐ์ง ์๋๋ก ๋ฐ๊ฟ ์ฃผ์๊ณ ์.
์๋ง `EPSG` ๊ฐ ๋ฌด์ธ๊ฐ์ ์ฝ์ด์ธ ๋ชจ์์
๋๋ค. ๊ทธ๋ด๋ ์๋์ ๊ฐ์ ๋ค์ด๋ฐ์ด๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
`String epsgLatitude, String epsgLongitude` |
@@ -0,0 +1,49 @@
+package com.codesquad.dust4.domain;
+
+public class DustStatusQuo {
+
+ private String dataTime; //์ธก์ ์ผ
+ private String pm10Value; //๋ฏธ์ธ๋จผ์ง(PM10) ๋๋
+ private String pm10Grade; //๋ฏธ์ธ๋จผ์ง(PM10) 24์๊ฐ ๋ฑ๊ธ
+
+ public DustStatusQuo() {}
+
+ public DustStatusQuo(String dataTime, String pm10Value, String pm10Grade) {
+ this.dataTime = dataTime;
+ this.pm10Value = pm10Value;
+ this.pm10Grade = pm10Grade;
+ }
+
+ public String getDataTime() {
+ return dataTime;
+ }
+
+ public void setDataTime(String dataTime) {
+ this.dataTime = dataTime;
+ }
+
+ public String getPm10Value() {
+ return pm10Value;
+ }
+
+ public void setPm10Value(String pm10Value) {
+ this.pm10Value = pm10Value;
+ }
+
+ public String getPm10Grade() {
+ return pm10Grade;
+ }
+
+ public void setPm10Grade(String pm10Grade) {
+ this.pm10Grade = pm10Grade;
+ }
+
+ @Override
+ public String toString() {
+ return "DustStatusQuo{" +
+ "dataTime='" + dataTime + '\'' +
+ ", pm10Value='" + pm10Value + '\'' +
+ ", pm10Grade='" + pm10Grade + '\'' +
+ '}';
+ }
+} | Java | ์....์ด๊ฒ ์ ๋ ํญ์ ๊ณ ๋ฏผ๋๋ ๋ถ๋ถ์ธ๋ฐ์.
ํ์ฌ ์ํ๋ผ๋ ์๋ฏธ์์ `StatusQuo` ๋ผ๊ณ ํ์
จ๊ฒ ์ง๋ง ์ฌ์ค ์ด๊ฒ ํ์
์ ๊ด์ ์์๋...ํํ ์ฌ์ฉ๋์ง ์๋ ๋จ์ด์ด๊ธด ํด์...
`CurrentStatus` ์ ๋๋ฉด ์ข์ง ์์๊น ์ถ๊ธด ํ๋ฐ์. status quo๋ ์ฌ์ค ์ข ์ด๋ ค์ด ๋จ์ด๋ผ์์.
ํด๋์ค๋ช
์ด๋ ๋ณ์๋ช
์๋ช
์ ์ฌ์ฉ๋๋ ์๋จ์ด๋ ํญ์ ์คํ๊ต ์์ด ๋จ์ด์ง ์ ๋ ์์ค์ ๋ฒ์ด๋์ง ์๋ ๊ฒ์ด ๋ฐ๋์งํด๋ด์. ๊ทธ๋ฆฌ๊ณ ๊ฐ๊ธ์ ๊ต์ฅํ ์ฝ๊ฒ ์จ์ผ ํ๊ณ ์.
`HyunjaeSangTae` ๊ฐ์ ์๋ช
๋ง ์๋๋ผ๋ฉด ๋ง์ด์์. |
@@ -0,0 +1,131 @@
+package com.codesquad.dust4.service;
+
+import com.codesquad.dust4.domain.DustStatusQuo;
+import com.codesquad.dust4.domain.LocationOfStation;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DustStatusPublicApi {
+ public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException {
+ String response = stationFromPublicApi(tmX, tmY);
+ LocationOfStation closestStation = closestStation(response);
+ String dustStatusResponse = dustStatusFromPublicApi(closestStation);
+ List<DustStatusQuo> status = statusQuos(dustStatusResponse);
+
+ return new DustInfoByStationDto(status, closestStation);
+ }
+
+ private static LocationOfStation closestStation(String stationJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<LocationOfStation> stations = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(stationJson);
+ array = (JSONArray) obj.get("list");
+ for (Object o : array) {
+ JSONObject o1 = (JSONObject) o;
+ String addr = String.valueOf(o1.get("addr"));
+ String stationName = String.valueOf(o1.get("stationName"));
+ String tm = String.valueOf(o1.get("tm"));
+
+ LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm));
+ stations.add(station);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station);
+ }
+
+ private static String stationFromPublicApi(String tmX, String tmY) throws IOException {
+ URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY +
+ "&tmX=" + tmX +
+ "&tmY=" + tmY +
+ "&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+
+ private static List<DustStatusQuo> statusQuos(String statusJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<DustStatusQuo> statusList = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(statusJson);
+ array = (JSONArray) obj.get("list");
+ for (Object object : array) {
+ JSONObject stationObject = (JSONObject) object;
+ String dateTime = String.valueOf(stationObject.get("dataTime"));
+ String grade = String.valueOf(stationObject.get("pm10Grade"));
+ if (grade.equals("-")) {
+ grade = "0";
+ }
+ String value = String.valueOf(stationObject.get("pm10Value"));
+ if (value.equals("-")) {
+ value = "0";
+ }
+
+ DustStatusQuo status = new DustStatusQuo(dateTime, value, grade);
+ statusList.add(status);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ return statusList;
+ }
+
+ private static String readString(HttpURLConnection connection) throws IOException {
+ BufferedReader bufferedReader;
+ if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } else {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+
+ bufferedReader.close();
+ connection.disconnect();
+
+ return stringBuilder.toString();
+ }
+
+
+ private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException {
+ URL url = new URL(PublicApi.API_URL +
+ "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" +
+ station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" +
+ PublicApi.API_KEY +
+ "&ver=1.3&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+} | Java | o1 ๋ณด๋ค ๋ ๋์ ๋ค์ด๋ฐ ๊ณ ๋ฏผํด์ฃผ์๊ณ ์. |
@@ -0,0 +1,131 @@
+package com.codesquad.dust4.service;
+
+import com.codesquad.dust4.domain.DustStatusQuo;
+import com.codesquad.dust4.domain.LocationOfStation;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DustStatusPublicApi {
+ public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException {
+ String response = stationFromPublicApi(tmX, tmY);
+ LocationOfStation closestStation = closestStation(response);
+ String dustStatusResponse = dustStatusFromPublicApi(closestStation);
+ List<DustStatusQuo> status = statusQuos(dustStatusResponse);
+
+ return new DustInfoByStationDto(status, closestStation);
+ }
+
+ private static LocationOfStation closestStation(String stationJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<LocationOfStation> stations = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(stationJson);
+ array = (JSONArray) obj.get("list");
+ for (Object o : array) {
+ JSONObject o1 = (JSONObject) o;
+ String addr = String.valueOf(o1.get("addr"));
+ String stationName = String.valueOf(o1.get("stationName"));
+ String tm = String.valueOf(o1.get("tm"));
+
+ LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm));
+ stations.add(station);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station);
+ }
+
+ private static String stationFromPublicApi(String tmX, String tmY) throws IOException {
+ URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY +
+ "&tmX=" + tmX +
+ "&tmY=" + tmY +
+ "&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+
+ private static List<DustStatusQuo> statusQuos(String statusJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<DustStatusQuo> statusList = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(statusJson);
+ array = (JSONArray) obj.get("list");
+ for (Object object : array) {
+ JSONObject stationObject = (JSONObject) object;
+ String dateTime = String.valueOf(stationObject.get("dataTime"));
+ String grade = String.valueOf(stationObject.get("pm10Grade"));
+ if (grade.equals("-")) {
+ grade = "0";
+ }
+ String value = String.valueOf(stationObject.get("pm10Value"));
+ if (value.equals("-")) {
+ value = "0";
+ }
+
+ DustStatusQuo status = new DustStatusQuo(dateTime, value, grade);
+ statusList.add(status);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ return statusList;
+ }
+
+ private static String readString(HttpURLConnection connection) throws IOException {
+ BufferedReader bufferedReader;
+ if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } else {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+
+ bufferedReader.close();
+ connection.disconnect();
+
+ return stringBuilder.toString();
+ }
+
+
+ private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException {
+ URL url = new URL(PublicApi.API_URL +
+ "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" +
+ station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" +
+ PublicApi.API_KEY +
+ "&ver=1.3&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+} | Java | ํด๋์ค๋ช
์ด ๋ชจํธํ๋ค์. ์.... `ApiUtils` ์ ๋๋ก?
์๋๋ฉด `ApiProcessor` ์ ๋๋ ๊ด์ฐฎ๊ฒ ๋ค์.
๊ทธ๋ฆฌ๊ณ ์ด ํด๋์ค์์ ๋๋ฌด ๋ง์ ๊ธฐ๋ฅ์ด ์ํ๋๊ณ ์๋๋ฐ์,
์ด ํด๋์ค์ ์ญํ ์ 1) ๋์ด์จ ๋ฆฌ์คํฐ์ค๋ฅผ ํ์ฑํด์ ์ ์ ํ ๊ฐ์ฒด๋ก ๋๋ ค์ฃผ๊ฑฐ๋ 2) API ์ฝ์ ์ํ ํ๋ผ๋ฏธํฐ๋ฅผ ์กฐํฉํด์ connection string์ ๋ง๋ค์ด์ฃผ๋ ๊ฒ ์ ๋๋ก ํ์ ํ์ผ๋ฉด ์ข๊ฒ ์ด์. |
@@ -0,0 +1,131 @@
+package com.codesquad.dust4.service;
+
+import com.codesquad.dust4.domain.DustStatusQuo;
+import com.codesquad.dust4.domain.LocationOfStation;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DustStatusPublicApi {
+ public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException {
+ String response = stationFromPublicApi(tmX, tmY);
+ LocationOfStation closestStation = closestStation(response);
+ String dustStatusResponse = dustStatusFromPublicApi(closestStation);
+ List<DustStatusQuo> status = statusQuos(dustStatusResponse);
+
+ return new DustInfoByStationDto(status, closestStation);
+ }
+
+ private static LocationOfStation closestStation(String stationJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<LocationOfStation> stations = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(stationJson);
+ array = (JSONArray) obj.get("list");
+ for (Object o : array) {
+ JSONObject o1 = (JSONObject) o;
+ String addr = String.valueOf(o1.get("addr"));
+ String stationName = String.valueOf(o1.get("stationName"));
+ String tm = String.valueOf(o1.get("tm"));
+
+ LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm));
+ stations.add(station);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station);
+ }
+
+ private static String stationFromPublicApi(String tmX, String tmY) throws IOException {
+ URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY +
+ "&tmX=" + tmX +
+ "&tmY=" + tmY +
+ "&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+
+ private static List<DustStatusQuo> statusQuos(String statusJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<DustStatusQuo> statusList = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(statusJson);
+ array = (JSONArray) obj.get("list");
+ for (Object object : array) {
+ JSONObject stationObject = (JSONObject) object;
+ String dateTime = String.valueOf(stationObject.get("dataTime"));
+ String grade = String.valueOf(stationObject.get("pm10Grade"));
+ if (grade.equals("-")) {
+ grade = "0";
+ }
+ String value = String.valueOf(stationObject.get("pm10Value"));
+ if (value.equals("-")) {
+ value = "0";
+ }
+
+ DustStatusQuo status = new DustStatusQuo(dateTime, value, grade);
+ statusList.add(status);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ return statusList;
+ }
+
+ private static String readString(HttpURLConnection connection) throws IOException {
+ BufferedReader bufferedReader;
+ if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } else {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+
+ bufferedReader.close();
+ connection.disconnect();
+
+ return stringBuilder.toString();
+ }
+
+
+ private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException {
+ URL url = new URL(PublicApi.API_URL +
+ "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" +
+ station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" +
+ PublicApi.API_KEY +
+ "&ver=1.3&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+} | Java | ๋ ์นธ ๋์ด์ก๊ตฐ์. |
@@ -0,0 +1,30 @@
+package com.codesquad.dust4.utils;
+
+import com.codesquad.dust4.api.DustAPIController;
+import java.util.concurrent.ExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.client.RestTemplate;
+
+public class AccessTokenUtil {
+
+ public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a";
+ public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349";
+ private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class);
+
+ public static String getLocationConversionAPIToken()
+ throws ExecutionException, InterruptedException {
+ String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json";
+ String accessTokenURL =
+ URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret="
+ + AccessTokenUtil.CONSUMER_SECRET_LOCATION;
+
+ RestTemplate restTemplate = new RestTemplate();
+
+ String receivedToken = restTemplate.getForObject(accessTokenURL, String.class);
+ String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken);
+ logger.info("accessToken: {} ", accessToken);
+
+ return accessToken;
+ }
+} | Java | ์์ฒญ์ด ๋ค์ด์ฌ๋๋ง๋ค API call์ ๋ฐ์์์ผ ํ ํฐ ์ ๋ณด๋ฅผ ์ป์ด์ค๊ฒ ๋๊ฒ ๋ค์.
์ ๋ง ๊ทธ๋์ผ ํ ํ์๊ฐ ์๋์? ํ ํฐ์ด ๋งค ์์ฒญ์๋ง๋ค ๋ณ๊ฒฝ๋๋ ๊ฑด๊ฐ์.
์ธ๋ถ API ํธ์ถ ํ์๋ ์ต์ํํ๋ ๊ฒ์ด ์ข์๋ฐ์, ๋ง์ฝ ์ด API์ ์๋ต ์๋๊ฐ ๋ฆ๋ค๊ฑฐ๋ ํ๋ฉด, ์๋น์ค ์๋์ ์ง์ฐ์ผ๋ก ๋ฐ๋ก ์ด์ด์ง ๊ฑฐ๊ณ , ์ด๋ฐ ์์ผ๋ก ์ฐ์์ ์ธ ์ง์ฐ์ ๊ฒช๋ค ๋ณด๋ฉด ๊ฒฐ๊ตญ ์๋น์ค ์ ๋ฉด ์ฅ์ ๋ก๋ ์ด์ด์ง ์ ์์ด์.
๋ง์ฝ access token์ด ๊ณ์ ๋์ ์ผ๋ก ๋ฐ๋์ด์ผ๋ง ํ๋ ๊ฒ์ด ์๋๋ผ๋ฉด, properties ํ์ผ์์ ์ ์ ๊ฐ์ผ๋ก ๊ด๋ฆฌํด์ฃผ์๊ณ ,
์๋ฅผ ๋ค์ด... ๋งค ์๊ฐ๋ง๋ค ๋ฐ๋์ด์ผ ํ๋ค๋ฉด `@Scheduled` ์ ๊ทน์ ์ผ๋ก ํ์ฉํด์ ๋ด๋ถ cache ์ฌ์ฉํ๋ ์ชฝ์ผ๋ก ์์ ๋๋ฉด ์ข๊ฒ ๋ค์. |
@@ -0,0 +1,30 @@
+package com.codesquad.dust4.utils;
+
+import com.codesquad.dust4.api.DustAPIController;
+import java.util.concurrent.ExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.client.RestTemplate;
+
+public class AccessTokenUtil {
+
+ public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a";
+ public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349";
+ private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class);
+
+ public static String getLocationConversionAPIToken()
+ throws ExecutionException, InterruptedException {
+ String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json";
+ String accessTokenURL =
+ URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret="
+ + AccessTokenUtil.CONSUMER_SECRET_LOCATION;
+
+ RestTemplate restTemplate = new RestTemplate();
+
+ String receivedToken = restTemplate.getForObject(accessTokenURL, String.class);
+ String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken);
+ logger.info("accessToken: {} ", accessToken);
+
+ return accessToken;
+ }
+} | Java | ์ด ํด๋์ค๋ `@Component` ์ฌ๋ ๋๊ฒ ๋๋ฐ์. |
@@ -0,0 +1,30 @@
+package com.codesquad.dust4.utils;
+
+import com.codesquad.dust4.api.DustAPIController;
+import java.util.concurrent.ExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.client.RestTemplate;
+
+public class AccessTokenUtil {
+
+ public static final String CONSUMER_KEY_LOCATION = "6e8fc57906324e20805a";
+ public static final String CONSUMER_SECRET_LOCATION = "aaa5becbdfcd4b5bb349";
+ private static final Logger logger = LoggerFactory.getLogger(DustAPIController.class);
+
+ public static String getLocationConversionAPIToken()
+ throws ExecutionException, InterruptedException {
+ String URL = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json";
+ String accessTokenURL =
+ URL + "?consumer_key=" + AccessTokenUtil.CONSUMER_KEY_LOCATION + "&consumer_secret="
+ + AccessTokenUtil.CONSUMER_SECRET_LOCATION;
+
+ RestTemplate restTemplate = new RestTemplate();
+
+ String receivedToken = restTemplate.getForObject(accessTokenURL, String.class);
+ String accessToken = ParseJSONDataUtil.parseAccessTokenJson(receivedToken);
+ logger.info("accessToken: {} ", accessToken);
+
+ return accessToken;
+ }
+} | Java | ํด๋์ค๋ฅผ `@Component` ๋ก ๊ด๋ฆฌํ๋ฉด ์ด ๊ฐ๋ `@Value` ๋ก ์ฃผ์
๋ฐ์ ์ ์๊ฒ ๋ค์. |
@@ -0,0 +1,15 @@
+package com.codesquad.dust4.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class WebCorsConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**")
+ .allowedOrigins("*");
+ }
+}
\ No newline at end of file | Java | `implements WebMvcConfigurer` ๋ณด๋จ `extends WebMvcConfigurationSupport` ๊ฐ ๋ ๋ซ๋ค๊ณ ์๊ฐ๋๋ค์.
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.html |
@@ -0,0 +1,8 @@
+package com.codesquad.dust4.exception;
+
+import org.springframework.web.bind.annotation.ControllerAdvice;
+
+@ControllerAdvice
+public class CustomControllerAdvice {
+
+} | Java | ์๋ง OAuth2 ์๊ตฌ์ฌํญ์ ์ ๋ ๊ตฌํํ์ง ๋ชปํ๋ ๊ฒ์ด ์๋๊ฐ ์๊ฐ๋ญ๋๋ค ใ
ใ
|
@@ -0,0 +1,49 @@
+package com.codesquad.dust4.domain;
+
+public class DustStatusQuo {
+
+ private String dataTime; //์ธก์ ์ผ
+ private String pm10Value; //๋ฏธ์ธ๋จผ์ง(PM10) ๋๋
+ private String pm10Grade; //๋ฏธ์ธ๋จผ์ง(PM10) 24์๊ฐ ๋ฑ๊ธ
+
+ public DustStatusQuo() {}
+
+ public DustStatusQuo(String dataTime, String pm10Value, String pm10Grade) {
+ this.dataTime = dataTime;
+ this.pm10Value = pm10Value;
+ this.pm10Grade = pm10Grade;
+ }
+
+ public String getDataTime() {
+ return dataTime;
+ }
+
+ public void setDataTime(String dataTime) {
+ this.dataTime = dataTime;
+ }
+
+ public String getPm10Value() {
+ return pm10Value;
+ }
+
+ public void setPm10Value(String pm10Value) {
+ this.pm10Value = pm10Value;
+ }
+
+ public String getPm10Grade() {
+ return pm10Grade;
+ }
+
+ public void setPm10Grade(String pm10Grade) {
+ this.pm10Grade = pm10Grade;
+ }
+
+ @Override
+ public String toString() {
+ return "DustStatusQuo{" +
+ "dataTime='" + dataTime + '\'' +
+ ", pm10Value='" + pm10Value + '\'' +
+ ", pm10Grade='" + pm10Grade + '\'' +
+ '}';
+ }
+} | Java | ๋ค, ๊ทธ๋ ๋ค์. ์ฌ์ค Status๋ง ์์ผ๋ฉด ๋์ง Quo๋ ๊ดํ ์ธ๋ฐ์๋ ์ ๋ฏธ์ฌ ๊ฐ์^^ ์กฐ๊ธ ๋ ๋ช
ํํ ๋จ์ด๋ช
์ฌ์ฉ์ ๋
ธ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,131 @@
+package com.codesquad.dust4.service;
+
+import com.codesquad.dust4.domain.DustStatusQuo;
+import com.codesquad.dust4.domain.LocationOfStation;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DustStatusPublicApi {
+ public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException {
+ String response = stationFromPublicApi(tmX, tmY);
+ LocationOfStation closestStation = closestStation(response);
+ String dustStatusResponse = dustStatusFromPublicApi(closestStation);
+ List<DustStatusQuo> status = statusQuos(dustStatusResponse);
+
+ return new DustInfoByStationDto(status, closestStation);
+ }
+
+ private static LocationOfStation closestStation(String stationJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<LocationOfStation> stations = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(stationJson);
+ array = (JSONArray) obj.get("list");
+ for (Object o : array) {
+ JSONObject o1 = (JSONObject) o;
+ String addr = String.valueOf(o1.get("addr"));
+ String stationName = String.valueOf(o1.get("stationName"));
+ String tm = String.valueOf(o1.get("tm"));
+
+ LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm));
+ stations.add(station);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station);
+ }
+
+ private static String stationFromPublicApi(String tmX, String tmY) throws IOException {
+ URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY +
+ "&tmX=" + tmX +
+ "&tmY=" + tmY +
+ "&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+
+ private static List<DustStatusQuo> statusQuos(String statusJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<DustStatusQuo> statusList = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(statusJson);
+ array = (JSONArray) obj.get("list");
+ for (Object object : array) {
+ JSONObject stationObject = (JSONObject) object;
+ String dateTime = String.valueOf(stationObject.get("dataTime"));
+ String grade = String.valueOf(stationObject.get("pm10Grade"));
+ if (grade.equals("-")) {
+ grade = "0";
+ }
+ String value = String.valueOf(stationObject.get("pm10Value"));
+ if (value.equals("-")) {
+ value = "0";
+ }
+
+ DustStatusQuo status = new DustStatusQuo(dateTime, value, grade);
+ statusList.add(status);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ return statusList;
+ }
+
+ private static String readString(HttpURLConnection connection) throws IOException {
+ BufferedReader bufferedReader;
+ if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } else {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+
+ bufferedReader.close();
+ connection.disconnect();
+
+ return stringBuilder.toString();
+ }
+
+
+ private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException {
+ URL url = new URL(PublicApi.API_URL +
+ "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" +
+ station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" +
+ PublicApi.API_KEY +
+ "&ver=1.3&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+} | Java | ์ฌ๊ธฐ์๋ gson ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋๋ฐ์. ํน์๋ (์๋ง ํธ๋
์ค์๋ ๊ฒ ๊ฐ์) ์คํ๋ง๋ถํธ์ ๋ด์ฅ๋ Jackson ์ฌ์ฉ์ ๊ถ์ฅํ์๋๋ผ๊ตฌ์. ์๋ฌด๋๋ ๊ทธ๊ฒ ๋ง์๊น์? ๊ทธ๋ฐ๋ฐ gson์ด ์๋ฌด๋๋ Jackson์ ๋นํด ์ฌ์ฉํ๊ธฐ๋ ์ฝ๋ค๋ณด๋ ใ
ใ
|
@@ -0,0 +1,131 @@
+package com.codesquad.dust4.service;
+
+import com.codesquad.dust4.domain.DustStatusQuo;
+import com.codesquad.dust4.domain.LocationOfStation;
+import com.codesquad.dust4.dto.DustInfoByStationDto;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DustStatusPublicApi {
+ public static DustInfoByStationDto dustStatus(String tmX, String tmY) throws IOException {
+ String response = stationFromPublicApi(tmX, tmY);
+ LocationOfStation closestStation = closestStation(response);
+ String dustStatusResponse = dustStatusFromPublicApi(closestStation);
+ List<DustStatusQuo> status = statusQuos(dustStatusResponse);
+
+ return new DustInfoByStationDto(status, closestStation);
+ }
+
+ private static LocationOfStation closestStation(String stationJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<LocationOfStation> stations = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(stationJson);
+ array = (JSONArray) obj.get("list");
+ for (Object o : array) {
+ JSONObject o1 = (JSONObject) o;
+ String addr = String.valueOf(o1.get("addr"));
+ String stationName = String.valueOf(o1.get("stationName"));
+ String tm = String.valueOf(o1.get("tm"));
+
+ LocationOfStation station = new LocationOfStation(stationName, addr, Float.parseFloat(tm));
+ stations.add(station);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return stations.stream().reduce(stations.get(0), (closest, station) -> closest.getTm() <= station.getTm() ? closest : station);
+ }
+
+ private static String stationFromPublicApi(String tmX, String tmY) throws IOException {
+ URL url = new URL(PublicApi.API_URL + "MsrstnInfoInqireSvc/getNearbyMsrstnList?ServiceKey=" + PublicApi.API_KEY +
+ "&tmX=" + tmX +
+ "&tmY=" + tmY +
+ "&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+
+ private static List<DustStatusQuo> statusQuos(String statusJson) {
+ JSONParser parser = new JSONParser();
+ JSONObject obj;
+ JSONArray array;
+ List<DustStatusQuo> statusList = new ArrayList<>();
+
+ try {
+ obj = (JSONObject) parser.parse(statusJson);
+ array = (JSONArray) obj.get("list");
+ for (Object object : array) {
+ JSONObject stationObject = (JSONObject) object;
+ String dateTime = String.valueOf(stationObject.get("dataTime"));
+ String grade = String.valueOf(stationObject.get("pm10Grade"));
+ if (grade.equals("-")) {
+ grade = "0";
+ }
+ String value = String.valueOf(stationObject.get("pm10Value"));
+ if (value.equals("-")) {
+ value = "0";
+ }
+
+ DustStatusQuo status = new DustStatusQuo(dateTime, value, grade);
+ statusList.add(status);
+ }
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ return statusList;
+ }
+
+ private static String readString(HttpURLConnection connection) throws IOException {
+ BufferedReader bufferedReader;
+ if (connection.getResponseCode() >= 200 && connection.getResponseCode() <= 300) {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ } else {
+ bufferedReader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ stringBuilder.append(line);
+ }
+
+ bufferedReader.close();
+ connection.disconnect();
+
+ return stringBuilder.toString();
+ }
+
+
+ private static String dustStatusFromPublicApi(LocationOfStation station) throws IOException {
+ URL url = new URL(PublicApi.API_URL +
+ "ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?stationName=" +
+ station.getStationName() + "&dataTerm=DAILY&pageNo=1&numOfRows=25&ServiceKey=" +
+ PublicApi.API_KEY +
+ "&ver=1.3&_returnType=json");
+
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-type", "application/json");
+
+ return readString(connection);
+ }
+} | Java | ์ธํ
๋ฆฌ์ ์ด์ ์ ์ฅํ ๋ ์์์ ์ปจ๋ฒค์
์ ๋ง์ถฐ์ฃผ๋ ๊ธฐ๋ฅ์ด ์๋ค๊ณ ํ๋๋ฐ์. ๊ทธ ์ด๋ฆ์ด ๊ธฐ์ต์ด ์๋์ง๋ง ๋์
์ ํด์ผ๊ฐฐ์ต๋๋ค. |
@@ -0,0 +1,67 @@
+package christmas.controller;
+
+import christmas.domain.Menu;
+import christmas.domain.Today;
+import christmas.domain.dao.OrderDAO;
+import christmas.service.EventDatable;
+import christmas.service.EventDateService;
+import christmas.service.EventPrice;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class Planner {
+ private final EventDatable eventDatable = new EventDateService();
+ private final OrderDAO orderDAO = OrderDAO.getInstance();
+ private Today today;
+ private EventPrice eventPrice;
+
+ public void run() {
+ InputView.printStartMessage();
+ dateRun();
+ menuRun();
+ eventPrice = new EventPrice(today);
+ InputView.printResultMessage();
+ discountDetailsRun();
+ }
+
+ private void menuRun() {
+ while (true) {
+ try {
+ orderDAO.addOrderDetail(InputView.readOrderAccept());
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void dateRun() {
+ while (true) {
+ try {
+ String input = InputView.readVisitDate();
+ Validator.validateDateToNumber(input);
+ today = new Today(Integer.parseInt(input), eventDatable);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private String giveaway() {
+ if (eventPrice.isGiveawayLimit()) {
+ return Menu.CHAMPAGNE.getName() + " 1๊ฐ";
+ }
+ return null;
+ }
+
+ private void discountDetailsRun() {
+ OutputView.printMenu(orderDAO.getOrder());
+ OutputView.printTotalOrderPrice(eventPrice.getTotalPrice());
+ OutputView.printGiveAway(giveaway());
+ OutputView.printBenefitDetails(eventPrice.getDiscountDetails());
+ OutputView.printTotalBenefit(eventPrice.totalDiscount());
+ OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway());
+ OutputView.printEventBadge(eventPrice.getEventBadge());
+ }
+} | Java | Planner ๋ณด๋ค๋ ~~~Controller๋ผ๋ ์ด๋ฆ์ผ๋ก ๋ฐ๊พธ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
์ฒ์์ ๋๋ฉ์ธ์ธ ์ค ์์์ด์. |
@@ -0,0 +1,67 @@
+package christmas.controller;
+
+import christmas.domain.Menu;
+import christmas.domain.Today;
+import christmas.domain.dao.OrderDAO;
+import christmas.service.EventDatable;
+import christmas.service.EventDateService;
+import christmas.service.EventPrice;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class Planner {
+ private final EventDatable eventDatable = new EventDateService();
+ private final OrderDAO orderDAO = OrderDAO.getInstance();
+ private Today today;
+ private EventPrice eventPrice;
+
+ public void run() {
+ InputView.printStartMessage();
+ dateRun();
+ menuRun();
+ eventPrice = new EventPrice(today);
+ InputView.printResultMessage();
+ discountDetailsRun();
+ }
+
+ private void menuRun() {
+ while (true) {
+ try {
+ orderDAO.addOrderDetail(InputView.readOrderAccept());
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void dateRun() {
+ while (true) {
+ try {
+ String input = InputView.readVisitDate();
+ Validator.validateDateToNumber(input);
+ today = new Today(Integer.parseInt(input), eventDatable);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private String giveaway() {
+ if (eventPrice.isGiveawayLimit()) {
+ return Menu.CHAMPAGNE.getName() + " 1๊ฐ";
+ }
+ return null;
+ }
+
+ private void discountDetailsRun() {
+ OutputView.printMenu(orderDAO.getOrder());
+ OutputView.printTotalOrderPrice(eventPrice.getTotalPrice());
+ OutputView.printGiveAway(giveaway());
+ OutputView.printBenefitDetails(eventPrice.getDiscountDetails());
+ OutputView.printTotalBenefit(eventPrice.totalDiscount());
+ OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway());
+ OutputView.printEventBadge(eventPrice.getEventBadge());
+ }
+} | Java | ์ปจํธ๋กค๋ฌ๋ ์ํ๋ฅผ ๊ฐ์ง์ง ์๋ ๊ฒ ์ข์ต๋๋ค. Today์ EventPrice๋ฅผ ๋ฉ์๋ ๋ด ์ง์ญ๋ณ์๋ก ํ์ฉํด์ฃผ์ธ์.
์ ์ง๋ณด์ ์, ๊ฐ์ ์๋ชป ํ ๋นํ๊ฑฐ๋ ์คํ ์์๊ฐ ๊ผฌ์ฌ์ ์๋ํ์ง ์์ ๋ฒ๊ทธ๋ฅผ ๋ฐ์์ํฌ ์ ์์ด์. |
@@ -0,0 +1,67 @@
+package christmas.controller;
+
+import christmas.domain.Menu;
+import christmas.domain.Today;
+import christmas.domain.dao.OrderDAO;
+import christmas.service.EventDatable;
+import christmas.service.EventDateService;
+import christmas.service.EventPrice;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class Planner {
+ private final EventDatable eventDatable = new EventDateService();
+ private final OrderDAO orderDAO = OrderDAO.getInstance();
+ private Today today;
+ private EventPrice eventPrice;
+
+ public void run() {
+ InputView.printStartMessage();
+ dateRun();
+ menuRun();
+ eventPrice = new EventPrice(today);
+ InputView.printResultMessage();
+ discountDetailsRun();
+ }
+
+ private void menuRun() {
+ while (true) {
+ try {
+ orderDAO.addOrderDetail(InputView.readOrderAccept());
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private void dateRun() {
+ while (true) {
+ try {
+ String input = InputView.readVisitDate();
+ Validator.validateDateToNumber(input);
+ today = new Today(Integer.parseInt(input), eventDatable);
+ break;
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ private String giveaway() {
+ if (eventPrice.isGiveawayLimit()) {
+ return Menu.CHAMPAGNE.getName() + " 1๊ฐ";
+ }
+ return null;
+ }
+
+ private void discountDetailsRun() {
+ OutputView.printMenu(orderDAO.getOrder());
+ OutputView.printTotalOrderPrice(eventPrice.getTotalPrice());
+ OutputView.printGiveAway(giveaway());
+ OutputView.printBenefitDetails(eventPrice.getDiscountDetails());
+ OutputView.printTotalBenefit(eventPrice.totalDiscount());
+ OutputView.printResultPayment(eventPrice.totalDiscountExcludingGiveaway());
+ OutputView.printEventBadge(eventPrice.getEventBadge());
+ }
+} | Java | eventPrice์ ๋ก์ง์ด ์ธ๋ถ๋ก ๋
ธ์ถ๋์ด ์์ด์. ๋ก์ง์ eventPrice ๋ด๋ถ๋ก ์ฎ๊ฒจ์ฃผ์ธ์.
```suggestion
private String giveaway() {
return eventPrice.getGiveawayMessage();
}
``` |
@@ -0,0 +1,11 @@
+package christmas.controller;
+
+public class Validator {
+ public static void validateDateToNumber(String number) {
+ try {
+ Integer.parseInt(number);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.");
+ }
+ }
+} | Java | Validator๋ฅผ validator ํจํค์ง๋ก ์ฎ๊ฒจ์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๋ฆ๋ DateValidator๋ก ๋ฐ๊พธ๋ฉด ์ข์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,75 @@
+package christmas.domain;
+
+import java.util.Map;
+import java.util.AbstractMap;
+
+public enum Menu {
+ APPETIZER(0, 0, "์ ํผํ์ด์ "),
+ MAIN_DISH(1, 2023, "๋ฉ์ธ"),
+ DESSERT(2, 2023, "๋์ ํธ"),
+ DRINK(3, 0, "์๋ฃ"),
+ MUSHROOM_SOUP(0, 6000, "์์ก์ด์ํ"),
+ TAPAS(0, 5500, "ํํ์ค"),
+ CAESAR_SALAD(0, 8000, "์์ ์๋ฌ๋"),
+ T_BONE_STEAK(1, 55000, "ํฐ๋ณธ์คํ
์ดํฌ"),
+ BBQ_RIBS(1, 54000, "๋ฐ๋นํ๋ฆฝ"),
+ SEAFOOD_PASTA(1, 35000, "ํด์ฐ๋ฌผํ์คํ"),
+ CHRISTMAS_PASTA(1, 25000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ"),
+ CHOCO_CAKE(2, 15000, "์ด์ฝ์ผ์ดํฌ"),
+ ICE_CREAM(2, 5000, "์์ด์คํฌ๋ฆผ"),
+ ZERO_COKE(3, 3000, "์ ๋ก์ฝ๋ผ"),
+ RED_WINE(3, 60000, "๋ ๋์์ธ"),
+ CHAMPAGNE(3, 25000, "์ดํ์ธ");
+
+ private final int type;
+ private final int price;
+ private final String name;
+
+ Menu(int type, int price, String name) {
+ this.type = type;
+ this.price = price;
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static Menu matchingMenu(String inputMenuName) {
+ for (Menu menu : Menu.values()) {
+ if (menu.name.equalsIgnoreCase(inputMenuName)) {
+ return menu;
+ }
+ }
+ throw new IllegalArgumentException("[ERROR] ์
๋ ฅํ์ ๋ฉ๋ด๋ ์๋ ๋ฉ๋ด์
๋๋ค.");
+ }
+
+ public static AbstractMap.SimpleEntry<String, Integer> giveawayChampagne() {
+ return new AbstractMap.SimpleEntry<>(CHAMPAGNE.name, CHAMPAGNE.price);
+ }
+
+ public static boolean isAllDrinks(Map<Menu, Integer> orderDetail) {
+ return orderDetail.keySet().stream()
+ .allMatch(item -> item.type == DRINK.type);
+ }
+
+ public static int calculateTotalPrice(Map<Menu, Integer> orderDetail) {
+ return orderDetail.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().price * entry.getValue())
+ .sum();
+ }
+
+ public static int calculateMainDishDiscount(Map<Menu, Integer> orderDetail) {
+ return orderDetail.entrySet().stream()
+ .filter(entry -> entry.getKey().type == MAIN_DISH.type)
+ .mapToInt(entry -> MAIN_DISH.price * entry.getValue())
+ .sum();
+ }
+
+ public static int calculateDessertDiscount(Map<Menu, Integer> orderDetail) {
+ return orderDetail.entrySet().stream()
+ .filter(entry -> entry.getKey().type == DESSERT.type)
+ .mapToInt(entry -> DESSERT.price * entry.getValue())
+ .sum();
+ }
+} | Java | type์ ์ซ์๋ก ๊ตฌ๋ณํ์ง ๋ง๊ณ ์ enum์ ํ์ ๊ตฌ๋ณํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์.
์ ๋ Course enum์์ APPETIZER, MAIN, DESSERT, DRINK๋ฅผ ๋ง๋ค์ด์ ๊ตฌ๋ณํ์ด์. |
@@ -0,0 +1,48 @@
+package christmas.domain;
+
+import christmas.service.EventDatable;
+
+public class Today {
+ private final DayOfWeek startDayOfMonth = DayOfWeek.FRIDAY;
+ private final EventDatable eventDatable;
+ private final int INDEX_ALIGN = 1;
+ private final int WEEK_LENGTH = 7;
+ private DayOfWeek todayOfWeek;
+ private int todayDate;
+
+ enum DayOfWeek {
+ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
+ }
+
+ public Today(int inputDate, EventDatable eventDatable) {
+ this.eventDatable = eventDatable;
+ setDate(inputDate);
+ }
+
+ public void setDate(int inputDate) {
+ eventDatable.validateDecemberDate(inputDate);
+ this.todayDate = inputDate;
+ this.todayOfWeek = getDayOfWeek(inputDate, startDayOfMonth);
+ }
+
+ public int getChristmasEventToday() {
+ if (eventDatable.isChristmasEventDay(todayDate)) {
+ return (todayDate * 100) + 900;
+ }
+ return 0;
+ }
+
+ public boolean isWeekend() {
+ return todayOfWeek == DayOfWeek.FRIDAY || todayOfWeek == DayOfWeek.SATURDAY;
+ }
+
+ public boolean isSpecialDay() {
+ return todayOfWeek == DayOfWeek.SUNDAY || eventDatable.isChristmasDDay(todayDate);
+ }
+
+ private DayOfWeek getDayOfWeek(int inputDate, DayOfWeek startDate) {
+ int startDayIndex = startDate.ordinal();
+ int dayOfWeekIndex = (startDayIndex + inputDate - INDEX_ALIGN) % WEEK_LENGTH;
+ return DayOfWeek.values()[dayOfWeekIndex];
+ }
+} | Java | setter๋ ์ง์ํด์ฃผ์ธ์. ๋ด๋ถ์ ์ผ๋ก๋ง ์ฌ์ฉ๋๊ณ ์๋ค๋ฉด, private๋ก ์ค์ ํด์ฃผ์ธ์. |
@@ -0,0 +1,30 @@
+package christmas.domain.dao;
+
+import christmas.domain.Menu;
+import christmas.domain.parser.OrderParsable;
+import christmas.domain.parser.OrderParser;
+
+import java.util.Map;
+import java.util.Collections;
+
+public class OrderDAO {
+ private final OrderParsable orderParsable;
+ private static final OrderDAO ORDER_DAO = new OrderDAO();
+ private static Map<Menu, Integer> orderDetail;
+
+ private OrderDAO() {
+ this.orderParsable = new OrderParser();
+ }
+
+ public static OrderDAO getInstance() {
+ return ORDER_DAO;
+ }
+
+ public Map<Menu, Integer> getOrder() {
+ return Collections.unmodifiableMap(orderDetail);
+ }
+
+ public void addOrderDetail(String inputOrder) {
+ orderDetail = orderParsable.getOrderDetail(inputOrder);
+ }
+} | Java | ๋ฒ๊ทธ๊ฐ ์ผ์ด๋๊ธฐ ์ ๋ง ์ฌ์ด ์ค๊ณ์์. private static ๋ณ์๋ฅผ ์กฐ์ํ๋ add ๋ฉ์๋๊ฐ ์กด์ฌํ๊ณ ์๊ณ , getOrder์์ ์ด๊ธฐํ๋์ง๋ ์์์.
static์ ๋ชจ๋ ์์ ๊ณ ํด๋น ํด๋์ค๋ฅผ ์ธ์คํด์ค๋ก ์์ฑํด์ ํ์ฉํ์ธ์. |
@@ -0,0 +1,51 @@
+package christmas.domain.parser;
+
+import christmas.domain.Menu;
+import christmas.domain.validator.OrderValidator;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class OrderParser implements OrderParsable {
+ private final OrderValidator orderValidator;
+
+ public OrderParser() {
+ this.orderValidator = new OrderValidator();
+ }
+
+ @Override
+ public Map<Menu, Integer> getOrderDetail(String inputOrder) {
+ Map<Menu, Integer> orderDetail = convertOrderMenu(inputOrder);
+ orderValidator.validateOnlyDrink(Menu.isAllDrinks(orderDetail), orderDetail);
+ return orderDetail;
+ }
+
+ private Map<Menu, Integer> convertOrderMenu(String inputOrder) {
+ return decodeOrderMenu(inputOrder).entrySet().stream()
+ .collect(Collectors.toMap(
+ entry -> Menu.matchingMenu(entry.getKey()),
+ Map.Entry::getValue
+ ));
+ }
+
+ private Map<String, Integer> decodeOrderMenu(String inputOrder) {
+ String[] orderParts = inputOrder.split(",");
+ return parseInputOrder(orderParts);
+ }
+
+ private Map<String, Integer> parseInputOrder(String[] orderParts) {
+ Map<String, Integer> splitOrderMenu = new HashMap<>();
+
+ for (String orderPart : orderParts) {
+ String[] part = orderPart.split("-");
+ orderValidator.validateParse(part);
+ splitOrderMenu.put(part[0].trim(), Integer.parseInt(part[1].trim()));
+ }
+
+ orderValidator.validateOrderAmount(splitOrderMenu);
+
+ return splitOrderMenu;
+ }
+}
+ | Java | validateOnlyDrink์ ๋ํ ๋ก์ง์ด ๋
ธ์ถ๋์ด ์์ด์. ๊ฒ์ฌ๋ validator ๋ด๋ถ์์ ์งํํด์ฃผ์ธ์,
```suggestion
@Override
public Map<Menu, Integer> getOrderDetail(String inputOrder) {
Map<Menu, Integer> orderDetail = convertOrderMenu(inputOrder);
orderValidator.validateOnlyDrink(orderDetail);
return orderDetail;
}
``` |
@@ -0,0 +1,22 @@
+package christmas.service;
+
+import christmas.domain.EventDate;
+
+public class EventDateService implements EventDatable {
+ @Override
+ public boolean isChristmasDDay(int todayDate) {
+ return todayDate == EventDate.CHRISTMAS_D_DAY_END.getDay();
+ }
+
+ @Override
+ public boolean isChristmasEventDay(int todayDate) {
+ return todayDate <= EventDate.CHRISTMAS_D_DAY_END.getDay();
+ }
+
+ @Override
+ public void validateDecemberDate(int inputDate) {
+ if (inputDate < EventDate.DECEMBER_DAY_START.getDay() || inputDate > EventDate.DECEMBER_DAY_END.getDay()) {
+ throw new IllegalArgumentException("[ERROR] ๋ ์ง๋ 1~31์ผ ๋ฒ์ ๋ด์์๋ง ์ ํจํฉ๋๋ค.");
+ }
+ }
+} | Java | Today์์ ์ธํฐํ์ด์ค๋ก ํด๋น ํด๋์ค๋ฅผ ๋ฐ์์ ๊ธฐ๋ฅ์ ํ์ฉํ๋๋ฐ, ๊ทธ๋ฅ Today ๋ด๋ถ์์ ๊ตฌํํด๋ ๋์ ๊ฒ ๊ฐ์์. |
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ <mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file | Unknown | ์ด ํ์ผ์ ๋ฒ์ ๊ด๋ฆฌ์ ๋ค์ด๊ฐ์ผ ํ๋ ์ด์ ๊ฐ ์์๊น์?
./idea ์ดํ ํด๋์ ๋ด์ฉ์ ๊ฐ๋ฐ์ ๊ฐ์ธ์ ์ค์ ์ด ๋ค์ด๊ฐ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์๋ฐ ํ ๋ด์์ ๋
ผ์๋ ๊ฒฝ์ฐ๋ง ๋ฑ๋ก ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -1,8 +1,13 @@
apply plugin: 'com.android.application'
-
apply plugin: 'kotlin-android'
-
apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-kapt'
+apply plugin: 'com.google.gms.google-services'
+apply plugin: 'io.fabric'
+
+def keystorePropertiesFile = rootProject.file("keystore.properties")
+def keystoreProperties = new Properties()
+keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 28
@@ -13,20 +18,57 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ multiDexEnabled true
}
buildTypes {
+ debug {
+ // FIXME debug/release์ ๋ฐ๋ผ์ base url, key ๋ฑ์ด ๋ฐ๋ก ์ฐ์ด๋๋ก ์ค์ ํด์ฃผ์ธ์. ๊ฐ๋ฐํ๊ฒฝ๊ณผ ๋ฐฐํฌํ๊ฒฝ์์ ์ฐ์ด๋ ๊ฐ๋ค์ด ๋ถ๋ฆฌ๋์ด์ผ ํฉ๋๋ค.
+ buildConfigField "String", "BaseServerURL", keystoreProperties.getProperty("baseServerUrl")
+ buildConfigField "String", "TmapApiKey", keystoreProperties.getProperty("tMapApiKey")
+ buildConfigField "String", "GoogleApiKey", keystoreProperties.getProperty("googleApiKey")
+ buildConfigField "String", "BaseGoogleUrl", keystoreProperties.getProperty("baseGoogleUrl")
+ buildConfigField "String", "NaverClientId", keystoreProperties.getProperty("naverClientId")
+ buildConfigField "String", "KakaoLocalUrl", keystoreProperties.getProperty("kakaoLocalUrl")
+ buildConfigField "String", "KakaoServiceKey", keystoreProperties.getProperty("kakaoServiceKey")
+ buildConfigField "String", "GooglePlacesApiKey", keystoreProperties.getProperty("googlePlacesApiKey")
+ buildConfigField "boolean", "isDebug", "true"
+ }
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ buildConfigField "String", "BaseServerURL", keystoreProperties.getProperty("baseServerUrl")
+ buildConfigField "String", "TmapApiKey", keystoreProperties.getProperty("tMapApiKey")
+ buildConfigField "String", "GoogleApiKey", keystoreProperties.getProperty("googleApiKey")
+ buildConfigField "String", "BaseGoogleUrl", keystoreProperties.getProperty("baseGoogleUrl")
+ buildConfigField "String", "NaverClientId", keystoreProperties.getProperty("naverClientId")
+ buildConfigField "String", "KakaoLocalUrl", keystoreProperties.getProperty("kakaoLocalUrl")
+ buildConfigField "String", "KakaoServiceKey", keystoreProperties.getProperty("kakaoServiceKey")
+ buildConfigField "String", "GooglePlacesApiKey", keystoreProperties.getProperty("googlePlacesApiKey")
+ buildConfigField "boolean", "isDebug", "false"
}
}
+ dataBinding {
+ enabled = true
+ }
+ androidExtensions {
+ experimental = true
+ }
+
+ configurations {
+ all*.exclude group: 'com.google.guava', module: 'listenablefuture'
+ }
+ packagingOptions {
+ exclude 'META-INF/proguard/androidx-annotations.pro'
+ }
+ sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
+
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
@@ -37,21 +79,74 @@ dependencies {
//ktx
implementation "androidx.core:core-ktx:$ktx_version"
+ //chrome custom tabs
+ implementation "androidx.browser:browser:$browser_version"
+
//retrofit
- implementation "com.squareup.retrofit2:retrofit:2.4.0"
- implementation "com.squareup.retrofit2:converter-gson:2.4.0"
- implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
+ implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
+ implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
+ implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
- //dagger
- implementation "com.google.dagger:dagger:$dagger_version"
- annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
- //dagger android
- implementation "com.google.dagger:dagger-android:$dagger_version"
- implementation "com.google.dagger:dagger-android-support:$dagger_version"
- annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
+ //okhttp3
+ implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3_version"
- //
- kapt "com.android.databinding:compiler:$compiler_version"
+ //koin
+ implementation "org.koin:koin-android:$koin_version"
+ implementation "org.koin:koin-androidx-viewmodel:$koin_version"
+ //glide
+ implementation "com.github.bumptech.glide:glide:$glide_version"
+ kapt "com.github.bumptech.glide:compiler:$glide_version"
-}
+ //design
+ implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
+
+ //firebase
+ implementation "com.google.firebase:firebase-database:$firebase_version"
+
+ //firebase Auth
+ implementation "com.google.firebase:firebase-auth:$firebase_auth_version"
+ implementation "com.google.android.gms:play-services-auth:$play_services_auth_version"
+
+ //rxjava
+ implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
+ implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
+
+ //firebase core
+ implementation "com.google.firebase:firebase-core:$firebase_version"
+
+ //crashlytics
+ implementation "com.crashlytics.sdk.android:crashlytics:$crashlytics_version"
+
+ //MPchart
+ implementation "com.github.PhilJay:MPAndroidChart:$mpchart_version"
+
+ //stetho
+ implementation "com.facebook.stetho:stetho:$stetho_version"
+ implementation "com.facebook.stetho:stetho-js-rhino:$stetho_version"
+
+ //Naver Map
+ implementation "com.naver.maps:map-sdk:$naver_map_version"
+
+ //ted permission
+ implementation "gun0912.ted:tedpermission-rx2:$tedpermission_version"
+
+ //naver ์์น ๊ตฌํ์ ํ๊ธฐ ์ํ library
+ implementation "androidx.multidex:multidex:$multidex_version"
+
+ //room
+ implementation "android.arch.persistence.room:runtime:$room_version"
+ kapt "android.arch.persistence.room:compiler:$room_version"
+ kaptTest "android.arch.persistence.room:testing:$room_version"
+ implementation "android.arch.persistence.room:rxjava2:$room_version"
+
+ //lottie
+ implementation "com.airbnb.android:lottie:$lottie_version"
+
+ //rxbinding
+ implementation "com.jakewharton.rxbinding3:rxbinding:$rx_binding_version"
+
+ implementation("com.google.android.libraries.places:places:1.0.0") {
+ exclude group: 'com.google.guava', module: 'listenablefuture'
+ }
+}
\ No newline at end of file | Unknown | ํ์ฌ ๊ตฌํ๋ ์ฌํญ์ด๋ฏ๋ก, ์ ๊ฑฐ๋์ด๋ ์ข์ ์ฃผ์์ผ๋ก ๋ณด์ด๋๋ฐ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
์ด๋ฐ ์ฃผ์์ ๊ฒฝ์ฐ, ๋ค์์ ๋ค๋ฅธ ๊ฐ๋ฐ์, ํน์ ๋ฏธ๋์ ๋ ๊ฐ ๋ณผ ๋ ํผ๋์ ์ฌ์ง๋ฅผ ์ค ์ ์์ต๋๋ค. |
@@ -1,21 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="kr.co.connect.boostcamp.livewhere">
-
+ xmlns:tools="http://schemas.android.com/tools" package="kr.co.connect.boostcamp.livewhere">
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
+ android:name=".LiveApplication"
+ android:allowBackup="false"
+ android:icon="@drawable/icon_logo"
+ android:roundIcon="@drawable/icon_logo"
android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
+
+ <uses-library android:name="org.apache.http.legacy"
+ android:required="false"/>
+
+ <meta-data
+ android:name="com.google.android.geo.API_KEY"
+ android:value="@string/key_street_view"/>
+ <activity android:name=".ui.main.SplashActivity"
+ android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+ <activity android:name=".ui.login.LoginActivity">
+
+ </activity>
+ <activity android:name=".ui.main.HomeActivity">
+ </activity>
+ <activity android:name=".ui.detail.DetailActivity"
+ android:windowSoftInputMode="adjustResize">
+
+ </activity>
+ <activity android:name=".ui.map.MapActivity"
+ android:screenOrientation="portrait">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW"/>
+
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <activity android:name=".ui.map.StreetMapActivity"
+ android:screenOrientation="portrait">
+ </activity>
+
</application>
</manifest>
\ No newline at end of file | Unknown | ํธํ์ฑ์ ์ํด ์ถ๊ฐํ ๋ผ์ธ์ผ๋ก ๋ณด์ด๋๋ฐ์, ์ค์ํ ๋ณ๊ฒฝ์ผ ๊ฒฝ์ฐ ๋ณ๋ ์ฃผ์์ผ๋ก ๋ถํ๋๋ฆฝ๋๋ค.
๋งํฌ๊ฐ์๊ฑธ ์ปค๋ฐ ๋ฉ์์ง๋ ์ฃผ์์ผ๋ก ๋ถ์ฌ์ฃผ์๋ฉด ๋์ค์ ์ฐพ๊ธฐ๋ ์ฌ์ธ๊ฑฐ์์! |
@@ -1,21 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="kr.co.connect.boostcamp.livewhere">
-
+ xmlns:tools="http://schemas.android.com/tools" package="kr.co.connect.boostcamp.livewhere">
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
+ android:name=".LiveApplication"
+ android:allowBackup="false"
+ android:icon="@drawable/icon_logo"
+ android:roundIcon="@drawable/icon_logo"
android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
+
+ <uses-library android:name="org.apache.http.legacy"
+ android:required="false"/>
+
+ <meta-data
+ android:name="com.google.android.geo.API_KEY"
+ android:value="@string/key_street_view"/>
+ <activity android:name=".ui.main.SplashActivity"
+ android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+ <activity android:name=".ui.login.LoginActivity">
+
+ </activity>
+ <activity android:name=".ui.main.HomeActivity">
+ </activity>
+ <activity android:name=".ui.detail.DetailActivity"
+ android:windowSoftInputMode="adjustResize">
+
+ </activity>
+ <activity android:name=".ui.map.MapActivity"
+ android:screenOrientation="portrait">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW"/>
+
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <activity android:name=".ui.map.StreetMapActivity"
+ android:screenOrientation="portrait">
+ </activity>
+
</application>
</manifest>
\ No newline at end of file | Unknown | ์กํฐ๋นํฐ ํ๊ทธ๋ค์ ์ฝ๋ ํฌ๋งท์ ํ๋ฒ ์ ๋ฆฌํด์ฃผ์ค ์ ์์๊น์? ์คํ๋์ค ๋จ์ถํค alt command L ์ ๋๋ฅด๋ฉด ํ๋ฒ์ ์ ๋ฆฌ๋ฉ๋๋ค.
๋ณ๊ฑฐ ์๋๊ฑฐ ๊ฐ์ง๋ง ๊ฐ๋
์ฑ์ด ๋์์ง๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค. ๋์ค์ ์ฝ๋๋ฅผ ๋ค์ ๋ณผ ๋ ์ข์์! |
@@ -0,0 +1 @@
+{"v":"5.1.1","fr":25,"ip":0,"op":49,"w":720,"h":600,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"top_01","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[360,300,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[{"i":[[1.375,1.125],[-0.283,-0.236],[7.75,6.75],[0,0],[0,0],[7.25,5.875],[0,0],[0,0],[14.875,-15.375],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[-1,-1],[0.125,-0.125]],"o":[[-1.368,-1.119],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.761,-2.237],[0,0],[0,0],[-8.103,8.376],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[2.015,2.016],[0,0]],"v":[[259.875,-15.5],[254.125,-21.625],[250.875,-24.25],[255.75,-20.125],[253.875,-21.688],[252.625,-22.375],[249.25,-25.125],[254,-21],[237.625,-2.25],[220.625,17],[224.625,19.875],[225.125,20.875],[225,20],[241,17],[258,-3],[255,-20.5],[251.25,-24],[255.25,-20],[252.5,-22.75]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":9,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":12,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":16,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":17,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":18,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":19,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":23,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":27,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":28,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[32.625,-23.042],[0,0],[0,0],[-6.75,-8.75],[0,0],[-9.042,5.333],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-28.361,22.372],[0,0],[0,0],[5.333,6.875],[0,0],[9.667,-8.75],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.333,-207.333],[-26.292,-211.458],[-202.5,-64.688],[-211.438,-53.229],[-207.833,-39.542],[-192.104,-21.25],[-176.458,-19.583],[0.917,-166.083],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":29,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[32.625,-23.042],[0,0],[0,0],[-6.75,-8.75],[0,0],[-9.042,5.333],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-28.361,22.372],[0,0],[0,0],[5.333,6.875],[0,0],[9.667,-8.75],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.333,-207.333],[-26.292,-211.458],[-202.5,-64.688],[-211.438,-53.229],[-207.833,-39.542],[-192.104,-21.25],[-176.458,-19.583],[0.917,-166.083],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[30.875,-15.125],[0,0],[0,0],[-7.25,-9.25],[0,0],[-5.125,-5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-18.084,13.117],[0,0],[0,0],[3,3.625],[0,0],[7,-5.25],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32,-209],[-20.875,-215.375],[-122.5,-132.062],[-115.312,-123.688],[-105.5,-110.625],[-99.313,-102.75],[-89.375,-92.75],[0.375,-166.75],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":30,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[30.875,-15.125],[0,0],[0,0],[-7.25,-9.25],[0,0],[-5.125,-5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-18.084,13.117],[0,0],[0,0],[3,3.625],[0,0],[7,-5.25],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32,-209],[-20.875,-215.375],[-122.5,-132.062],[-115.312,-123.688],[-105.5,-110.625],[-99.313,-102.75],[-89.375,-92.75],[0.375,-166.75],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[28,-22.167],[0,0],[0,0],[-7,-9.417],[0,0],[-6.417,-7.875],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-12.945,8.489],[0,0],[0,0],[4.5,6.583],[0,0],[5.458,-2.833],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.167,-208.167],[-25,-211.833],[-57.875,-186.375],[-50.792,-177.083],[-41.5,-164.708],[-33,-153.583],[-25.708,-144.75],[0.417,-167],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":31,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[28,-22.167],[0,0],[0,0],[-7,-9.417],[0,0],[-6.417,-7.875],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-12.945,8.489],[0,0],[0,0],[4.5,6.583],[0,0],[5.458,-2.833],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.167,-208.167],[-25,-211.833],[-57.875,-186.375],[-50.792,-177.083],[-41.5,-164.708],[-33,-153.583],[-25.708,-144.75],[0.417,-167],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[24.875,-7.958],[0,0],[0,0],[-8.25,-10.646],[0,0],[-8.146,-9.875],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-7.806,3.861],[0,0],[0,0],[6.25,7.854],[0,0],[4.729,4.375],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[24.833,-212.583],[-15.625,-218.792],[-31.188,-207.75],[-23.083,-198.354],[-11.75,-183.854],[-4.313,-175.542],[1.771,-167],[7.583,-161.25],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":32,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[24.875,-7.958],[0,0],[0,0],[-8.25,-10.646],[0,0],[-8.146,-9.875],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-7.806,3.861],[0,0],[0,0],[6.25,7.854],[0,0],[4.729,4.375],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[24.833,-212.583],[-15.625,-218.792],[-31.188,-207.75],[-23.083,-198.354],[-11.75,-183.854],[-4.313,-175.542],[1.771,-167],[7.583,-161.25],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[21.75,6.25],[0,0],[0,0],[0,-11],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-2.667,-0.767],[0,0],[0,0],[0,13.038],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[4.25,-221.25],[-1,-222.625],[-0.875,-206.625],[-0.5,-179.5],[1.375,-166],[14.25,-156.5],[14.75,-155.5],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":33,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[21.75,6.25],[0,0],[0,0],[0,-11],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-2.667,-0.767],[0,0],[0,0],[0,13.038],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[4.25,-221.25],[-1,-222.625],[-0.875,-206.625],[-0.5,-179.5],[1.375,-166],[14.25,-156.5],[14.75,-155.5],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[0,-10.762],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[0,2.75],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.25,-183],[105,-166.25],[105.25,-158],[105.25,-151.375],[104.875,-148.375],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":41,"s":[{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[0,-10.762],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[0,2.75],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.25,-183],[105,-166.25],[105.25,-158],[105.25,-151.375],[104.875,-148.375],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true}],"e":[{"i":[[6.5,-0.187],[0,0],[8,0],[0,0],[0,0],[2.5,0],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[2.125,3.375],[0.625,7.625]],"o":[[-4,0.313],[0,0],[-10.75,-0.375],[0,0],[0,0],[-1.625,0.125],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[0.125,-9.375],[0,0]],"v":[[166.5,-149.563],[140.25,-149.438],[129.125,-149.375],[117.625,-149.625],[114.062,-149.594],[108.25,-149.5],[104.875,-149.312],[104.875,-145.062],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.875,-79.875],[186.625,-149.375]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":42,"s":[{"i":[[6.5,-0.187],[0,0],[8,0],[0,0],[0,0],[2.5,0],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[2.125,3.375],[0.625,7.625]],"o":[[-4,0.313],[0,0],[-10.75,-0.375],[0,0],[0,0],[-1.625,0.125],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[0.125,-9.375],[0,0]],"v":[[166.5,-149.563],[140.25,-149.438],[129.125,-149.375],[117.625,-149.625],[114.062,-149.594],[108.25,-149.5],[104.875,-149.312],[104.875,-145.062],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.875,-79.875],[186.625,-149.375]],"c":true}],"e":[{"i":[[16.32,13.056],[0,0],[7.75,6.75],[0,0],[0,0],[2.25,2.375],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.088,7.065],[9.5,8]],"o":[[-5,-4],[0,0],[-5.438,-4.736],[0,0],[0,0],[-1.891,-1.996],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-8.406,-6.534],[0,0]],"v":[[154.5,-104.625],[141.75,-115.625],[125.25,-129.75],[118.5,-135.75],[114.875,-139.188],[110.25,-143.5],[105,-148.5],[104.875,-141.75],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[185.25,-80.25],[172.75,-90.25]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":43,"s":[{"i":[[16.32,13.056],[0,0],[7.75,6.75],[0,0],[0,0],[2.25,2.375],[0,0],[0,0],[0.5,-12.25],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.088,7.065],[9.5,8]],"o":[[-5,-4],[0,0],[-5.438,-4.736],[0,0],[0,0],[-1.891,-1.996],[0,0],[0,0],[-0.455,11.14],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-8.406,-6.534],[0,0]],"v":[[154.5,-104.625],[141.75,-115.625],[125.25,-129.75],[118.5,-135.75],[114.875,-139.188],[110.25,-143.5],[105,-148.5],[104.875,-141.75],[104.5,-88.75],[112.625,-73.75],[142.25,-49],[142.75,-48],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[185.25,-80.25],[172.75,-90.25]],"c":true}],"e":[{"i":[[15.596,12.569],[-0.047,-0.039],[7.75,6.75],[0,0],[0,0],[2.297,2.324],[0,0],[0,0],[11.438,-13.229],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.088,7.065],[7.938,6.646]],"o":[[-6.085,-4.956],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.034,-2.039],[0,0],[0,0],[-7.312,8.271],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-7.38,-5.737],[0,0]],"v":[[184.063,-79.688],[175.313,-87.417],[176.5,-86.438],[173.458,-89.354],[169.354,-92.938],[165.146,-96.75],[158.979,-102.458],[156.438,-101.229],[134.062,-75.021],[123.583,-64.458],[149.375,-42.958],[149.875,-41.958],[225,20],[241,17],[258,-3],[255,-20.5],[218.958,-51.083],[212.833,-56.5],[200.292,-66.875]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":44,"s":[{"i":[[15.596,12.569],[-0.047,-0.039],[7.75,6.75],[0,0],[0,0],[2.297,2.324],[0,0],[0,0],[11.438,-13.229],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.088,7.065],[7.938,6.646]],"o":[[-6.085,-4.956],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.034,-2.039],[0,0],[0,0],[-7.312,8.271],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-7.38,-5.737],[0,0]],"v":[[184.063,-79.688],[175.313,-87.417],[176.5,-86.438],[173.458,-89.354],[169.354,-92.938],[165.146,-96.75],[158.979,-102.458],[156.438,-101.229],[134.062,-75.021],[123.583,-64.458],[149.375,-42.958],[149.875,-41.958],[225,20],[241,17],[258,-3],[255,-20.5],[218.958,-51.083],[212.833,-56.5],[200.292,-66.875]],"c":true}],"e":[{"i":[[14.872,12.081],[-0.094,-0.079],[7.75,6.75],[0,0],[0,0],[2.344,2.274],[0,0],[0,0],[15.875,-12.958],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.087,7.066],[6.375,5.292]],"o":[[-7.17,-5.912],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.178,-2.081],[0,0],[0,0],[-9.239,7.541],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-6.354,-4.94],[0,0]],"v":[[213.625,-54.75],[208.875,-59.208],[204.75,-62.125],[205.417,-61.958],[206.583,-60.188],[202.792,-63.5],[195.708,-69.917],[190.75,-74.208],[169.375,-56.792],[150.792,-41.417],[156.5,-36.917],[157,-35.917],[225,20],[241,17],[258,-3],[255,-20.5],[246.417,-27.667],[240.417,-32.75],[227.833,-43.5]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":45,"s":[{"i":[[14.872,12.081],[-0.094,-0.079],[7.75,6.75],[0,0],[0,0],[2.344,2.274],[0,0],[0,0],[15.875,-12.958],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[9.087,7.066],[6.375,5.292]],"o":[[-7.17,-5.912],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.178,-2.081],[0,0],[0,0],[-9.239,7.541],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-6.354,-4.94],[0,0]],"v":[[213.625,-54.75],[208.875,-59.208],[204.75,-62.125],[205.417,-61.958],[206.583,-60.188],[202.792,-63.5],[195.708,-69.917],[190.75,-74.208],[169.375,-56.792],[150.792,-41.417],[156.5,-36.917],[157,-35.917],[225,20],[241,17],[258,-3],[255,-20.5],[246.417,-27.667],[240.417,-32.75],[227.833,-43.5]],"c":true}],"e":[{"i":[[1.375,1.125],[-0.283,-0.236],[7.75,6.75],[0,0],[0,0],[2.532,2.072],[0,0],[0,0],[14.875,-15.375],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[-1,-1],[0.125,-0.125]],"o":[[-1.368,-1.119],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.75,-2.25],[0,0],[0,0],[-8.103,8.376],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[2.015,2.016],[0,0]],"v":[[256.875,-18.375],[254.125,-21.625],[250.875,-24.25],[247.875,-26.875],[246,-28.438],[244.75,-29.125],[241.375,-31.875],[246.125,-27.75],[228.875,-8.875],[211.375,9.75],[218,15],[218.5,16],[225,20],[241,17],[258,-3],[255,-20.5],[251.25,-24],[255.25,-20],[252.5,-22.75]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":46,"s":[{"i":[[1.375,1.125],[-0.283,-0.236],[7.75,6.75],[0,0],[0,0],[2.532,2.072],[0,0],[0,0],[14.875,-15.375],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[-1,-1],[0.125,-0.125]],"o":[[-1.368,-1.119],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.75,-2.25],[0,0],[0,0],[-8.103,8.376],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[2.015,2.016],[0,0]],"v":[[256.875,-18.375],[254.125,-21.625],[250.875,-24.25],[247.875,-26.875],[246,-28.438],[244.75,-29.125],[241.375,-31.875],[246.125,-27.75],[228.875,-8.875],[211.375,9.75],[218,15],[218.5,16],[225,20],[241,17],[258,-3],[255,-20.5],[251.25,-24],[255.25,-20],[252.5,-22.75]],"c":true}],"e":[{"i":[[1.375,1.125],[-0.283,-0.236],[7.75,6.75],[0,0],[0,0],[7.25,5.875],[0,0],[0,0],[14.875,-15.375],[0,0],[-11.632,-9.795],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[-1,-1],[0.125,-0.125]],"o":[[-1.368,-1.119],[0,0],[-5.438,-4.736],[0,0],[0,0],[-2.761,-2.237],[0,0],[0,0],[-8.103,8.376],[0,0],[2.375,2],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[2.015,2.016],[0,0]],"v":[[259.875,-15.5],[254.125,-21.625],[250.875,-24.25],[255.75,-20.125],[253.875,-21.688],[252.625,-22.375],[249.25,-25.125],[254,-21],[237.625,-2.25],[220.625,17],[224.625,19.875],[225.125,20.875],[225,20],[241,17],[258,-3],[255,-20.5],[251.25,-24],[255.25,-20],[252.5,-22.75]],"c":true}]},{"t":47}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.518,0.651,0.957,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[100],"e":[0]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":1,"s":[0],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":8,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":9,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":12,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":16,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":17,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":18,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":19,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":23,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":27,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":28,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":47,"s":[100],"e":[0]},{"t":48}],"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 2","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":49,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Shape Layer 4","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[360,300,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[59.5,-54.5],[0,-17.5],[0,0],[-7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.617,-10.494],[-7.645,-0.159],[-19,0.25],[0,0],[0,13],[0,0],[8,8]],"o":[[0,0],[-1,82],[0.5,14.75],[0,0],[7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0.5,8.5],[12,0.25],[19.005,-0.25],[0,0],[0,-13],[0,0],[-8,-8]],"v":[[-8,-132],[-185.5,17.5],[-186.5,208],[-167,225],[18,225.5],[27,219.5],[27,93.5],[27.25,69.5],[111,69.5],[111.25,93],[111.25,118],[111,187.5],[111.5,219],[132,225.5],[168,225],[187,206],[187.5,28],[187,18],[9,-131.5]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.988,0.906,0.58,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":60,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":49,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Shape Layer 3","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[360,300,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[{"i":[[0,0],[85.5,12.5],[0,-17.5],[0,0],[-7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.617,-10.494],[-7.645,-0.159],[-19,0.25],[0,0],[0,13],[0,0],[8,8]],"o":[[0,0],[0.5,3.5],[0.5,14.75],[0,0],[7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0.5,8.5],[12,0.25],[19.005,-0.25],[0,0],[0,-13],[0,0],[-8,-8]],"v":[[84,219],[-185.5,223.5],[-186.5,224],[-167,225],[18,225.5],[27,219.5],[27,93.5],[27.25,225.5],[111,225.5],[111.25,249],[111.25,274],[111,222.5],[111.5,219],[132,225.5],[168,225],[177,224],[177.5,218],[177,224],[101,219.5]],"c":true}],"e":[{"i":[[0,0],[59.5,-54.5],[0,-17.5],[0,0],[-7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[-0.617,-10.494],[-7.645,-0.159],[-19,0.25],[0,0],[0,13],[0,0],[8,8]],"o":[[0,0],[-1,82],[0.5,14.75],[0,0],[7,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0.5,8.5],[12,0.25],[19.005,-0.25],[0,0],[0,-13],[0,0],[-8,-8]],"v":[[-8,-132],[-185.5,17.5],[-186.5,208],[-167,225],[18,225.5],[27,219.5],[27,93.5],[27.25,69.5],[111,69.5],[111.25,93],[111.25,118],[111,187.5],[111.5,219],[132,225.5],[168,225],[187,206],[187.5,28],[187,18],[9,-131.5]],"c":true}]},{"t":35}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.988,0.737,0.075,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[0],"e":[100]},{"t":38}],"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 1","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":49,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"top_02","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[360,300,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[18,0],[0,0],[0,-9],[0,0],[0,0],[33.5,-27],[0,0],[0,0],[-6.5,-8.5],[0,0],[-11,10.5],[0,0],[0,0],[-5,6],[0,0],[11,10],[0,0],[0.5,11.5],[0,0]],"o":[[-18,0],[0,0],[0,9],[0,0],[0,0],[-33.5,27],[0,0],[0,0],[6.5,8.5],[0,0],[11,-10.5],[0,0],[0,0],[5,-6],[0,0],[-11,-10],[0,0],[-0.5,-11.5],[0,0]],"v":[[171.5,-221],[114,-221],[105.5,-210],[105.5,-144.5],[32.5,-206.5],[-29,-209.5],[-242.5,-31],[-259.5,-18],[-259,-4],[-238.5,19.5],[-220,17],[1,-165],[225,20],[241,17],[258,-3],[255,-20.5],[191.5,-74.5],[186.5,-90],[187,-208.5]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.584,0.8,1,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":80,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Shape 2","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":49,"st":0,"bm":0}],"markers":[]}
\ No newline at end of file | Unknown | ๋ฆฌ์์ค ํ์ผ ์ด๋ฆ์ ๊ฒฝ์ฐ 1, 2 ๋ณด๋ค๋ homeLoading, smallLoading ๋ฑ์ ์๋ฏธ๊ฐ ์๋ ๊ฐ์ ์ฃผ๋๊ฒ๋ ์ข์ต๋๋ค!
์ ๋ค๋ง ๋ค๋ฅธ ํ๋ค๊ณผ์ ์ปค๋ฎค๋์ผ์ด์
์ด ๋ฒํธ๋ก ๊ฐ๊ณ ์๋ค๋ฉด ํํ ์ ์ง ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,45 @@
+package kr.co.connect.boostcamp.livewhere
+
+import android.content.Context
+import androidx.multidex.MultiDex
+import androidx.multidex.MultiDexApplication
+import com.bumptech.glide.Glide
+import com.crashlytics.android.Crashlytics
+import com.facebook.stetho.Stetho
+import com.naver.maps.map.NaverMapSdk
+import io.fabric.sdk.android.Fabric
+import kr.co.connect.boostcamp.livewhere.di.appModules
+import org.koin.android.ext.android.startKoin
+
+
+// FIXME MultiDex ์ด์๊ฐ ๋ฐ์ํ ์ฌ์ง๊ฐ ์ถฉ๋ถํ๊ธฐ๋๋ฌธ์ gradle๊ณผ Applicationํด๋์ค์์ Multidex ํ๊ฒฝ์ ๊ตฌ์ฑํด์ฃผ์ธ์
+class LiveApplication : MultiDexApplication() {
+ override fun onCreate() {
+ super.onCreate()
+ //debug๋ณ์๋ฅผ ๋๊ณ debug ์ธ์ง ์บ์นํจ.
+ if (BuildConfig.isDebug) {
+ Stetho.initializeWithDefaults(this)
+ }
+ startKoin(this, appModules)
+ //Firebase Crashlytics
+ Fabric.with(this, Crashlytics())
+ NaverMapSdk.getInstance(this).client = NaverMapSdk.NaverCloudPlatformClient(BuildConfig.NaverClientId)
+ }
+
+ //application class์์ MultiDex ์ฌ์ฉ
+ override fun attachBaseContext(base: Context?) {
+ super.attachBaseContext(base)
+ MultiDex.install(this)
+ }
+
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ Glide.get(this).clearMemory()
+ }
+
+ override fun onTrimMemory(level: Int) {
+ super.onTrimMemory(level)
+ Glide.get(this).trimMemory(level)
+ }
+}
\ No newline at end of file | Kotlin | ์ด ์ฃผ์์ ์๋ ์ฝ๋์์ ์ถฉ๋ถํ ์ค๋ช
๋๋ฏ๋ก, ์ญ์ ์ ์๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,40 @@
+package kr.co.connect.boostcamp.livewhere.api
+
+import io.reactivex.Single
+import kr.co.connect.boostcamp.livewhere.model.HouseResponse
+import kr.co.connect.boostcamp.livewhere.model.PlaceResponse
+import retrofit2.Response
+import retrofit2.http.GET
+import retrofit2.http.POST
+import retrofit2.http.Query
+
+interface Api {
+ @GET("house/search/info")
+ fun getHouseDetail(
+ @Query("address") address: String
+ ): Single<Response<List<Any>>>
+
+ @GET("house/search/infos")
+ fun getDetail(
+ @Query("address") address: String
+ ): Single<Response<HouseResponse>>
+
+ @GET("place/search/infos")
+ fun getPlace(
+ @Query("lat") lat: String,
+ @Query("lng") lng: String,
+ @Query("radius") radius: String,
+ @Query("category") category: String
+ ): Single<Response<PlaceResponse>>
+
+ @GET("house/search/find/infos")
+ fun getDetailWithAddress(
+ @Query("address") address: String
+ ): Single<Response<HouseResponse>>
+
+ @POST("")
+ fun postReview(
+ @Query("nickname") nickname: String, @Query("id") id: String, @Query("contents") contents: String
+ ): Single<Response<Any>>
+
+}
\ No newline at end of file | Kotlin | review๋ฅผ ์ถ๊ฐํ๋ api๋ ์๋ํฌ์ธํธ url ์ด base์ ๊ฐ๋์?
์๋ชป ์์ฑ๋ ๊ฒ์ ์๋์ง ํ์ธ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,20 @@
+package kr.co.connect.boostcamp.livewhere.api
+
+import io.reactivex.Observable
+import kr.co.connect.boostcamp.livewhere.BuildConfig
+import kr.co.connect.boostcamp.livewhere.model.TmapResponse
+import retrofit2.Response
+import retrofit2.http.GET
+import retrofit2.http.Query
+
+interface TmapApi {
+ @GET("tmap/pois")
+ fun getAddress(
+ @Query("searchKeyword") searchKeyword: String,
+ @Query("appKey") appKey: String = BuildConfig.TmapApiKey,
+ @Query("count") count: String = "10",
+ @Query("areaLLCode") code: String = "11"
+ ): Observable<Response<TmapResponse>>
+
+
+}
\ No newline at end of file | Kotlin | * ๋ค๋ฅธ api ์ฒ๋ผ, ์ด api์ ๋ฆฌํด ๊ฐ๋ single ํ์
์ด ์ข์๋ณด์
๋๋ค. (์ผํ์ฑ ์์ฒญ์ด๋ฏ๋ก)
ํน์ Observable์ด์ด์ผ ํ๋ ์ด์๊ฐ ์์๊น์?
* count, areaLLCode์ ๋ํ ์ค๋ช
์ด ์ถ๊ฐ๋๋ฉด ๋์ค์ ์ ์ง๋ณด์ํ๊ธฐ ํธํ ๋ฏ ํฉ๋๋ค. ๊ฐ์ ๋ํ ์์๋ ์์ ๋ฆฌ์คํธ๋ฅผ ๋ณผ ์ ์๋ ๋งํฌ๋ฅผ ์ฒจ๋ถ ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,38 @@
+package kr.co.connect.boostcamp.livewhere.data
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.core.content.edit
+import kotlin.properties.ReadWriteProperty
+import kotlin.reflect.KProperty
+
+interface SharedPreference {
+ var uuid: String?
+}
+
+class SharedPreferenceStorage(context: Context) : SharedPreference {
+ private val prefs = context.applicationContext.getSharedPreferences(PREF, Context.MODE_PRIVATE)
+
+ override var uuid: String? by UuidPreference(prefs, PREF_UUID, null)
+
+ companion object {
+ const val PREF = "pref"
+ const val PREF_UUID = "pref_uuid"
+ }
+}
+
+class UuidPreference(
+ private val pref: SharedPreferences,
+ private val name: String,
+ private val defaultValue: String?
+) : ReadWriteProperty<Any, String?> {
+
+
+ override fun getValue(thisRef: Any, property: KProperty<*>): String? {
+ return pref.getString(name, defaultValue)
+ }
+
+ override fun setValue(thisRef: Any, property: KProperty<*>, value: String?) {
+ pref.edit { putString(name, value) }
+ }
+}
\ No newline at end of file | Kotlin | kotlin ์์๋ String ์ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฒ๋ฆฌํ๋ฉด ์ฌ์ฉํ๋ ์ชฝ์์ ์ข ๋ ํธํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
preference์ฒ๋ผ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ์ nullable๋ก ์ ์ธํ๋ฉด, safe call์ด ๊ณผ๋ํด์ง๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๋ฌผ๋ก ๋น ๋ฌธ์์ด์ ๋ํ ์ฒ๋ฆฌ๋ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,38 @@
+package kr.co.connect.boostcamp.livewhere.data
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.core.content.edit
+import kotlin.properties.ReadWriteProperty
+import kotlin.reflect.KProperty
+
+interface SharedPreference {
+ var uuid: String?
+}
+
+class SharedPreferenceStorage(context: Context) : SharedPreference {
+ private val prefs = context.applicationContext.getSharedPreferences(PREF, Context.MODE_PRIVATE)
+
+ override var uuid: String? by UuidPreference(prefs, PREF_UUID, null)
+
+ companion object {
+ const val PREF = "pref"
+ const val PREF_UUID = "pref_uuid"
+ }
+}
+
+class UuidPreference(
+ private val pref: SharedPreferences,
+ private val name: String,
+ private val defaultValue: String?
+) : ReadWriteProperty<Any, String?> {
+
+
+ override fun getValue(thisRef: Any, property: KProperty<*>): String? {
+ return pref.getString(name, defaultValue)
+ }
+
+ override fun setValue(thisRef: Any, property: KProperty<*>, value: String?) {
+ pref.edit { putString(name, value) }
+ }
+}
\ No newline at end of file | Kotlin | ์์ ๊ฐ์ ๋งฅ๋ฝ์ด์ง๋ง, default value๊ฐ non null ํ์
์ธ๊ฒ์ด ์ฌ์ฉํ๋ ์ชฝ์์ ๋ ๋ณด๊ธฐ ์ข์ ์ฝ๋๋ก ์์ฑ ๊ฐ๋ฅํฉ๋๋ค. |
@@ -0,0 +1,25 @@
+package kr.co.connect.boostcamp.livewhere.data.dao
+
+import androidx.room.Dao
+import androidx.room.Insert
+import androidx.room.OnConflictStrategy
+import androidx.room.Query
+import kr.co.connect.boostcamp.livewhere.data.entity.BookmarkEntity
+
+@Dao
+interface BookmarkDAO {
+ @Query("SELECT * FROM bookmark")
+ fun getAll(): List<BookmarkEntity>
+
+ @Insert(onConflict = OnConflictStrategy.IGNORE)
+ fun insertBookmark(bookmark: BookmarkEntity): Long
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ fun insertBookmarkAll(bookmark: List<BookmarkEntity>): List<Long>
+
+ @Query("DELETE from Bookmark")
+ fun deleteAll(): Int
+
+ @Query("DELETE from Bookmark WHERE address IN (:address)")
+ fun deleteBookmark(address: String): Int
+}
\ No newline at end of file | Kotlin | delete ์ฐ์ฐ์ ๋ํ ๋ฐํ๊ฐ์ ๊ผญ Int ์ฌ์ผ ํ๋์?
์ฐ๋ ์ชฝ์์๋ boolean ์ด๋ ์์ธ๊ฐ ๋ฐ์ํ๋๊ฒ ๋ช
ํํ๊ธฐ ๋๋ฌธ์, ํ๋ฒ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. (Room ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด์๋ผ๋ฉด ์ด์ฉ ์ ์์ง๋ง์ ใ
ใ
) |
@@ -0,0 +1,14 @@
+package kr.co.connect.boostcamp.livewhere.data.entity
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = "bookmark")
+data class BookmarkEntity(
+ @PrimaryKey var address: String,
+ @ColumnInfo(name = "building_name") var building_name: String,
+ @ColumnInfo(name = "image_url") var img_url: String,
+ @ColumnInfo(name = "longitude") var longitude: String,
+ @ColumnInfo(name = "latitude") var latitude: String
+)
\ No newline at end of file | Kotlin | * ๋ณดํต์ convention์ผ๋ก ๋ณ์๋ช
์ผ๋ก snake case (aaa_bb) ๋ ์ ์ฌ์ฉํ์ง ์์ต๋๋ค. img_url ๋ณด๋ค๋ imgUrl ๋ฑ์ด ์ข์๋ณด์
๋๋ค.
* ์ด ํด๋์ค์ ํ๋๋ค์ variable๋ณด๋ค๋, immutableํ ๊ฐ์ผ๋ก ์์ฑํด์ค๋ ๊ด์ฐฎ์๋ณด์
๋๋ค. (db์์ ์๋ ๊ฐ์ ๊ฐ์ ธ์ค๋ฏ๋ก)
entity ์ฒ๋ผ ๋ก์ง์ ์๋์ชฝ์ ์๋ ํด๋์ค์์ ํ๋๋ค์ด ํ์์ด์์ผ๋ก mutable(์ฌํ ๋น ๊ฐ๋ฅํ) ํ๋ฉด, ๋์ค์ ๊ฐ์ ๋ณํ๊ฒ ํ๋ ๋ก์ง์ด ์์ ๊ฒจ์ฐ ์ถ์ ์ด ๋งค์ฐ ์ด๋ ต์ต๋๋ค. ์ถ๊ฐ์ ์ธ ์ค๋ช
์ด ํ์ํ๋ค๋ฉด ๋ง์์ฃผ์ธ์. |
@@ -0,0 +1,14 @@
+package kr.co.connect.boostcamp.livewhere.data.entity
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = "bookmark")
+data class BookmarkEntity(
+ @PrimaryKey var address: String,
+ @ColumnInfo(name = "building_name") var building_name: String,
+ @ColumnInfo(name = "image_url") var img_url: String,
+ @ColumnInfo(name = "longitude") var longitude: String,
+ @ColumnInfo(name = "latitude") var latitude: String
+)
\ No newline at end of file | Kotlin | ๋ค๋ฅธ entity ํด๋์ค๋ค๋ ๊ทธ๋ฐ ๋ถ๋ถ์ด ๋ณด์ด๋๋ฐ ํ๊บผ๋ฒ์ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,50 @@
+package kr.co.connect.boostcamp.livewhere.di
+
+import io.reactivex.schedulers.Schedulers
+import kr.co.connect.boostcamp.livewhere.BuildConfig
+import kr.co.connect.boostcamp.livewhere.api.Api
+import kr.co.connect.boostcamp.livewhere.api.TmapApi
+import kr.co.connect.boostcamp.livewhere.util.TMAP_BASE_URL
+import okhttp3.OkHttpClient
+import okhttp3.logging.HttpLoggingInterceptor
+import org.koin.dsl.module.module
+import retrofit2.Retrofit
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
+import retrofit2.converter.gson.GsonConverterFactory
+import java.util.concurrent.TimeUnit
+
+val apiModule = module {
+ single("api") {
+ Retrofit.Builder()
+ .client(
+ OkHttpClient.Builder()
+ .connectTimeout(30, TimeUnit.SECONDS)
+ .readTimeout(30, TimeUnit.SECONDS)
+ .writeTimeout(30, TimeUnit.SECONDS)
+ .addInterceptor(HttpLoggingInterceptor())//http log ํ์ธ
+ .build()
+ )
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
+ .addConverterFactory(GsonConverterFactory.create())
+ .baseUrl(BuildConfig.BaseServerURL)
+ .build()
+ .create(Api::class.java)
+ }
+
+ single("tmapApi") {
+ Retrofit.Builder()
+ .client(
+ OkHttpClient.Builder()
+ .connectTimeout(30, TimeUnit.SECONDS)
+ .readTimeout(30, TimeUnit.SECONDS)
+ .writeTimeout(30, TimeUnit.SECONDS)
+ .addInterceptor(HttpLoggingInterceptor())
+ .build()
+ )
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
+ .addConverterFactory(GsonConverterFactory.create())
+ .baseUrl(TMAP_BASE_URL)
+ .build()
+ .create(TmapApi::class.java)
+ }
+}
\ No newline at end of file | Kotlin | ์ด๋ฐ ๊ฐ๋ค์ ์์๋ก ๋ถ๋ฆฌ ๊ฐ๋ฅํ ๊น์?
๋์ค์ ๋ค๋ฅธ ๊ฐ๋ฐ์๊ฐ ๋ณผ ๋ ์ ๋ถ ๊ฐ์ ์๋ฏธ์ ๊ฐ์ผ๋ก ์ทจ๊ธํ ์๋ ์๊ณ , ์ด์ ์์ด ๋ณ๊ฒฝํ ์๋ ์์ต๋๋ค.
* ์ 30์ด์ธ์ง ๊ฐ๋จํ ์ค๋ช
์ด ์ถ๊ฐ๋๋ฉด ์ข์ต๋๋ค. |
@@ -0,0 +1,13 @@
+package kr.co.connect.boostcamp.livewhere.di
+
+
+val appModules = arrayListOf(
+ apiModule
+ , loginModule
+ , sharedModule
+ , databaseModule
+ , homeModule
+ , mapModule
+ , reverseGeoApiModule
+ , detailModule
+) | Kotlin | ์ฝ๋ ํฌ๋งท ํ๋ฒ ๋ถํ๋๋ฆฝ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก
```
aaa,
bbb,
ccc,
```
์ด๋ ๊ฒ ๋ฆฌ์คํธ๋ฅผ ์์ฑํฉ๋๋ค. ์์ ๋ถ๋ถ์ด์ง๋ง ์ ์ฝ๋๋ฅผ ์ ๊น๋ณด๊ณ ์ง๋๊ฐ๋ค๋ฉด apiModule์ด ์ฝ๊ฐ ๋ฌ๋ผ๋ณด์ด๋ ๋จ์ ์ด ์์ต๋๋ค.
์ฝ๋ฉ ์ปจ๋ฒค์
๋งฅ๋ฝ์์ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,27 @@
+package kr.co.connect.boostcamp.livewhere.di
+
+import kr.co.connect.boostcamp.livewhere.repository.BookmarkRepositoryImpl
+import kr.co.connect.boostcamp.livewhere.repository.BookmarkUserRepository
+import kr.co.connect.boostcamp.livewhere.repository.ReviewRepository
+import kr.co.connect.boostcamp.livewhere.ui.detail.DetailViewModel
+import org.koin.androidx.viewmodel.ext.koin.viewModel
+import org.koin.dsl.module.module
+
+
+val detailModule = module {
+
+ factory("reviewRepository") { ReviewRepository() }
+ factory("bookmarkRemoteRepository") { BookmarkUserRepository() }
+ factory("bookmarkLocalRepository") { BookmarkRepositoryImpl(get("bookmarkDAO")) }
+
+ viewModel {
+ DetailViewModel(
+ get("reviewRepository"),
+ get("bookmarkRemoteRepository"),
+ get("bookmarkLocalRepository"),
+ get()
+ )
+ }
+}
+
+ | Kotlin | koin์ ๊ฒฝ์ฐ get() ๋ง ์์ฑํด๋ ๋ง๋ ํ์
์ ๋ฃ์ด์ค ํ
๋ฐ์,
์์ฒ๋ผ ์ด๋ฆ์ ๋ฃ์ ๊ฐ๋ค์ ์ถํ ์ฌ์ฉํ๋ ์ธ์คํด์ค๊ฐ ๋ฐ๋ ์ ์๊ธฐ ๋๋ฌธ์ธ๊ฐ์?
์ถ๊ฐ๋ก ๊ทธ๋ ๋ค๊ณ ํด๋, ๋ค๋ฅธ ์ธ์คํด์ค๊ฐ ์ถ๊ฐ ๋ ๋ ๋ณ๊ฒฝํด์ฃผ์ด๋ ๋ ๊ฑฐ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,16 @@
+package kr.co.connect.boostcamp.livewhere.di
+
+import kr.co.connect.boostcamp.livewhere.repository.AutoCompleteRepositoryImpl
+import kr.co.connect.boostcamp.livewhere.repository.BookmarkRepositoryImpl
+import kr.co.connect.boostcamp.livewhere.repository.RecentSearchRepositoryImpl
+import kr.co.connect.boostcamp.livewhere.ui.main.HomeViewModel
+import org.koin.androidx.viewmodel.ext.koin.viewModel
+import org.koin.dsl.module.module
+
+val homeModule = module {
+ factory("bookmarkRepository") { BookmarkRepositoryImpl(get("bookmarkDAO")) }
+ factory("recentSearchRepository") { RecentSearchRepositoryImpl(get("recentSearchDAO")) }
+ factory("autoCompleteRepository") { AutoCompleteRepositoryImpl(get("tmapApi")) }
+
+ viewModel { HomeViewModel(get("bookmarkRepository"), get("recentSearchRepository"), get("autoCompleteRepository")) }
+}
\ No newline at end of file | Kotlin | ์ ๋ฆฌ๋ทฐ์ ๊ฐ์ ๋งฅ๋ฝ์ผ๋ก ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,29 @@
+import { NUMBERS } from "./numbers.js";
+import ERROR from "./error.js";
+import { PROMPT } from "./prompt.js";
+
+const { zero, presentAmount } = NUMBERS;
+const { prefix } = ERROR;
+const {month, preview, champagne, piece, won, none} = PROMPT;
+
+const messageFormat = {
+ errorMessage: (message) => `${prefix} ${message}`,
+
+ preview: (date) => `${month}${date}${preview}`,
+
+ menu: (menuNames, quantities) => `${menuNames} ${quantities}${piece}`,
+
+ preDiscount: (totalprice) => `${totalprice.toLocaleString()}${won}`,
+
+ free: (totalprice) => (totalprice < presentAmount ? `${none}` : `${champagne}`),
+
+ benefit: (item) => item !== zero ? `${item.type}${item.amount.toLocaleString()}${won}` : `${none}`,
+
+ totalBenefit: (totalDiscountPrice) => `${totalDiscountPrice.toLocaleString()}${won}`,
+
+ discountedAmount: (total) => `${total.toLocaleString()}${won}`,
+
+ badge: (selectedBadge) => (selectedBadge !== undefined ? selectedBadge.badge : `${none}`),
+};
+
+export default messageFormat; | JavaScript | ์ถ๋ ฅ ๋ฉ์ธ์ง ํ์์ ๋ฐ๋ก ์ง์ ํด ์ฃผ๋ ๋ฐฉ๋ฒ๋ ์๊ตฐ์ ์ข์ ๋ฐฉ๋ฒ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค |
@@ -0,0 +1,119 @@
+import { DESSERT_MENU, MAIN_MENU } from "../constants/menu.js";
+import { DAY, DISCOUNT, NUMBERS } from "../constants/numbers.js";
+import { PROMPT } from "../constants/prompt.js";
+import OutputView from "../OutputView.js";
+import benefit from "./benefit.js";
+
+const { discount_price, special_discount, basis, day_discount, day_basis } = DISCOUNT;
+const { christmas, sunday } = DAY;
+const { year, month, zero, discount_start } = NUMBERS;
+const { benefit_detail } = PROMPT;
+
+/**
+ * ํ ์ธ์ ๊ด๋ จ๋ ๊ณ์ฐ์ ๋ด๋นํ๋ Discount ํด๋์ค
+ */
+class Discount {
+ /**
+ * ๋ฉ๋ด, ๋ ์ง, ์ด ๊ฐ๊ฒฉ์ ๋ฐ์ ํ ์ธ์ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๊ณ ๋ฐํํจ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ discountPrice(menu, date, totalPrice) {
+ const day = this.#getDayOfWeek(date);
+ const christmas = this.#ChristmasDday(date);
+ const week = day <= 5 ? this.#week(menu, DESSERT_MENU) : this.#week(menu, MAIN_MENU);
+ const special = this.#special(day, date);
+ const discounts = this.#eachDiscount(christmas, week, special, totalPrice, day);
+ const finalDiscount = discounts !== undefined ? discounts : [];
+
+ this.#discountOutput(finalDiscount);
+ return finalDiscount;
+ }
+
+ /**
+ * ๋ ์ง์ ๋ฐ๋ฅธ ์์ผ ๋ฐํ
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - 0๋ถํฐ 6๊น์ง ์ผ, ์, ํ, ์, ๋ชฉ, ๊ธ, ํ
+ */
+ #getDayOfWeek(date) {
+ const day = new Date(year, month, date);
+ return day.getDay();
+ }
+
+ /**
+ * ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ */
+ #ChristmasDday(date) {
+ if (date <= christmas) {
+ return (date - day_basis) * day_discount + basis;
+ }
+ return zero;
+ }
+
+ /**
+ * ํน์ ๋ฉ๋ด์ ๋ํ ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {Array} targetMenu - ํ ์ธ ๋์ ๋ฉ๋ด
+ * @returns {number} - ํ ์ธ ๊ธ์ก
+ */
+ #week(menu, targetMenu) {
+ const piece = menu.menuNames.reduce((acc, food, index) => {
+ if (targetMenu.includes(food)) {
+ acc += Number(menu.quantities[index]);
+ }
+ return acc;
+ }, 0);
+ return piece * discount_price;
+ }
+
+ /**
+ * ์ผ์์ผ ๋๋ ํฌ๋ฆฌ์ค๋ง์ค์ ์ถ๊ฐ์ ์ธ ํ ์ธ์ ๋ฐํํจ.
+ *
+ * @param {number} day - ์์ผ
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ์ถ๊ฐ์ ์ธ ํ ์ธ ๊ธ์ก
+ */
+ #special(day, date) {
+ return day === sunday || Number(date) === christmas
+ ? special_discount : zero;
+ }
+
+ /**
+ * ๊ฐ ํ ์ธ ํํ์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @param {number} christmas - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ * @param {number} week - ์ฃผ์ค ๋๋ ์ฃผ๋ง ํ ์ธ ๊ธ์ก
+ * @param {number} special - ํน๋ณ ํ ์ธ ๊ธ์ก
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @param {number} day - ์
๋ ฅํ ๋ ์ง์ ์์ผ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ #eachDiscount(christmas, week, special, totalPrice, day) {
+ if (totalPrice >= discount_start) {
+ return benefit(christmas, week, special, totalPrice, day);
+ }
+ }
+
+ /**
+ * ์ต์ข
ํ ์ธ ํํ ์ถ๋ ฅ
+ *
+ * @param {Array} finalDiscount - ์ต์ข
ํ ์ธ ํํ ๋ชฉ๋ก
+ * @returns {void}
+ */
+ #discountOutput(finalDiscount) {
+ OutputView.print(benefit_detail);
+ finalDiscount.length !== zero
+ ? finalDiscount.map((item) => OutputView.benefit(item)) : OutputView.benefit(zero);
+ }
+}
+export default Discount; | JavaScript | parameter๊ฐ ๋ง์ ๊ฒ์ ๊ถ์ฅํ์ง ์์๋ ๊ฒ์ผ๋ก ๊ธฐ์ตํด์, parameter์ ์ค์ผ ์ ์๋ ๋ฐฉ๋ฒ์ ์๊ฐํด ๋ด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,119 @@
+import { DESSERT_MENU, MAIN_MENU } from "../constants/menu.js";
+import { DAY, DISCOUNT, NUMBERS } from "../constants/numbers.js";
+import { PROMPT } from "../constants/prompt.js";
+import OutputView from "../OutputView.js";
+import benefit from "./benefit.js";
+
+const { discount_price, special_discount, basis, day_discount, day_basis } = DISCOUNT;
+const { christmas, sunday } = DAY;
+const { year, month, zero, discount_start } = NUMBERS;
+const { benefit_detail } = PROMPT;
+
+/**
+ * ํ ์ธ์ ๊ด๋ จ๋ ๊ณ์ฐ์ ๋ด๋นํ๋ Discount ํด๋์ค
+ */
+class Discount {
+ /**
+ * ๋ฉ๋ด, ๋ ์ง, ์ด ๊ฐ๊ฒฉ์ ๋ฐ์ ํ ์ธ์ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๊ณ ๋ฐํํจ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ discountPrice(menu, date, totalPrice) {
+ const day = this.#getDayOfWeek(date);
+ const christmas = this.#ChristmasDday(date);
+ const week = day <= 5 ? this.#week(menu, DESSERT_MENU) : this.#week(menu, MAIN_MENU);
+ const special = this.#special(day, date);
+ const discounts = this.#eachDiscount(christmas, week, special, totalPrice, day);
+ const finalDiscount = discounts !== undefined ? discounts : [];
+
+ this.#discountOutput(finalDiscount);
+ return finalDiscount;
+ }
+
+ /**
+ * ๋ ์ง์ ๋ฐ๋ฅธ ์์ผ ๋ฐํ
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - 0๋ถํฐ 6๊น์ง ์ผ, ์, ํ, ์, ๋ชฉ, ๊ธ, ํ
+ */
+ #getDayOfWeek(date) {
+ const day = new Date(year, month, date);
+ return day.getDay();
+ }
+
+ /**
+ * ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ */
+ #ChristmasDday(date) {
+ if (date <= christmas) {
+ return (date - day_basis) * day_discount + basis;
+ }
+ return zero;
+ }
+
+ /**
+ * ํน์ ๋ฉ๋ด์ ๋ํ ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {Array} targetMenu - ํ ์ธ ๋์ ๋ฉ๋ด
+ * @returns {number} - ํ ์ธ ๊ธ์ก
+ */
+ #week(menu, targetMenu) {
+ const piece = menu.menuNames.reduce((acc, food, index) => {
+ if (targetMenu.includes(food)) {
+ acc += Number(menu.quantities[index]);
+ }
+ return acc;
+ }, 0);
+ return piece * discount_price;
+ }
+
+ /**
+ * ์ผ์์ผ ๋๋ ํฌ๋ฆฌ์ค๋ง์ค์ ์ถ๊ฐ์ ์ธ ํ ์ธ์ ๋ฐํํจ.
+ *
+ * @param {number} day - ์์ผ
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ์ถ๊ฐ์ ์ธ ํ ์ธ ๊ธ์ก
+ */
+ #special(day, date) {
+ return day === sunday || Number(date) === christmas
+ ? special_discount : zero;
+ }
+
+ /**
+ * ๊ฐ ํ ์ธ ํํ์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @param {number} christmas - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ * @param {number} week - ์ฃผ์ค ๋๋ ์ฃผ๋ง ํ ์ธ ๊ธ์ก
+ * @param {number} special - ํน๋ณ ํ ์ธ ๊ธ์ก
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @param {number} day - ์
๋ ฅํ ๋ ์ง์ ์์ผ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ #eachDiscount(christmas, week, special, totalPrice, day) {
+ if (totalPrice >= discount_start) {
+ return benefit(christmas, week, special, totalPrice, day);
+ }
+ }
+
+ /**
+ * ์ต์ข
ํ ์ธ ํํ ์ถ๋ ฅ
+ *
+ * @param {Array} finalDiscount - ์ต์ข
ํ ์ธ ํํ ๋ชฉ๋ก
+ * @returns {void}
+ */
+ #discountOutput(finalDiscount) {
+ OutputView.print(benefit_detail);
+ finalDiscount.length !== zero
+ ? finalDiscount.map((item) => OutputView.benefit(item)) : OutputView.benefit(zero);
+ }
+}
+export default Discount; | JavaScript | 3ํญ ์ฐ์ฐ์๋ฅผ ๋ค์ํ ๊ณณ์ ์ผ๋ฌด์ง๊ฒ ์ฌ์ฉํ์๋ ๊ฒ ๊ฐ์์. ์ ๋ณด๊ณ ๋ฐฐ์๋๋ค ใ
ใ
|
@@ -0,0 +1,89 @@
+/**
+ * @fileoverview badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module badgeTest
+ */
+import { Console } from "@woowacourse/mission-utils";
+import badge from "../../src/domain/badge.js";
+
+/**
+ * Console ๋ชจ๋์์ print ๋ฉ์๋์ spyOn์ ์์ฑํ์ฌ ๋ฐํํ๋ ํจ์
+ * @returns {jest.SpyInstance} Console.print์ spyOn
+ */
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(Console, "print");
+ logSpy.mockClear();
+
+ return logSpy;
+};
+/**
+ * badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("badge ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let logSpy;
+ /**
+ * ๊ฐ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ logSpy๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeEach(() => {
+ logSpy = getLogSpy();
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 1: ํ ์ธ ๊ธ์ก์ด 0์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 0;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 2: ํ ์ธ ๊ธ์ก์ด 2๋ง์์ด ๋์ ๋ ์ฐํ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -20001;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์ฐํ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 3: ํ ์ธ ๊ธ์ก์ด 1๋ง์ ์ด์ 2๋ง์ ๋ฏธ๋ง์ผ ๋ ํธ๋ฆฌ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -19999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "ํธ๋ฆฌ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 4: ํ ์ธ ๊ธ์ก์ด 5์ฒ์ ์ด์ 1๋ง์ ๋ฏธ๋ง์ผ ๋ ๋ณ์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = -9999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "๋ณ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 5: ํ ์ธ ๊ธ์ก์ด 0์ ์ด์์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 1000;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+});
\ No newline at end of file | JavaScript | ๋จ์ํ
์คํธ๋ฅผ ํ๊ธฐ ์ฝ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ์
จ๋ค๋๊ฒ ๋ณด์ฌ์ง๋ ํ
์คํธ ์ฝ๋๋ค์.
์ ๊ฐ์ ๊ฒฝ์ฐ์ ์ด๋ฐ์์ ํ
์คํธ ์์ฑ์ด ๋ถ๊ฐ๋ฅํ์ด์ ๋ง์ด ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค~ |
@@ -0,0 +1,119 @@
+import { DESSERT_MENU, MAIN_MENU } from "../constants/menu.js";
+import { DAY, DISCOUNT, NUMBERS } from "../constants/numbers.js";
+import { PROMPT } from "../constants/prompt.js";
+import OutputView from "../OutputView.js";
+import benefit from "./benefit.js";
+
+const { discount_price, special_discount, basis, day_discount, day_basis } = DISCOUNT;
+const { christmas, sunday } = DAY;
+const { year, month, zero, discount_start } = NUMBERS;
+const { benefit_detail } = PROMPT;
+
+/**
+ * ํ ์ธ์ ๊ด๋ จ๋ ๊ณ์ฐ์ ๋ด๋นํ๋ Discount ํด๋์ค
+ */
+class Discount {
+ /**
+ * ๋ฉ๋ด, ๋ ์ง, ์ด ๊ฐ๊ฒฉ์ ๋ฐ์ ํ ์ธ์ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๊ณ ๋ฐํํจ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ discountPrice(menu, date, totalPrice) {
+ const day = this.#getDayOfWeek(date);
+ const christmas = this.#ChristmasDday(date);
+ const week = day <= 5 ? this.#week(menu, DESSERT_MENU) : this.#week(menu, MAIN_MENU);
+ const special = this.#special(day, date);
+ const discounts = this.#eachDiscount(christmas, week, special, totalPrice, day);
+ const finalDiscount = discounts !== undefined ? discounts : [];
+
+ this.#discountOutput(finalDiscount);
+ return finalDiscount;
+ }
+
+ /**
+ * ๋ ์ง์ ๋ฐ๋ฅธ ์์ผ ๋ฐํ
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - 0๋ถํฐ 6๊น์ง ์ผ, ์, ํ, ์, ๋ชฉ, ๊ธ, ํ
+ */
+ #getDayOfWeek(date) {
+ const day = new Date(year, month, date);
+ return day.getDay();
+ }
+
+ /**
+ * ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @private
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ */
+ #ChristmasDday(date) {
+ if (date <= christmas) {
+ return (date - day_basis) * day_discount + basis;
+ }
+ return zero;
+ }
+
+ /**
+ * ํน์ ๋ฉ๋ด์ ๋ํ ํ ์ธ ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๋ฐํ.
+ *
+ * @param {Object} menu - ์ฃผ๋ฌธํ ์์์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ๊ฐ์ฒด
+ * @param {Array} targetMenu - ํ ์ธ ๋์ ๋ฉ๋ด
+ * @returns {number} - ํ ์ธ ๊ธ์ก
+ */
+ #week(menu, targetMenu) {
+ const piece = menu.menuNames.reduce((acc, food, index) => {
+ if (targetMenu.includes(food)) {
+ acc += Number(menu.quantities[index]);
+ }
+ return acc;
+ }, 0);
+ return piece * discount_price;
+ }
+
+ /**
+ * ์ผ์์ผ ๋๋ ํฌ๋ฆฌ์ค๋ง์ค์ ์ถ๊ฐ์ ์ธ ํ ์ธ์ ๋ฐํํจ.
+ *
+ * @param {number} day - ์์ผ
+ * @param {string} date - ์
๋ ฅํ ๋ ์ง
+ * @returns {number} - ์ถ๊ฐ์ ์ธ ํ ์ธ ๊ธ์ก
+ */
+ #special(day, date) {
+ return day === sunday || Number(date) === christmas
+ ? special_discount : zero;
+ }
+
+ /**
+ * ๊ฐ ํ ์ธ ํํ์ ๊ณ์ฐํ์ฌ ๋ฐํํจ.
+ *
+ * @param {number} christmas - ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๊ธ์ก
+ * @param {number} week - ์ฃผ์ค ๋๋ ์ฃผ๋ง ํ ์ธ ๊ธ์ก
+ * @param {number} special - ํน๋ณ ํ ์ธ ๊ธ์ก
+ * @param {number} totalPrice - ์ด ์ฃผ๋ฌธ ๊ฐ๊ฒฉ
+ * @param {number} day - ์
๋ ฅํ ๋ ์ง์ ์์ผ
+ * @returns {Array} - ๊ณ์ฐ๋ ํ ์ธ ํํ ๋ชฉ๋ก
+ */
+ #eachDiscount(christmas, week, special, totalPrice, day) {
+ if (totalPrice >= discount_start) {
+ return benefit(christmas, week, special, totalPrice, day);
+ }
+ }
+
+ /**
+ * ์ต์ข
ํ ์ธ ํํ ์ถ๋ ฅ
+ *
+ * @param {Array} finalDiscount - ์ต์ข
ํ ์ธ ํํ ๋ชฉ๋ก
+ * @returns {void}
+ */
+ #discountOutput(finalDiscount) {
+ OutputView.print(benefit_detail);
+ finalDiscount.length !== zero
+ ? finalDiscount.map((item) => OutputView.benefit(item)) : OutputView.benefit(zero);
+ }
+}
+export default Discount; | JavaScript | ๊ณ ๋ฏผํ๊ณ ๊ณ ๋ฏผํ๋ค๊ฐ ์๊ฐ์ด ์์ด์... ์์... |
@@ -0,0 +1,143 @@
+/**
+ * @fileoverview ์ ์ฒด ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module AppTest
+ */
+import App from "../src/App.js";
+import { Console } from "@woowacourse/mission-utils";
+import { EOL as LINE_SEPARATOR } from "os";
+
+/**
+ * ์ฃผ์ด์ง ์
๋ ฅ๊ฐ์ผ๋ก Console.readLineAsync๋ฅผ ๋ชจํนํ๋ ํจ์
+ *
+ * @param {string[]} inputs - ๋ชจํนํ ์
๋ ฅ๊ฐ ๋ฐฐ์ด
+ * @return {void}
+ */
+const mockQuestions = (inputs) => {
+ Console.readLineAsync = jest.fn();
+
+ Console.readLineAsync.mockImplementation(() => {
+ const input = inputs.shift();
+
+ return Promise.resolve(input);
+ });
+};
+
+/**
+ * Console.print์ ๋ํ spy๋ฅผ ์ป๋ ํจ์
+ *
+ * @return {jest.SpyInstance<void, any>}
+ */
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(Console, "print");
+ logSpy.mockClear();
+
+ return logSpy;
+};
+
+/**
+ * logSpy๋ฅผ ์ด์ฉํ์ฌ ์ถ๋ ฅ๋ ๋ก๊ทธ๋ฅผ ๋ฌธ์์ด๋ก ๋ฐํํ๋ ํจ์
+ *
+ * @param {jest.SpyInstance<void, any>} logSpy - Console.print์ ๋ํ spy
+ * @return {string} ์ถ๋ ฅ๋ ๋ก๊ทธ ๋ฌธ์์ด
+ */
+const getOutput = (logSpy) => {
+ return [...logSpy.mock.calls].join(LINE_SEPARATOR);
+};
+
+/**
+ * ์ถ๋ ฅ๋ ๋ก๊ทธ๊ฐ ํน์ ๋ก๊ทธ๋ฅผ ํฌํจํ๋์ง ๊ฒ์ฆํ๋ ํจ์
+ *
+ * @param {string} received - ์ถ๋ ฅ๋ ๋ก๊ทธ ๋ฌธ์์ด
+ * @param {string[]} expectedLogs - ํฌํจ ์ฌ๋ถ๋ฅผ ๊ฒ์ฆํ ๋ก๊ทธ๋ค์ ๋ฐฐ์ด
+ * @return {void}
+ */
+const expectLogContains = (received, expectedLogs) => {
+ expectedLogs.forEach((log) => {
+ expect(received).toContain(log);
+ });
+};
+
+/**
+ * ์ ์ฒด ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("์ ์ฒด ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ test("์ ์ ์ถ๋ ฅ ํ
์คํธ", async () => {
+ //given
+ const logSpy = getLogSpy();
+ mockQuestions([
+ "23",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-1,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ ]);
+
+ //when
+ const app = new App();
+ await app.run();
+
+ //then
+ const expected = [
+ "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.",
+ "12์ 23์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!",
+ "<์ฃผ๋ฌธ ๋ฉ๋ด>",
+ "์์ก์ด์ํ 1๊ฐ",
+ "์์ ์๋ฌ๋ 1๊ฐ",
+ "ํํ์ค 1๊ฐ",
+ "ํฐ๋ณธ์คํ
์ดํฌ 2๊ฐ",
+ "ํฌ๋ฆฌ์ค๋ง์คํ์คํ 1๊ฐ",
+ "์์ด์คํฌ๋ฆผ 2๊ฐ",
+ "์ด์ฝ์ผ์ดํฌ 2๊ฐ",
+ "์ ๋ก์ฝ๋ผ 1๊ฐ",
+ "๋ ๋์์ธ 1๊ฐ",
+ "<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>",
+ "257,500์",
+ "<์ฆ์ ๋ฉ๋ด>",
+ "์ดํ์ธ 1๊ฐ",
+ "<ํํ ๋ด์ญ>",
+ "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,200์",
+ "์ฃผ๋ง ํ ์ธ: -6,069์",
+ "์ฆ์ ์ด๋ฒคํธ: -25,000์",
+ "<์ดํํ ๊ธ์ก>",
+ "-34,269์",
+ "<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>",
+ "248,231์",
+ "<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>",
+ "์ฐํ",
+ ];
+ expectLogContains(getOutput(logSpy), expected);
+ });
+ test("12๋ง์ ์ดํ์ ๊ธ์ก์ ์
๋ ฅํ ๊ฒฝ์ฐ", async () => {
+ //given
+ const logSpy = getLogSpy();
+ mockQuestions(["24", "ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-2"]);
+
+ //when
+ const app = new App();
+ await app.run();
+
+ //then
+ const expected = [
+ "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.",
+ "12์ 24์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!",
+ "<์ฃผ๋ฌธ ๋ฉ๋ด>",
+ "ํํ์ค 1๊ฐ",
+ "ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ",
+ "ํด์ฐ๋ฌผํ์คํ 1๊ฐ",
+ "์์ด์คํฌ๋ฆผ 2๊ฐ",
+ "์ ๋ก์ฝ๋ผ 2๊ฐ",
+ "<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>",
+ "111,500์",
+ "<์ฆ์ ๋ฉ๋ด>",
+ "์์",
+ "<ํํ ๋ด์ญ>",
+ "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,300์",
+ "ํ์ผ ํ ์ธ: -4,046์",
+ "ํน๋ณ ํ ์ธ: -1,000์",
+ "<์ดํํ ๊ธ์ก>",
+ "-8,346์",
+ "<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>",
+ "103,154์",
+ "<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>",
+ "๋ณ",
+ ];
+ expectLogContains(getOutput(logSpy), expected);
+ })
+}); | JavaScript | "ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ์์ ๋ฌ๋ฆฌ ๋ช
์ํ์ง ์๋ ํ ํ์ผ, ํจํค์ง ์ด๋ฆ์ ์์ ํ๊ฑฐ๋ ์ด๋ํ์ง ์๋๋ค." ๋ผ๊ณ ์ ํ์ ธ ์์ง๋ง AppTest๋ก ๋ฐ๋ก ๋ช
์ํด ๋์ผ์
จ๊ธธ๋ ์ฝ๋ฉํธ ๋จ๊ฒจ๋ด
๋๋ค..!! |
@@ -0,0 +1,89 @@
+/**
+ * @fileoverview badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module badgeTest
+ */
+import { Console } from "@woowacourse/mission-utils";
+import badge from "../../src/domain/badge.js";
+
+/**
+ * Console ๋ชจ๋์์ print ๋ฉ์๋์ spyOn์ ์์ฑํ์ฌ ๋ฐํํ๋ ํจ์
+ * @returns {jest.SpyInstance} Console.print์ spyOn
+ */
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(Console, "print");
+ logSpy.mockClear();
+
+ return logSpy;
+};
+/**
+ * badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("badge ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let logSpy;
+ /**
+ * ๊ฐ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ logSpy๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeEach(() => {
+ logSpy = getLogSpy();
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 1: ํ ์ธ ๊ธ์ก์ด 0์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 0;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 2: ํ ์ธ ๊ธ์ก์ด 2๋ง์์ด ๋์ ๋ ์ฐํ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -20001;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์ฐํ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 3: ํ ์ธ ๊ธ์ก์ด 1๋ง์ ์ด์ 2๋ง์ ๋ฏธ๋ง์ผ ๋ ํธ๋ฆฌ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -19999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "ํธ๋ฆฌ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 4: ํ ์ธ ๊ธ์ก์ด 5์ฒ์ ์ด์ 1๋ง์ ๋ฏธ๋ง์ผ ๋ ๋ณ์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = -9999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "๋ณ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 5: ํ ์ธ ๊ธ์ก์ด 0์ ์ด์์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 1000;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+});
\ No newline at end of file | JavaScript | ๋จ์ ํ
์คํธ ์์น์์ "๋ชจํน์ ํผํ ์ ์์ผ๋ฉด ์ต๋ํ ํผํ๋ ๊ฒ์ด ์ข๋ค."๊ณ ์ธ๊ธํ๊ณ ์๋๋ฐ์.
Console.print์ ์ถ๋ ฅ์ด ์ ๋๋์ง ํ์ธํ๋ ๊ฒ ๋ณด๋จ ๋๋ฉ์ธ์ '๋จ์ ํ
์คํธ'์ธ ๋งํผ Badge์์ ์์ํ๋ ์ด๋ฒคํธ ๋ฑ์ง๋ฅผ ์ ๋ฐํ ํ๋์ง ํ์ธํ๋ฉด ๋ ์ข์๊ฑฐ ๊ฐ์ ์ฝ๋ฉํธ ๋จ๊ฒจ๋ด
๋๋ค..!!
๋ํ, Badge์ UI ๋ก์ง์ด ๊ฒฐํฉ๋์๋๊ฑธ ์ดํด๋ณผ ์ ์์๋๋ฐ, 3์ฃผ์ฐจ ๊ณตํต ํผ๋๋ฐฑ์ ๋ช
์๋ UI ๋ก์ง๊ณผ ๋น์ฆ๋์ค ๋ก์ง ๋ถ๋ฆฌ๋ฅผ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค.
https://github.com/mawrkus/js-unit-testing-guide#-dont-mock-everything |
@@ -0,0 +1,89 @@
+/**
+ * @fileoverview badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module badgeTest
+ */
+import { Console } from "@woowacourse/mission-utils";
+import badge from "../../src/domain/badge.js";
+
+/**
+ * Console ๋ชจ๋์์ print ๋ฉ์๋์ spyOn์ ์์ฑํ์ฌ ๋ฐํํ๋ ํจ์
+ * @returns {jest.SpyInstance} Console.print์ spyOn
+ */
+const getLogSpy = () => {
+ const logSpy = jest.spyOn(Console, "print");
+ logSpy.mockClear();
+
+ return logSpy;
+};
+/**
+ * badge ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("badge ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let logSpy;
+ /**
+ * ๊ฐ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ logSpy๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeEach(() => {
+ logSpy = getLogSpy();
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 1: ํ ์ธ ๊ธ์ก์ด 0์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 0;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 2: ํ ์ธ ๊ธ์ก์ด 2๋ง์์ด ๋์ ๋ ์ฐํ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -20001;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์ฐํ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 3: ํ ์ธ ๊ธ์ก์ด 1๋ง์ ์ด์ 2๋ง์ ๋ฏธ๋ง์ผ ๋ ํธ๋ฆฌ๊ฐ ์ถ๋ ฅ๋์ด์ผ ํจ", () => {
+ // given
+ const totalDiscountPrice = -19999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "ํธ๋ฆฌ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 4: ํ ์ธ ๊ธ์ก์ด 5์ฒ์ ์ด์ 1๋ง์ ๋ฏธ๋ง์ผ ๋ ๋ณ์ด ์ถ๋ ฅ๋์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = -9999;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "๋ณ"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+
+ test("ํ
์คํธ ์ผ์ด์ค 5: ํ ์ธ ๊ธ์ก์ด 0์ ์ด์์ผ ๋ ์์์ด ์ถ๋ ฅ๋์ด์ด์ผ ํจ.", () => {
+ // given
+ const totalDiscountPrice = 1000;
+
+ // when
+ badge(totalDiscountPrice);
+
+ // then
+ const expected = "์์"
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining(expected));
+ });
+});
\ No newline at end of file | JavaScript | ํ
์คํธ ์ผ์ด์ค๊ฐ ๊น๋ํด์ ์ ์ฝํ๋ค์ ๐ |
@@ -0,0 +1,111 @@
+/**
+ * @fileoverview Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module DiscountTest
+ */
+import Discount from "../../src/domain/Discount.js";
+import orderMenu from "../../src/domain/orderMenu.js";
+import preDiscountAmount from "../../src/domain/preDiscountAmount";
+
+/**
+ * ์ฃผ์ด์ง ์์์ ๋ํ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ์ ๋ฐํํ๋ ํจ์
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @returns {{menu: Object, totalPrice: number}} ์ฃผ๋ฌธํ ์์์ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ
+ */
+const getMenuAndTotalPrice = (food) => {
+ const menu = orderMenu(food);
+ const totalPrice = preDiscountAmount(menu.menuNames, menu.quantities);
+
+ return { menu, totalPrice };
+};
+
+/**
+ * Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("Discount ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let discount;
+ /**
+ * ๋ชจ๋ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ Discount ๊ฐ์ฒด๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeAll(() => {
+ discount = new Discount();
+ });
+
+ /**
+ * ์ฌ๋ฌ ํ
์คํธ ์ผ์ด์ค์ ๋ํ ํ
์คํธ๋ฅผ ์ํํ๋ ํจ์
+ * @param {string} description - ํ
์คํธ ์ผ์ด์ค์ ๋ํ ์ค๋ช
+ * @param {string} date - ํ ์ธ์ ๋ฐ์ ๋ ์ง
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @param {Array} expected - ์์๋๋ ํ ์ธ ๋ชฉ๋ก
+ */
+ test.each([
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค์ผ ๋ ํ์ผ ํ ์ธ(๋์ ํธ 1๊ฐ)), ํน๋ณ ํ ์ธ",
+ "25",
+ "ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3400 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -2023 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํ ์์ผ์ผ ๋ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 2๊ฐ)",
+ "16",
+ "ํํ์ค-1,๋ฐ๋นํ๋ฆฝ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,์ดํ์ธ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -2500 },
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -4046 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 3๊ฐ)",
+ "28",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์ด์ฝ์ผ์ดํฌ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -6069 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 5๊ฐ)",
+ "30",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-4,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,๋ฐ๋นํ๋ฆฝ-1,ํด์ฐ๋ฌผํ์คํ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-4,์ด์ฝ์ผ์ดํฌ-1,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1,์ดํ์ธ-1",
+ [
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -10115 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 4๊ฐ)์ ํน๋ณ ํ ์ธ",
+ "31",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-1,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -8092 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "1๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ํ ์ธ ํํ์ด ์ ์ฉ๋์ง ์์",
+ "16",
+ "์์ก์ด์ํ-1,์ ๋ก์ฝ๋ผ-1",
+ [],
+ ],
+ [
+ "1๋ง์ ์ด์ 12๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ์ดํ์ธ ์ฆ์ ์ด ๋์ง ์์",
+ "24",
+ "ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-2",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3300 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -4046 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ ],
+ ],
+ ])("ํ
์คํธ ์ผ์ด์ค %#: %s", (_, date, food, expected) => {
+ const { menu, totalPrice } = getMenuAndTotalPrice(food);
+ const result = discount.discountPrice(menu, date, totalPrice);
+ expect(result).toEqual(expected);
+ });
+}); | JavaScript | jsDoc ์ฌ์ฉ์ ์ ํ์๋ค์ ๐ |
@@ -0,0 +1,111 @@
+/**
+ * @fileoverview Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module DiscountTest
+ */
+import Discount from "../../src/domain/Discount.js";
+import orderMenu from "../../src/domain/orderMenu.js";
+import preDiscountAmount from "../../src/domain/preDiscountAmount";
+
+/**
+ * ์ฃผ์ด์ง ์์์ ๋ํ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ์ ๋ฐํํ๋ ํจ์
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @returns {{menu: Object, totalPrice: number}} ์ฃผ๋ฌธํ ์์์ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ
+ */
+const getMenuAndTotalPrice = (food) => {
+ const menu = orderMenu(food);
+ const totalPrice = preDiscountAmount(menu.menuNames, menu.quantities);
+
+ return { menu, totalPrice };
+};
+
+/**
+ * Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("Discount ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let discount;
+ /**
+ * ๋ชจ๋ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ Discount ๊ฐ์ฒด๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeAll(() => {
+ discount = new Discount();
+ });
+
+ /**
+ * ์ฌ๋ฌ ํ
์คํธ ์ผ์ด์ค์ ๋ํ ํ
์คํธ๋ฅผ ์ํํ๋ ํจ์
+ * @param {string} description - ํ
์คํธ ์ผ์ด์ค์ ๋ํ ์ค๋ช
+ * @param {string} date - ํ ์ธ์ ๋ฐ์ ๋ ์ง
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @param {Array} expected - ์์๋๋ ํ ์ธ ๋ชฉ๋ก
+ */
+ test.each([
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค์ผ ๋ ํ์ผ ํ ์ธ(๋์ ํธ 1๊ฐ)), ํน๋ณ ํ ์ธ",
+ "25",
+ "ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3400 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -2023 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํ ์์ผ์ผ ๋ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 2๊ฐ)",
+ "16",
+ "ํํ์ค-1,๋ฐ๋นํ๋ฆฝ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,์ดํ์ธ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -2500 },
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -4046 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 3๊ฐ)",
+ "28",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์ด์ฝ์ผ์ดํฌ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -6069 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 5๊ฐ)",
+ "30",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-4,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,๋ฐ๋นํ๋ฆฝ-1,ํด์ฐ๋ฌผํ์คํ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-4,์ด์ฝ์ผ์ดํฌ-1,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1,์ดํ์ธ-1",
+ [
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -10115 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 4๊ฐ)์ ํน๋ณ ํ ์ธ",
+ "31",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-1,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -8092 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "1๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ํ ์ธ ํํ์ด ์ ์ฉ๋์ง ์์",
+ "16",
+ "์์ก์ด์ํ-1,์ ๋ก์ฝ๋ผ-1",
+ [],
+ ],
+ [
+ "1๋ง์ ์ด์ 12๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ์ดํ์ธ ์ฆ์ ์ด ๋์ง ์์",
+ "24",
+ "ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-2",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3300 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -4046 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ ],
+ ],
+ ])("ํ
์คํธ ์ผ์ด์ค %#: %s", (_, date, food, expected) => {
+ const { menu, totalPrice } = getMenuAndTotalPrice(food);
+ const result = discount.discountPrice(menu, date, totalPrice);
+ expect(result).toEqual(expected);
+ });
+}); | JavaScript | beforeAll์ ์ฌ์ฉํด์ DRY ์์น์ ์ค์ํ์๋๊ฒ์ด ์ธ์์ ์ด๋ค์ ๐ |
@@ -0,0 +1,111 @@
+/**
+ * @fileoverview Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ํ์ผ
+ * @module DiscountTest
+ */
+import Discount from "../../src/domain/Discount.js";
+import orderMenu from "../../src/domain/orderMenu.js";
+import preDiscountAmount from "../../src/domain/preDiscountAmount";
+
+/**
+ * ์ฃผ์ด์ง ์์์ ๋ํ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ์ ๋ฐํํ๋ ํจ์
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @returns {{menu: Object, totalPrice: number}} ์ฃผ๋ฌธํ ์์์ ๋ฉ๋ด์ ์ด ๊ฐ๊ฒฉ
+ */
+const getMenuAndTotalPrice = (food) => {
+ const menu = orderMenu(food);
+ const totalPrice = preDiscountAmount(menu.menuNames, menu.quantities);
+
+ return { menu, totalPrice };
+};
+
+/**
+ * Discount ๊ธฐ๋ฅ์ ๋ํ ํ
์คํธ ์ํธ
+ */
+describe("Discount ๊ธฐ๋ฅ ํ
์คํธ", () => {
+ let discount;
+ /**
+ * ๋ชจ๋ ํ
์คํธ ์ผ์ด์ค ์คํ ์ ์ Discount ๊ฐ์ฒด๋ฅผ ์ด๊ธฐํํ๋ ํจ์
+ */
+ beforeAll(() => {
+ discount = new Discount();
+ });
+
+ /**
+ * ์ฌ๋ฌ ํ
์คํธ ์ผ์ด์ค์ ๋ํ ํ
์คํธ๋ฅผ ์ํํ๋ ํจ์
+ * @param {string} description - ํ
์คํธ ์ผ์ด์ค์ ๋ํ ์ค๋ช
+ * @param {string} date - ํ ์ธ์ ๋ฐ์ ๋ ์ง
+ * @param {string} food - ์ฃผ๋ฌธํ ์์์ ๋ชฉ๋ก
+ * @param {Array} expected - ์์๋๋ ํ ์ธ ๋ชฉ๋ก
+ */
+ test.each([
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค์ผ ๋ ํ์ผ ํ ์ธ(๋์ ํธ 1๊ฐ)), ํน๋ณ ํ ์ธ",
+ "25",
+ "ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3400 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -2023 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํ ์์ผ์ผ ๋ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 2๊ฐ)",
+ "16",
+ "ํํ์ค-1,๋ฐ๋นํ๋ฆฝ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,์ดํ์ธ-1",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -2500 },
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -4046 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 3๊ฐ)",
+ "28",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์ด์ฝ์ผ์ดํฌ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -6069 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ์ฃผ๋ง ํ ์ธ(๋ฉ์ธ 5๊ฐ)",
+ "30",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-4,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,๋ฐ๋นํ๋ฆฝ-1,ํด์ฐ๋ฌผํ์คํ-1,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-4,์ด์ฝ์ผ์ดํฌ-1,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1,์ดํ์ธ-1",
+ [
+ { type: "์ฃผ๋ง ํ ์ธ: ", amount: -10115 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "ํฌ๋ฆฌ์ค๋ง์ค ์ดํ ํ์ผ ํ ์ธ(๋์ ํธ 4๊ฐ)์ ํน๋ณ ํ ์ธ",
+ "31",
+ "์์ก์ด์ํ-1,์์ ์๋ฌ๋-1,ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-2,ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1,๋ ๋์์ธ-1",
+ [
+ { type: "ํ์ผ ํ ์ธ: ", amount: -8092 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ { type: "์ฆ์ ์ด๋ฒคํธ: ", amount: -25000 },
+ ],
+ ],
+ [
+ "1๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ํ ์ธ ํํ์ด ์ ์ฉ๋์ง ์์",
+ "16",
+ "์์ก์ด์ํ-1,์ ๋ก์ฝ๋ผ-1",
+ [],
+ ],
+ [
+ "1๋ง์ ์ด์ 12๋ง์ ์ดํ ๊ธ์ก์ด๋ผ ์ดํ์ธ ์ฆ์ ์ด ๋์ง ์์",
+ "24",
+ "ํํ์ค-1,ํฐ๋ณธ์คํ
์ดํฌ-1,ํด์ฐ๋ฌผํ์คํ-1,์์ด์คํฌ๋ฆผ-2,์ ๋ก์ฝ๋ผ-2",
+ [
+ { type: "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: ", amount: -3300 },
+ { type: "ํ์ผ ํ ์ธ: ", amount: -4046 },
+ { type: "ํน๋ณ ํ ์ธ: ", amount: -1000 },
+ ],
+ ],
+ ])("ํ
์คํธ ์ผ์ด์ค %#: %s", (_, date, food, expected) => {
+ const { menu, totalPrice } = getMenuAndTotalPrice(food);
+ const result = discount.discountPrice(menu, date, totalPrice);
+ expect(result).toEqual(expected);
+ });
+}); | JavaScript | ```suggestion
{
"description": "ํฌ๋ฆฌ์ค๋ง์ค์ผ ๋ ํ์ผ ํ ์ธ(๋์ ํธ 1๊ฐ)), ํน๋ณ ํ ์ธ",
"visitDate": "25",
"orderMenuInfo": [
{ "menuItem": "ํด์ฐ๋ฌผํ์คํ", "quantity": 2 },
{ "menuItem": "๋ ๋์์ธ", "quantity": 1 },
{ "menuItem": "์ด์ฝ์ผ์ดํฌ", "quantity": 1 }
],
"result": [
{ "type": "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ", "amount": -3400 },
{ "type": "ํ์ผ ํ ์ธ", "amount": -2023 },
{ "type": "ํน๋ณ ํ ์ธ", "amount": -1000 },
{ "type": "์ฆ์ ์ด๋ฒคํธ", "amount": -25000 }
]
}
```
์ด๋ ๊ฒ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ฉด ๋ ๋ช
์์ ์ผ๋ก ๋ณด์ผ๊ฑฐ ๊ฐ์์! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.