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 } ] } ``` ์ด๋ ‡๊ฒŒ ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋” ๋ช…์‹œ์ ์œผ๋กœ ๋ณด์ผ๊ฑฐ ๊ฐ™์•„์š”!