code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ๋ฉ์๋ ์ฒด์ด๋์ ์ ์ฉํด์ Arrays.stream(trimmedInputCarName).forEach(~~)
๋ก ์ด์ด ๋ถ์ด์๋ฉด ์ด๋จ๊น์ |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ฉ์๋๋ค์ด static ์ธ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ชจ๋ ๋ฉ์๋๊ฐ public ์ผ๋ก ๊ณต๊ฐ๋์ด์๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | RacingGame ์์ Cars ์ ๋ํ ์ํ๋ฅผ ๋ค๊ณ ์์ผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,12 @@
+import java.util.ArrayList;
+
+public class Main {
+ public static void main(String[] args) {
+ RacingGame racing = new RacingGame();
+ ArrayList<Car> cars = new ArrayList<>();
+ cars = racing.registerCarNames(cars, racing.nameSet(InputView.setNames()));
+ int number = InputView.inputNumber();
+ ResultView result = new ResultView();
+ result.resultRacing(number, cars);
+ }
+} | Java | ์กฐ์์ ๋ธ๋กํฌ์ effective java ์๋ '๊ฐ์ฒด๋ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํด ์ฐธ์กฐํ๋ผ.'
๋ผ๋ ๋ถ๋ถ์ด ์์ต๋๋ค.
ํ๋ฒ ์ฝ์ด๋ณด์๊ณ ๊ฐ์ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ~
jaehun2841.github.io/2019/03/01/effective-java-item64/#%EC%9C%A0%EC%97%B0%ED%95%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B3%80%EC%88%98 |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ฉ์๋๋ช
์ด ๋๋ถ๋ถ ๋ช
์ฌ์ธ ๊ฒ ๊ฐ์๋ฐ ๋์ฌํ์ผ๋ก ๋ฐ๊ฟ๋ณด๋ฉด ์ด๋จ๊น์~
๊ทธ๋ฆฌ๊ณ cnt ๊ฐ์ ๊ฒฝ์ฐ์๋ ํ๋ค์์ผ๋ก ์ ์ด์ฃผ๋ฉด ์คํฐ๋ ๊ท์น์ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ํ ํด๋์ค์์ ์ฑ
์์ ๋ง์ด ๋ค๊ณ ์๊ธฐ ๋๋ฌธ์ ํด๋์ค ๊ธธ์ด๊ฐ ๋์ด๋ ๊ฒ ๊ฐ์๋ฐ์,
winner ์ ๋ํ ๋ก์ง์ ๋ค๋ฅธ ํด๋์ค๋ฅผ ๋ง๋ค์ด ์์ํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,39 @@
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+
+public class RacingGameTest {
+ RacingGame r;
+ ResultView v;
+
+ @Before
+ public void setUp() {
+ r = new RacingGame();
+ v = new ResultView();
+ }
+
+ @Test
+ public void carNamesInputTest() {
+ String input = "์์ก, ์๋์ฐ, ๊ตฌ๋ฆ, ๊ทธ๋ฆฌ์ฆ, ํค์บฃ";
+ assertEquals("์์ก ์๋์ฐ ๊ตฌ๋ฆ ๊ทธ๋ฆฌ์ฆ ํค์บฃ", r.getInputNames(input));
+ }
+
+ @Test
+ public void winnerTest() {
+ ArrayList<Car> cars = new ArrayList<>();
+ String input = "์์ก, ์๋์ฐ, ๊ตฌ๋ฆ, ๊ทธ๋ฆฌ์ฆ, ํค์บฃ";
+ int number = 1;
+ int[] randomNumbers = {1, 3, 5, 8, 2};
+ cars = r.registerCarNames(cars, r.nameSet(input));
+ assertEquals(" ๊ตฌ๋ฆ ๊ทธ๋ฆฌ์ฆ ", r.getWinner(cars, randomNumbers));
+ }
+
+ @After
+ public void tearDown() {
+ r = null;
+ }
+}
\ No newline at end of file | Java | ์คํฐ๋ ๊ท์น : ๋ณ์๋ช
์ ์ค์ฌ์ฐ์ง ์๋๋ค |
@@ -0,0 +1,40 @@
+import java.util.ArrayList;
+
+public class ResultView {
+ public static void resultRacing(int number, ArrayList<Car> cars) {
+ System.out.println("์คํ ๊ฒฐ๊ณผ");
+ for (int i = 0; i < number; i++) {
+ RacingGame.randomToNumber(cars);
+ resultRacing(cars);
+ System.out.println("");
+ }
+ ArrayList<String> winners = RacingGame.findWinner(cars);
+ finalResultView(winners);
+ }
+
+ public static void resultRacing(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ System.out.println(cars.get(i).getName() + ":" + racingView(cars.get(i).getPosition()));
+ }
+ }
+
+ public static String racingView(int n) {
+ String car = "";
+ for (int i = 0; i < n; i++) {
+ car += "-";
+ }
+ return car;
+ }
+
+ public static void finalResultView(ArrayList<String> winners) {
+ if (winners.size() == 1) {
+ System.out.println(winners.get(0) + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค.");
+ }
+ if (winners.size() > 1) {
+ for (int i = 0; i < winners.size() - 1; i++) {
+ System.out.print(winners.get(i) + ",");
+ }
+ System.out.println(winners.get(winners.size() - 1) + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค.");
+ }
+ }
+} | Java | ResultView ๋ ์ดํ๋ฆฌ์ผ์ด์
์ ํ๋ฆ์ด๋ ๋ก์ง์ ์ ํ์ ์์ด ๊ทธ๋ฅ ๋ค์ด์จ input ์ ๋ํด์ ์ถ๋ ฅ๋ง ํด์ฃผ๋ ์ ๋์ ์ญํ ์ ํ๋๋ก ๋ณ๊ฒฝํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -5,6 +5,7 @@
import com.project.Project.domain.interaction.ReviewLike;
import com.project.Project.domain.member.Member;
import com.project.Project.domain.member.RecentMapLocation;
+import com.project.Project.domain.review.Review;
import java.util.List;
import java.util.Optional;
@@ -21,4 +22,9 @@ public interface MemberService {
public List<ReviewLike> getReviewLikeList(Member member);
Long delete(Member member);
+
+
+
+
+
} | Java | ์ด ๋ฉ์๋๋ฅผ ReviewService๋ก ์ฎ๊ธฐ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
๊ฐ๋ง๋ณด๋ ์ด์ ์ ์์ฑํ๋ ์์ getReviewLikeList๋ ์๋ชป ์์นํด ์๋ ๊ฒ ๊ฐ๋ค์ |
@@ -7,6 +7,7 @@
import com.project.Project.domain.interaction.ReviewLike;
import com.project.Project.domain.member.Member;
import com.project.Project.domain.member.RecentMapLocation;
+import com.project.Project.domain.review.Review;
import com.project.Project.repository.interaction.FavoriteRepository;
import com.project.Project.repository.interaction.ReviewLikeRepository;
import com.project.Project.repository.member.MemberCustomRepository;
@@ -79,4 +80,6 @@ public Integer getReviewCnt(Member member) {
public List<ReviewLike> getReviewLikeList(Member member) {
return reviewLikeRepository.findByReviewLikeStatusAndMember(ReviewLikeStatus.LIKED, member);
}
+
+
} | Java | ๋ง์ฐฌ๊ฐ์ง๋ก ReviewServiceImpl์ชฝ์ผ๋ก ์ฎ๊ธฐ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -2,6 +2,7 @@
import com.project.Project.domain.member.Member;
import com.project.Project.domain.review.Review;
+import com.querydsl.core.types.dsl.BooleanExpression;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -40,4 +41,6 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
@Query("select review from Review review where review.author.id = :memberId and review.id = :reviewId")
Optional<Review> findReviewByAuthorAndReview(Long memberId, Long reviewId);
+
+ List<Review> findReviewsByAuthor(Member member);
} | Java | ์ด ๋ฉ์๋๋ deleted ํ๋ ์ ์ธํ๋ ๊ฒ ๋ฐ์ํ์๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -3,21 +3,17 @@
<mapper namespace="com.midnear.midnearshopping.mapper.coupon_point.PointMapper">
<insert id="grantPoints" useGeneratedKeys="true" keyProperty="pointId">
INSERT INTO point (
- amount, reason
+ amount, reason, review_id, user_id, grant_date
) VALUES (
- #{amount}, #{reason}
+ #{amount}, #{reason}, #{reviewId}, #{userId}, NOW()
)
</insert>
- <insert id="setReviewPointAmount">
- INSERT INTO review_point (
- text_review, photo_review
- ) VALUES (
- #{textReview}, #{photoReview}
- )
- </insert>
- <delete id="deletePreviousData">
- delete from review_point
- </delete>
+ <select id="getProductInfoByReviewId" resultType="java.lang.String">
+ select concat(op.product_name, ' _ ', op.color)
+ from reviews r
+ join order_products op on r.order_product_id = op.order_product_id
+ where review_id = #{reviewId}
+ </select>
<!--์๋ ํ์ผ ๋ฐ๋ก ๋บด๊ธฐ ์ ๋งคํด์ ์ฌ๊ธฐ์ ๋ฃ์-->
<select id="getPointList">
select | Unknown | ๊ฐ์ฌํฉ๋๋ค.. |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | `@Enumerated` ๋ถ์ฌ์ฃผ์ค๊บผ์ฃ ? ๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ์ด๊ฑธ ๋์ณค๋ค์;;ใ
ใ
|
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ๊ฒจ์ฐ ํ๋ ์ฐพ์์ต๋๋ค๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | extension์ ์ด๋ค ๋ณ์ ์ธ๊ฐ์..?! ์ ๋ ํด๋, ํ์ผ ๊ด๋ จ ์ํฐํฐ ์ค๊ณ ์ค์ธ๋ฐ ์นผ๋ผ ์ค์ ์ ์ ๋ง ์ํ์ ๊ฒ ๊ฐ์์ ๊ณ ์ํ์
จ์ต๋๋ค!! ๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ํ์ผ ํ์ฅ์์
๋๋ค! |
@@ -0,0 +1,29 @@
+import { Console } from '@woowacourse/mission-utils';
+import parseInput from './parseInput';
+
+const inputHandler = {
+ async dateHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ validate(Number(input));
+ return Number(input);
+ } catch (e) {
+ Console.print(e.message);
+ return this.dateHandler(userInput, validate);
+ }
+ },
+
+ async orderHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ const menu = parseInput(input);
+ validate(menu);
+ return Object.fromEntries(menu);
+ } catch (e) {
+ Console.print(e.message);
+ return this.orderHandler(userInput, validate);
+ }
+ },
+};
+
+export default inputHandler; | JavaScript | ์์ ์
๋ ฅ ๋ฐ๊ณ ๋์ ๋ฐ๋ก ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ ์์๋ค์ ์ด ๋ฐฉ๋ฒ์ ์๊ฐํ์ง ๋ชปํ๋ ๊ฒ ๊ฐ์ต๋๋ค ใ
..
์ถ๊ฐ๋ก trim,split,map์ ๊ฒฐํฉํด์ ์ฐ๋ ๊ฒ๋ณด๋ค ์ ๊ทํํ์์ ์ฌ์ฉํด๋ณด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ํน์ new Date() ๋ง๊ณ ๋๋จธ์ง ๊ฐ์ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์๊น์?? |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ํด๋น ๋ถ๋ถ๋ ์ ๊ทํํ์์ ์ฐ๋ฉด if๋ฅผ ํ๋๋ง ์จ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค ! |
@@ -0,0 +1,29 @@
+import { Console } from '@woowacourse/mission-utils';
+import parseInput from './parseInput';
+
+const inputHandler = {
+ async dateHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ validate(Number(input));
+ return Number(input);
+ } catch (e) {
+ Console.print(e.message);
+ return this.dateHandler(userInput, validate);
+ }
+ },
+
+ async orderHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ const menu = parseInput(input);
+ validate(menu);
+ return Object.fromEntries(menu);
+ } catch (e) {
+ Console.print(e.message);
+ return this.orderHandler(userInput, validate);
+ }
+ },
+};
+
+export default inputHandler; | JavaScript | ์ ๊ท ํํ์์ ํ์ฉํ์ผ๋ฉด ๊ตณ์ด ํ์ฑํ๋ ์์
์ด ํ์ํ์ง ์์์ ์๋ ์๊ฒ ๋ค์ ์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค ใ
ใ
๐คฃ |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋ฏธ์
์์ 2023๋
2์๋ก ์ ํํ ๊ธฐ๊ฐ์ ๋ช
์ํด์ฃผ์๊ธฐ์ ๊ด๋ จ๋ ๊ฑด ์ต๋ํ Date ๊ฐ์ฒด ์์ฑ์ด ์๋ ๊ตฌํ์ผ๋ก ํด๊ฒฐํ๊ณ ์ถ๋ค๋ ์ ์์ ์ฌ์ฉ์ ํ์ง ์์ผ๋ ค๊ณ ํ์ต๋๋ค ! ๋ ๊ทธ๋ฌ๋ค๋ณด๋ ์ถฉ๋ถํ ๋ค๋ฅธ ํํ์์ผ๋ก ์ผ์๋ฅผ ํ๋ณํ ์ ์๋ค๊ณ ์๊ฐํ์ฌ ๊ทธ๋ ๊ฒ ๊ตฌํํ๋ ๊ฑฐ ๊ฐ๋ค์ ๐ค |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ๋ฏธ์
์ ์งํํ๋ฉด์ ๊ฐ์ธ์ ์ผ๋ก key๊ฐ์ ํ๊ธ๋ก ํ๋๊ฒ ๋ง๋๊ฐ? ํ๋ ์๋ฌธ์ด ๋ค์์ต๋๋ค!
์ฌ๊ฒฝ๋ ์๊ฐ์ด ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,28 @@
+import InputView from '../View/InputView';
+import OutputView from '../View/OutputView';
+import Client from './Client';
+
+class PromotionController {
+ async insertInput() {
+ const client = new Client(
+ await InputView.readDate(),
+ await InputView.readOrder(),
+ );
+ const date = client.getDate();
+ this.printOutput(client, date);
+ }
+
+ printOutput(client, date) {
+ OutputView.printIntro();
+ OutputView.printPreview(date);
+ OutputView.printMenuTitle(client);
+ OutputView.printBeforeDiscount(client);
+ OutputView.printGift(client);
+ OutputView.printBenefit(client);
+ OutputView.printDiscountAmount(client);
+ OutputView.printAfterDiscount(client);
+ OutputView.printEventBadge(client);
+ }
+}
+
+export default PromotionController; | JavaScript | Controller ๋ก์ง์ด ๊น๋ํด์ ๋ณด๊ธฐ ์ข๋ค์ ๋ฐฐ์๊ฐ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ ์ด๋ถ๋ถ ๋๋ฌธ์ ๊ณคํน์ ์น๋ค๋๋ฐ ๋ค๋ค ๋น์ทํ ์๊ฐ์ด์
จ๋๋ด์ ๐ค ํนํ ์ดํ์ธ ์ฆ์ ์ฌ๋ถ๋ฅผ ํ๋ณํ ๋ `์ดํ์ธ.price` ์์ผ๋ก ํธ์ถํด์ผํ๋ ์ ๋๋ฌธ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ๊ณผ ๋ช
์นญ์ ๋ฐ๋ก ์ฆ์ ๋ฉ๋ด์ ๋ํ ์์๋ก ์ ์ธํ๊ธฐ๋ ํ์ต๋๋ค..
๋ก์ง์์์๋ ํธ์ถ๋์ง ์์ง๋ง, ํ
์คํธ ์ฝ๋์์๋ ๋ ํธ์ถํด์ผํ๋ ๋ถ๋ถ๋ค์ด ์์ด ๊ณ ๋ฏผ์ด ๋ง์๋ค์ ใ
ใ
์ฌ์ค..
```js
SOUP : { name: ์์ก์ด ์ํ, price : 6000, ... }
```
์๋ฐ ์์ผ๋ก ์ ์ธ ํํ๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ id ๋ก SOUP๋ฅผ ์ ์ธํด์ ํค๊ฐ์ ํ๋ณํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค๋ฉด ํ๊ธ๋ก ์์ฑํ๋ ๋ก์ง์ ๋์ด๋ผ ์ ์์์ ๊ฑฐ๋ ์๊ฐ์ ํ์์ด์...ใ
ใ
์
๋ ฅ์ ๋ํ ๋ณํ์ด ์ฌ์ด ํํ๋ฅผ ์ฑํํ๊ณ ์ ํ๋ ๊ฑฐ ๊ฐ์ต๋๋ค ๐คฃ |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | Object.freeze() ๋ ์์ ๋๊ฒฐ์ ํด์ฃผ๊ธฐ ๋๋ฌธ์ deepFreeze์ ๋ํด์ ์์๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!!
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#%EB%B0%B0%EC%97%B4_%EB%8F%99%EA%B2%B0 |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ด๋ฒ์ ๊ธ์ก์ ๊ดํ ์ซ์๋ฅผ ๋ค๋ฃจ๋ฉด์ `numeric seperator` ๋ผ๋ ๋ฐฉ์์ ์๊ฒ๋์๋๋ฐ
๊ฐ์ธ์ ์ผ๋ก ์ซ์ ๋จ์๊ฐ ํ๋์ ๋ค์ด์์ ์ข๋๋ผ๊ตฌ์!
```suggestion
GIFT_CONDITION: 120_000,
``` |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ํจ์ ๋ก์ง์ด ์ฌ๋ฌ์ค์ด๋ผ ์๋์ฒ๋ผ ์์ ํ๋๊ฑด ์ด๋จ๊น์??
```suggestion
const parseInput = (userInput) => {
return userInput
.trim()
.split(",")
.map((item) => {
const [name, quantity] = item.trim().split("-");
return [name, Number(quantity)];
});
};
```
https://github.com/airbnb/javascript#whitespace--implicit-arrow-linebreak
https://github.com/airbnb/javascript#arrows--paren-wrap |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์ฌ์ฉํ์ง ์๋ ํ๋ผ๋ฏธํฐ๋ ์ธ๋๋ฐ๋ก ํํํ๋ ๊ด์ต์ด ์๋ค๊ณ ํฉ๋๋ค!
```suggestion
const total = menu.reduce((acc, [_, count]) => acc + count, 0);
``` |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์ค ์ข์ ๋ฐฉ๋ฒ์ด๋ค์. |
@@ -0,0 +1,208 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
๊ธฐ๋ฅ ๋ชฉ๋ก ์ ๋ฆฌ ๐
+
+### ํด๋์ค, ํจ์ ์ ๋ฆฌ
+
+1. Domain
+- 1-1. `PromotionController`
+ - ์ ์ฒด ํ๋ก๋ชจ์
์ ํ๋ก์ธ์ค ๋ฐ ์
์ถ๋ ฅ์ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค
+- 1-2. `Discount`
+ - ๋ ์ง์ ๋ํ ํํ๋ค์ ํ์ธํ๊ณ , ํํ์ ๊ณ์ฐํ๋ ํด๋์ค
+- 1-3. `Client`
+ - ์ฃผ๋ฌธ๊ณผ ๋ ์ง ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ๊ฐ์ ํ ์ธ ํํ๊ณผ ์ฃผ๋ฌธ ๊ฐ๊ฒฉ์ ๊ณ์ฐํ๋ ํด๋์ค
+
+2. View
+- 2-1. `InputView`
+ - ์ฌ์ฉ์๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํ๊ณ , ์
๋ ฅ๋ ๋ฐ์ดํฐ ๋ฐํํ๋ ํจ์
+- 2-2. `OutputView`
+ - ํ๋ก์ธ์ค ๊ฒฐ๊ณผ ๋ฐ ์ค๋ฅ ๋ฉ์ธ์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์ถ๋ ฅํ๋ ํจ์
+
+
+3. Util
+- 3-1. `constants`
+ - ์ฌ์ฉ๋๋ ๋งค์ง๋๋ฒ, ์๋ฌ๋ฉ์ธ์ง, ์
์ถ๋ ฅ ๋ฉ์์ง, ์ถ๋ ฅ ํ์ดํ ๋ฑ ์์ ์ ์
+- 3-2. `inputHandler`
+ - InputView ๋ด์์ ์
๋ ฅ์ ๋ฐ๋ ๋ก์ง ํธ๋ค๋ฌ ์ ์
+- 3-3. `parseInput`
+ - ๊ณ ๊ฐ์ ๋ฉ๋ด ์
๋ ฅ์ ๋ฉ๋ด ์ฃผ๋ฌธ ๋ฆฌ์คํธ ํํ๋ก ๋ณํํ๋ ํจ์ ์ ์
+- 3-4. `validateInput`
+ - ๊ณ ๊ฐ์ ์
๋ ฅ์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ ํจ์ ์ ์
+4. `App`
+ - ํ๋ก๋ชจ์
์ปจํธ๋กค๋ฌ ํด๋์ค๋ฅผ ์คํ์ํค๋ ์ ์ฒด
+5. `index`
+ - ๋ก์ง์ ์ํํ๋ App์ ์คํํ๋ ์ง์
์
+
+
+### ๊ตฌํ ๊ธฐ๋ฅ ์ ๋ฆฌ
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- [x] ์ด๋ฒคํธ ํ๋๋ ๋ฉํธ ์ถ๋ ฅ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง(์ผ) ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- [x] 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- [x] `<์ฃผ๋ฌธ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ ์ถ๋ ฅ
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- [x] `<์ฆ์ ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ดํ์ธ 1๊ฐ` ๋๋ `์์` ์ถ๋ ฅ
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- [x] `<ํํ ๋ด์ญ>` ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํ์ผ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํน๋ณ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅ
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<์ดํํ ๊ธ์ก>` ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก ์ถ๋ ฅ
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- [x] `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ์ถ๋ ฅ
+- [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง ์ถ๋ ฅ
+
+
+### ์ด๋ฒคํธ ์ ๋ฆฌ
+
+1-1. 2023.12.1 ~ 2023.12.25 ํ ์ธ
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - 12.1 ๊ธฐ์ค 1,000์ ํ ์ธ ~
+ - 12.25 ๊ธฐ์ค 3400์ ํ์ธ
+
+1-2. 2023.12.1 ~ 2023.12.31 ํ ์ธ
+
+- ํ์ผ ํ ์ธ (์ผ, ์, ํ, ์, ๋ชฉ)
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ (๊ธ, ํ )
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ (3(์ผ), 10(์ผ), 17(์ผ), 24(์ผ), 25(์), 31(์ผ))
+ - ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ 1000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - **ํ ์ธ ์ ์ด ์ฃผ๋ฌธ๊ธ์ก**์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+1-3. ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+
+- ์ด ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง
+ - ๋ฏธ์ถฉ์กฑ : ์์
+ - 5์ฒ์ ์ด์ : ๋ณ
+ - 1๋ง์ ์ด์ : ํธ๋ฆฌ
+ - 2๋ง์ ์ด์ : ์ฐํ
+
+1-4. ์ฃผ์ ์ฌํญ
+
+- 'ํ ์ธ'์ด๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง, ๊ธ์ก '์ฐจ๊ฐ'์ ๋ ๊ฐ๊น์. %๋ก ํ ์ธ์ด ์๋ - ํ์
+- ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ธ์ง ํ์ธํ๊ณ ์ด๋ฒคํธ ์ ์ฉ ํ์
+- ์๋ฃ๋ง, ์ฃผ๋ฌธ ์ ์ฃผ๋ฌธ ์์ฒด๊ฐ ๋ถ๊ฐ
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ ๊น์ง ์ฃผ๋ฌธ ๊ฐ๋ฅ
+
+
+### ํ๋ฆ ์ ๋ฆฌ
+
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- 1-1. ์ด๋ฒคํธ ํ๋๋ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 1-2. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง(์ผ)๋ฅผ ์ซ์๋ก๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+ -1-2-1. ์
๋ ฅ ๋ฐ์ ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- 2-1. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+- 2-2. `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ๋๋ค.
+ - 2-2-1. ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- 3-1. 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- 4-1. `<์ฃผ๋ฌธ๋ฉ๋ด>`๋ฅผ ์ถ๋ ฅํ๋ค.
+- 4-2. `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ์ `์ฃผ๋ฌธ ๋ฉ๋ด (๋ฉ๋ด๊ฐ์)๊ฐ\n` ๋ก ์ถ๋ ฅํ๋ค.
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- 5-1. `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ ์ถ๋ ฅํ๋ค.
+- 5-2. ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+ - 5-2-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- 6-1. `์ดํ์ธ (๊ฐ์)๊ฐ` ์ถ๋ ฅํ๋ค.
+ - 6-2-1. ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์ ๊ฒฝ์ฐ ๋น ์ดํ์ธ์ด 1๊ฐ์ฉ ์ฆ์ ๋๋ค.
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- 7-1. `<ํํ ๋ด์ญ>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 7-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 7-2. ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-3. ํ์ผ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-4. ํน๋ณ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-5. ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅํ๋ค.
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- 8-1. `<์ดํํ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 8-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 8-2. *7. ํํ๋ด์ญ ์ถ๋ ฅ* ์ `7-2 ~ 7-5` ์ ๊ธ์ก์ ๋ชจ๋ ๋ํด์ ์ถ๋ ฅํ๋ค.
+
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- 9-1. `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 9-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅํ๋ค.
+- 9-2. **5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ** ์์ **8. ์ด ํํ ๊ธ์ก ์ถ๋ ฅ** ์ ๋บ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- 10-1. `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 10-2. ์ถ๋ ฅํ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ฒฝ์ฐ `์์`์ ์ถ๋ ฅํ๋ค.
+
+
+### ๐ ํ์ผ ๊ตฌ์กฐ
+
+```
+โ src
+ โฃ Domain
+ โ โฃ PromotionController.js
+ โ โฃ Client.js
+ โ โ Discount.js
+ โฃ View
+ โ โฃ InputView.js
+ โ โ OutputView.js
+ โฃ Util
+ โ โฃ constants.js
+ โ โฃ parseInput.js
+ โ โฃ inputHandler.js
+ โ โ validateInput.js
+ โฃ App.js
+ โ index.js
+```
\ No newline at end of file | Unknown | UserFlow๊ฐ ๋ช
ํํ๊ฒ ์์ฑ๋ ๊ฒ ๊ฐ์์ :)
userflow๋ฅผ ์์ฑํ๋ฉด์ ์ค๊ณ๋ฅผ ํ๋ฉด, ์์ธ์ฒ๋ฆฌ๋ flow๋ฅผ ์ค๊ณํจ์ ์์ด์ ๋ง์ ๋์์ด ๋ ๊ฒ ๊ฐ๋ค์! |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ์ด ํจํด ์์ฒด๋ ์๋นํ ์ข๋ค์. ๊ทธ๋ฐ๋ฐ ์๋์ ๊ฐ์ ๊ฒฝ์ฐ๋ ์ปค๋ฒ๊ฐ ์ ๋ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค.
```javascript
const item = 'ํํ์ค-1-'
const [name, menu] = item.trim().split('-')
console.log(name, menu) // ํํ์ค, 1
``` |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋งค์ฐ ์ฌ์ํ ๋ถ๋ถ์ด์ง๋ง, 7๊ณผ 1,2๋ ์์ํ๋ฅผ ์งํํ๋ฉด ์ด๋จ๊น ์ถ๋ค์!
1๊ณผ 2๊ฐ ๋ฌด์์ ์๋ฏธํ๋์ง ํท๊ฐ๋ฆด ์๋ ์๊ณ , ๋์ผํ๊ฒ ์์ ํ ์ ์๋๋ก์ :) |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ```javascript
getOrderList() {
Object.entries(this.#order).map(([name, count]) =>`${name} ${count}${INFO.COUNT}`);
return output.join('\n)';
}
```
```javascript
Object.entries(this.#order)
.map(([name, count]) => MENU[name].price * count)
.reduce((acc, cur) => acc+cur, 0)
```
์ฌ์ํ ์คํ์ผ ์ฐจ์ด์ง๋ง ์ด๋ ๊ฒ ๊ณ ์น ์๋ ์๊ฒ ๋ค์. |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ด์ง๋ง ์ด ๊ฒฝ์ฐ๋ `model`์ด `view`์ ์ง์์ ๋๋ฌด ๋ง์ด ์๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๋ค `view`์์๋ "{ํ ์ธ}: {๊ธ์ก}์"ํ์์ผ๋ก ๋ฐ๊ธธ ์ํ ์๋ ์์ง๋ง ๋ค๋ฅธ `view`์์๋ "{๊ธ์ก}๋งํผ {ํ ์ธ}์ ๋ฐ์ผ์
จ์ด์"์ ๊ฐ์ด ์ถ๋ ฅํ๊ธฐ๋ฅผ ์ํ ์ ์๋ค๋ ์๊ฐ์ด ๋ค๊ณ , ๋ฐ๋ผ์ `domain` ์์ญ์ด `view` ์์ญ์์ ์ฒ๋ฆฌ๋์ด์ผ ํ๋ ๊ฒ ์๋๊น ์๊ฐ์ด ๋๋ค์. |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๊ฐ case๋ง๋ค ๋ฐ๋ก ๊ตฌ๋ถ์ ์ง์ด ์ฃผ์ ๊ฑฐ๋ผ๋ฉด,
```javascript
let specialDayDiscount = 0;
specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
```
์ ๊ฐ์ ๋ฐฉ์๋ ์ข์ง๋ง, ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํ๋ฒ์ ์ ์ธํด ๋ฒ๋ ค๋ ๊ด์ฐฎ์ง ์์๊น ์ถ์ด์!
```javascript
const specialDayDiscount = -DATE.SPECIAL_DISCOUNT;
``` |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ ์ด๋ฐ ๋ฐฉ๋ฒ์ ๋ชฐ๋ผ์ ๋๊ฐ๋ก ๋๋ ์ ์ผ์๋๋ฐ, ์ข์ ๋ฐฉ๋ฒ์ด ์์๊ตฐ์!
์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค ใ
ใ
โบ๏ธ |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ค ๊ธ์ก์ด ํฐ ๊ฒฝ์ฐ ๋ ์ ์ฉํ๊ฒ ๋ค์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค ! |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์์ด๋น์ค๋น ์ปจ๋ฒค์
์์ ์ง์ํ๋ ๊ฑฐ ๊ฐ๋๋ผ๊ตฌ์.. ๊ทธ๋์ ํน์๋ ํด์ ๋ป๋๋ฐ ์ฌ์ฉํ๋๊ฒ ์ข์๋ ๊ฑฐ ๊ฐ๋ค์ ๐ค |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ์๋ง ์ ๋ฐ ์
๋ ฅ์ด ๋ค์ด์จ๋ค๋ฉด ์ ํจ์ฑ ๊ฒ์ฌ์์ ๊ฑธ๋ฌ๋ด์ค ์ ์์ ๊ฑฐ ๊ฐ์ต๋๋ค ! ๊ทธ๋๋ ํ์ฑํ๋ ๊ณผ์ ์์ ๋ฐ์ํ ์ ์๋ ์๋ฌ ๊ฒฝ์ฐ๋ฅผ ์๋ ค์ฃผ์
์ ์ข ๋ ๊ณ ๋ฏผํด๋ณผ ์ ์๋ ๊ณ๊ธฐ๊ฐ ๋ ๊ฑฐ ๊ฐ์์ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ์ค ํจ์ฌ ๊น๋ํ ๊ฑฐ ๊ฐ์ ์ข๋ค์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค. ๋ง์ํ์ ๊ฑฐ์ฒ๋ผ ๋ชจ๋ธ์ด ๋ทฐ์ ์ธ๋ถ์ฌํญ์ ๊ณผ๋ํ๊ฒ ์๊ณ ์๋ ํํ๋ผ๋ฉด ํํ๋ฐฉ์์ด ํผํฉ๋ ๋๋์ด ๋ค์ด ์ ์ฐ์ฑ์ด ๋จ์ด์ง ๊ฑฐ ๊ฐ๋ค์ ใ
ใ
์ฌ์ค mvc ํจํด์ ์ง์ฐฉํ์ง ์๊ณ ํด๋์ค ์์ฒด๊ฐ ๊ฐ์ง ์ ์๋ ์ญํ ์ ์๊ฐํ๊ณ , ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋ฐฉ์์ ๊ณ ๋ คํ๋ค๋ณด๋ ํจํด์์ ์ค๋ ์ฒ๋ฆฌ๊ธฐ์ค๊ณผ๋ ์ด๊ธ๋๋ ์ํฉ์ด ๋ฐ์ํ๋ ๊ฑฐ ๊ฐ๋ค์ ... ๋ฒ ๋ฆฌ์์ด์
์ด ๋ค์ํ๊ฒ ์กด์ฌํ๋ ์ํฉ์์๋ ์ ์ฐํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๊ตฌ์กฐ๊ฐ ๋ฌด์์ธ์ง ์ข๋ ๊ณ ๋ฏผํด๋ด์ผ๊ฒ ๋ค์ ์กฐ์ธ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ํธ๋ค ์ธํ์์ ๋ฐ์์ ๋ฐ๋ก ํ์ฑํ์๋ ๊ฒ ๊ฐ์๋ฐ ์ ํจ์ฑ ๊ฒ์ฌ์์ ๋๋ฝ๋์ง ์์๊น์? |
@@ -0,0 +1,208 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
๊ธฐ๋ฅ ๋ชฉ๋ก ์ ๋ฆฌ ๐
+
+### ํด๋์ค, ํจ์ ์ ๋ฆฌ
+
+1. Domain
+- 1-1. `PromotionController`
+ - ์ ์ฒด ํ๋ก๋ชจ์
์ ํ๋ก์ธ์ค ๋ฐ ์
์ถ๋ ฅ์ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค
+- 1-2. `Discount`
+ - ๋ ์ง์ ๋ํ ํํ๋ค์ ํ์ธํ๊ณ , ํํ์ ๊ณ์ฐํ๋ ํด๋์ค
+- 1-3. `Client`
+ - ์ฃผ๋ฌธ๊ณผ ๋ ์ง ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ๊ฐ์ ํ ์ธ ํํ๊ณผ ์ฃผ๋ฌธ ๊ฐ๊ฒฉ์ ๊ณ์ฐํ๋ ํด๋์ค
+
+2. View
+- 2-1. `InputView`
+ - ์ฌ์ฉ์๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํ๊ณ , ์
๋ ฅ๋ ๋ฐ์ดํฐ ๋ฐํํ๋ ํจ์
+- 2-2. `OutputView`
+ - ํ๋ก์ธ์ค ๊ฒฐ๊ณผ ๋ฐ ์ค๋ฅ ๋ฉ์ธ์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์ถ๋ ฅํ๋ ํจ์
+
+
+3. Util
+- 3-1. `constants`
+ - ์ฌ์ฉ๋๋ ๋งค์ง๋๋ฒ, ์๋ฌ๋ฉ์ธ์ง, ์
์ถ๋ ฅ ๋ฉ์์ง, ์ถ๋ ฅ ํ์ดํ ๋ฑ ์์ ์ ์
+- 3-2. `inputHandler`
+ - InputView ๋ด์์ ์
๋ ฅ์ ๋ฐ๋ ๋ก์ง ํธ๋ค๋ฌ ์ ์
+- 3-3. `parseInput`
+ - ๊ณ ๊ฐ์ ๋ฉ๋ด ์
๋ ฅ์ ๋ฉ๋ด ์ฃผ๋ฌธ ๋ฆฌ์คํธ ํํ๋ก ๋ณํํ๋ ํจ์ ์ ์
+- 3-4. `validateInput`
+ - ๊ณ ๊ฐ์ ์
๋ ฅ์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ ํจ์ ์ ์
+4. `App`
+ - ํ๋ก๋ชจ์
์ปจํธ๋กค๋ฌ ํด๋์ค๋ฅผ ์คํ์ํค๋ ์ ์ฒด
+5. `index`
+ - ๋ก์ง์ ์ํํ๋ App์ ์คํํ๋ ์ง์
์
+
+
+### ๊ตฌํ ๊ธฐ๋ฅ ์ ๋ฆฌ
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- [x] ์ด๋ฒคํธ ํ๋๋ ๋ฉํธ ์ถ๋ ฅ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง(์ผ) ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- [x] 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- [x] `<์ฃผ๋ฌธ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ ์ถ๋ ฅ
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- [x] `<์ฆ์ ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ดํ์ธ 1๊ฐ` ๋๋ `์์` ์ถ๋ ฅ
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- [x] `<ํํ ๋ด์ญ>` ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํ์ผ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํน๋ณ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅ
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<์ดํํ ๊ธ์ก>` ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก ์ถ๋ ฅ
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- [x] `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ์ถ๋ ฅ
+- [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง ์ถ๋ ฅ
+
+
+### ์ด๋ฒคํธ ์ ๋ฆฌ
+
+1-1. 2023.12.1 ~ 2023.12.25 ํ ์ธ
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - 12.1 ๊ธฐ์ค 1,000์ ํ ์ธ ~
+ - 12.25 ๊ธฐ์ค 3400์ ํ์ธ
+
+1-2. 2023.12.1 ~ 2023.12.31 ํ ์ธ
+
+- ํ์ผ ํ ์ธ (์ผ, ์, ํ, ์, ๋ชฉ)
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ (๊ธ, ํ )
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ (3(์ผ), 10(์ผ), 17(์ผ), 24(์ผ), 25(์), 31(์ผ))
+ - ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ 1000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - **ํ ์ธ ์ ์ด ์ฃผ๋ฌธ๊ธ์ก**์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+1-3. ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+
+- ์ด ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง
+ - ๋ฏธ์ถฉ์กฑ : ์์
+ - 5์ฒ์ ์ด์ : ๋ณ
+ - 1๋ง์ ์ด์ : ํธ๋ฆฌ
+ - 2๋ง์ ์ด์ : ์ฐํ
+
+1-4. ์ฃผ์ ์ฌํญ
+
+- 'ํ ์ธ'์ด๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง, ๊ธ์ก '์ฐจ๊ฐ'์ ๋ ๊ฐ๊น์. %๋ก ํ ์ธ์ด ์๋ - ํ์
+- ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ธ์ง ํ์ธํ๊ณ ์ด๋ฒคํธ ์ ์ฉ ํ์
+- ์๋ฃ๋ง, ์ฃผ๋ฌธ ์ ์ฃผ๋ฌธ ์์ฒด๊ฐ ๋ถ๊ฐ
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ ๊น์ง ์ฃผ๋ฌธ ๊ฐ๋ฅ
+
+
+### ํ๋ฆ ์ ๋ฆฌ
+
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- 1-1. ์ด๋ฒคํธ ํ๋๋ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 1-2. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง(์ผ)๋ฅผ ์ซ์๋ก๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+ -1-2-1. ์
๋ ฅ ๋ฐ์ ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- 2-1. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+- 2-2. `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ๋๋ค.
+ - 2-2-1. ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- 3-1. 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- 4-1. `<์ฃผ๋ฌธ๋ฉ๋ด>`๋ฅผ ์ถ๋ ฅํ๋ค.
+- 4-2. `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ์ `์ฃผ๋ฌธ ๋ฉ๋ด (๋ฉ๋ด๊ฐ์)๊ฐ\n` ๋ก ์ถ๋ ฅํ๋ค.
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- 5-1. `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ ์ถ๋ ฅํ๋ค.
+- 5-2. ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+ - 5-2-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- 6-1. `์ดํ์ธ (๊ฐ์)๊ฐ` ์ถ๋ ฅํ๋ค.
+ - 6-2-1. ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์ ๊ฒฝ์ฐ ๋น ์ดํ์ธ์ด 1๊ฐ์ฉ ์ฆ์ ๋๋ค.
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- 7-1. `<ํํ ๋ด์ญ>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 7-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 7-2. ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-3. ํ์ผ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-4. ํน๋ณ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-5. ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅํ๋ค.
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- 8-1. `<์ดํํ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 8-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 8-2. *7. ํํ๋ด์ญ ์ถ๋ ฅ* ์ `7-2 ~ 7-5` ์ ๊ธ์ก์ ๋ชจ๋ ๋ํด์ ์ถ๋ ฅํ๋ค.
+
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- 9-1. `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 9-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅํ๋ค.
+- 9-2. **5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ** ์์ **8. ์ด ํํ ๊ธ์ก ์ถ๋ ฅ** ์ ๋บ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- 10-1. `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 10-2. ์ถ๋ ฅํ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ฒฝ์ฐ `์์`์ ์ถ๋ ฅํ๋ค.
+
+
+### ๐ ํ์ผ ๊ตฌ์กฐ
+
+```
+โ src
+ โฃ Domain
+ โ โฃ PromotionController.js
+ โ โฃ Client.js
+ โ โ Discount.js
+ โฃ View
+ โ โฃ InputView.js
+ โ โ OutputView.js
+ โฃ Util
+ โ โฃ constants.js
+ โ โฃ parseInput.js
+ โ โฃ inputHandler.js
+ โ โ validateInput.js
+ โฃ App.js
+ โ index.js
+```
\ No newline at end of file | Unknown | ์ฒ์ ๊ธฐ๋ฅ ๊ตฌํ ๋ชฉ๋ก ์์ฑ์ ์ ํ๋ฆ์ ๋ฆฌ๋ฅผ ๋จผ์ ํ๋ ๋ฐฉ์์ผ๋ก 4์ฃผ๊ฐ ์งํํ์ด์ !! ์ด๋ ๋ญ ๊ตฌํํด์ผํ ์ง๊ฐ ์ ๋ณด์ฌ์ ๋์์ด ๋ง์ด ๋์๋ ๊ฑฐ ๊ฐ์์ ์ถ์ฒ๋๋ฆฝ๋๋ค ใ
ใ
|
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋ ์ง ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ๊ด๋ จ ์์๋ฅผ ์ ์ํด๋์ ๋ถ๋ค์ด ๋ง์ด ๋ณด์ด๋๋ผ๊ตฌ์ ! ์ ๋ ๊ด๋ จ๋ ๋ณ์๋ ์ ์ํ๋๊ฒ ์ข์ ๊ฑฐ ๊ฐ๋ค๊ณ ์๊ฐ์ด ๋๋ค์ ใ
ใ
์ถ์ฒ ๊ฐ์ฌํฉ๋๋ค ~ โบ๏ธ |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ์ค ๋ณ์ ์ ์ธ์ ๊ฐ๊ฒฐํ๊ฒ ํ ์ ์์ด์ ์ข์ ๋ฐฉ๋ฒ์ธ๊ฑฐ ๊ฐ์์ ๊ฐ์ฌํฉ๋๋ค ใ
ใ
!! |
@@ -0,0 +1,26 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0);
+
+ private final String name;
+ private final int limitPrice;
+
+ EventBadge(String name, int limitPrice) {
+ this.name = name;
+ this.limitPrice = limitPrice;
+ }
+
+ public static String findBadgeByTotalDiscount(int totalDiscount) {
+ return Arrays.stream(values())
+ .filter(badge -> totalDiscount >= badge.limitPrice)
+ .findFirst()
+ .orElse(NONE)
+ .name;
+ }
+} | Java | ์ด ๋ฉ์๋๋ EvenBadge์ ๋ฉค๋ฒ์ ์ ์ธ ์์์ ์์กด์ ์ธ ๊ฒ ๊ฐ์์. ๋ ์ข๊ฒ ๊ฐ์ ํ ๋ฐฉ๋ฒ์ ์์๊น์? |
@@ -0,0 +1,25 @@
+package christmas.config;
+
+public class Message {
+ public static final String INPUT_DATE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ public static final String INPUT_ORDER = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public static final String OUTPUT_VISIT_DATE = "12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n";
+ public static final String OUTPUT_MENU_TITLE = "\n<์ฃผ๋ฌธ ๋ฉ๋ด>";
+ public static final String OUTPUT_ITEM = "%s %d๊ฐ%n";
+ public static final String OUTPUT_WON = "%s์%n";
+ public static final String OUTPUT_MINUS_WON = "-" + OUTPUT_WON;
+ public static final String OUTPUT_TOTAL_PRICE = "%n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_GIFT_TITLE = "\n<์ฆ์ ๋ฉ๋ด>";
+ public static final String OUTPUT_PROMOTION_TITLE = "\n<ํํ ๋ด์ญ>";
+ public static final String OUTPUT_PROMOTION_ITEM = "%s: " + OUTPUT_MINUS_WON;
+ public static final String OUTPUT_TOTAL_DISCOUNT = "%n<์ดํํ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_PAYMENT_PRICE = "%n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_BADGE = "%n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>%n%s%n";
+ public static final String OUTPUT_NONE = "์์";
+
+
+ public static final String ERROR_MESSAGE_PREFIX = "[ERROR]";
+ public static final String ERROR_INPUT_DATE = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String ERROR_INPUT_ORDER = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+} | Java | ํ๋ก๊ทธ๋จ ์ ์ญ์์ ์ฌ์ฉํ์ง ์๊ณ Output์์๋ง ์ฌ์ฉํ๋ ๋ณ์๋ ๋ฐ๋ก ํด๋์ค๋ก ๋ง๋ค์ง ์๊ณ Output๊ฐ์ฒด ์์ ์์ ํ๋๋ก ์ ์ธํด๋ ์ข์ ๊ฒ ๊ฐ์์:smile:
์ถ๊ฐ์ ์ผ๋ก Message ์์ ์๋ฌ๋ฉ์์ง์ Output์์ ์ฌ์ฉํ๋ ์์๊ฐ ํผํฉ๋์ด ์์ด์ ๋ถ๋ฆฌํ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | MVC ํจํด์์ Controller๋ผ๋ฆฌ ์๋ก ์์กดํ๋ ๊ฒ์ ๋ณ๋ก ์ข์ง ์๋ค๊ณ ์๊ณ ์๋๋ฐ InputController๋ฅผ ๋ฐ๋ก ๋ง๋ค๊ณ PromotionController์์ ์ฌ์ฉํ ์ด์ ๊ฐ ๋ฐ๋ก ์์๊น์? |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | setOrder, setVisitDate ๊ฐ๊ฐ VisitDate, Order ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์๋ ๊ฒ ๊ฐ์์.
set์ด๋ผ๋ ์ ๋์ด๋ณด๋ค generate๊ฐ ์ข ๋ ์ด์ธ๋ฆฐ๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | ๋ฉ์๋ ๋ช
์ ๋ช
์ฌ๋ก ํ๋ ๊ฒ์ ๋ณ๋ก ์ข์ง ์์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,45 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.config.Gift;
+import christmas.config.Menu;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+public class GiftEvent implements DiscountEventInterface {
+ private final int totalPrice;
+
+ public GiftEvent(int totalPrice) {
+ this.totalPrice = totalPrice;
+ }
+
+ private Gift getGift() {
+ return Gift.getGift(totalPrice);
+ }
+
+ private String getGiftMenu() {
+ return getGift().getMenu();
+ }
+
+ @Override
+ public boolean isDiscountTarget() {
+ return !getGift().equals(Gift.NONE);
+ }
+
+ private int getGiftPrice() {
+ return Menu.getMenu(getGiftMenu())
+ .getPrice();
+ }
+
+ @Override
+ public Map<Event, Integer> getDiscountInfo() {
+ Map<Event, Integer> discountInfo = new EnumMap<>(Event.class);
+
+ if (isDiscountTarget()) {
+ discountInfo.put(Event.GIFT, getGiftPrice());
+ }
+
+ return discountInfo;
+ }
+} | Java | ์ด๋ฒคํธ๊ฐ ์ ๊ณตํ๋ ๊ณตํต๊ธฐ๋ฅ์ ์ธํฐํ์ด์ค๋ก ์ ๋ฝ์ ๊ฒ ๊ฐ์์:+1: |
@@ -0,0 +1,46 @@
+package christmas.model;
+
+import christmas.config.Menu;
+import christmas.config.MenuType;
+import christmas.util.Util;
+import christmas.util.validator.OrderGenerateAfterValidator;
+import christmas.util.validator.OrderGenerateBeforeValidator;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Order {
+ private final Map<Menu, Integer> order;
+
+ public Order(String order) {
+ new OrderGenerateBeforeValidator(order);
+ this.order = new OrderGenerator(order).generateOrder();
+ new OrderGenerateAfterValidator(this);
+ }
+
+ public int getTotalQuantity() {
+ return Util.intStreamSum(order.values().stream());
+ }
+
+ public int getMenuQuantity(MenuType menuType) {
+ return Util.intStreamSum(order.keySet()
+ .stream()
+ .filter(menu -> menu.getType() == menuType)
+ .map(order::get));
+ }
+
+ public int getTotalPrice() {
+ return Util.intStreamSum(order.entrySet()
+ .stream()
+ .map(entry -> entry.getKey().getPrice() * entry.getValue()));
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return order.entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ entry -> entry.getKey().getName(),
+ Map.Entry::getValue
+ ));
+ }
+} | Java | ์ ๋ String ๊ฐ์ ์
๋ ฅ๋ฐ์์ Order ๊ฐ์ฒด์์ ํ์ฑ์ ์งํํ๋๋ฐ ์ด ๋ถ๋ถ์ ๋ฐ๋ก OrderGenerator๋ผ๋ ๊ฐ์ฒด๋ก ๋ถ๋ฆฌํ๋๊น ๋ ์ข์ ๊ฒ ๊ฐ์์:+1: |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | Promotion์ด๋ผ๋ ํด๋์ค๋ช
์ ํด๋์ค๋ช
๋ง ๋ณด๊ณ ์ด๋ค ๊ธฐ๋ฅ์ ํ๋์ง ์ถ์ธกํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | ์ด ํํ ๊ธ์ก์ ๊ตฌํ๋ ๋ฉ์๋์ธ๋ฐ TotalDiscount๋ ์ด ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ ์๋ฏธ๊ฐ ๋ ๊ฐํ ๊ฒ ๊ฐ์์ ๋ฉ์๋ ์ด๋ฆ์ getTotalBenefitPrice๋ผ๋๊ฐ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋ฐ๊พธ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | setter๋ฅผ ์ด์ฉํด์ Promotion ๊ฐ์ฒด๊ฐ ๊ฐ์ง ์ํ๋ฅผ ์กฐ์ํ๋ ๊ฒ์ ๋ณ๋ก ๊ฐ์ฒด ์งํฅ์ ์ธ ์ค๊ณ๊ฐ ์๋ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ก Promotionํด๋์ค๋ฅผ ์์ฑํ๋ ์ญํ ์ ํ๋ ๊ฒ ๊ฐ๊ตฐ์.
์ ๋ Promotion์ ๊ตณ์ด ์์ฑํ์ง ์๊ณ ์ด ํด๋์ค์์ ๊ด๋ฆฌํ๋๊ฒ ๋ ์ข๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ ๊ฒ ์ค๊ณํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | 26๋ฒ ๋ผ์ธ ๋ถํฐ 44๋ฒ ๋ผ์ธ์ ๊ฐ๊ฐ์ ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ๊ณ ํํ ๊ธ์ก์ promotion๊ฐ์ฒด์ set ํด์ฃผ๋ ๊ฒ ๊ฐ์๋ฐ ์ด๋ถ๋ถ์ ์กฐ๊ธ ๋ ๊ฐ๋ตํ ํ ์ ์์ง ์์๊น์? |
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | ์ผ๋ฐ ์ ์ผ๋ก Controller์์๋ ๋์๋ง ์ ์ํ์ง ์ํ๋ ์ ์ํ์ง ์๋ ๊ฑธ๋ก ์๊ณ ์๋๋ฐ, PromotionController๋ Controller๋ณด๋ค๋ ๋๋ฉ์ธ์ค๋ฌ์ด(?)๊ฒ ๊ฐ์์ |
@@ -0,0 +1,26 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0);
+
+ private final String name;
+ private final int limitPrice;
+
+ EventBadge(String name, int limitPrice) {
+ this.name = name;
+ this.limitPrice = limitPrice;
+ }
+
+ public static String findBadgeByTotalDiscount(int totalDiscount) {
+ return Arrays.stream(values())
+ .filter(badge -> totalDiscount >= badge.limitPrice)
+ .findFirst()
+ .orElse(NONE)
+ .name;
+ }
+} | Java | ๋ฐ๊ตด์ด๋ ์ฝ๋ ๋ณด๊ณ ์๊ฒ๋์์ง๋ง Predicate ๋ฅผ ์ด์ฉํด์ ์กฐ๊ฑด์ ๊ฑธ์ด์ฃผ๋ฉด ์ข์์ ๊ฒ ๊ฐ์ต๋๋ค
ํจ์ํ ์ธํฐํ์ด์ค์ ๋ํ ๊ณต๋ถ๋ฅผ ํด์ผ๊ฒ ๋ค์! |
@@ -0,0 +1,25 @@
+package christmas.config;
+
+public class Message {
+ public static final String INPUT_DATE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ public static final String INPUT_ORDER = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public static final String OUTPUT_VISIT_DATE = "12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n";
+ public static final String OUTPUT_MENU_TITLE = "\n<์ฃผ๋ฌธ ๋ฉ๋ด>";
+ public static final String OUTPUT_ITEM = "%s %d๊ฐ%n";
+ public static final String OUTPUT_WON = "%s์%n";
+ public static final String OUTPUT_MINUS_WON = "-" + OUTPUT_WON;
+ public static final String OUTPUT_TOTAL_PRICE = "%n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_GIFT_TITLE = "\n<์ฆ์ ๋ฉ๋ด>";
+ public static final String OUTPUT_PROMOTION_TITLE = "\n<ํํ ๋ด์ญ>";
+ public static final String OUTPUT_PROMOTION_ITEM = "%s: " + OUTPUT_MINUS_WON;
+ public static final String OUTPUT_TOTAL_DISCOUNT = "%n<์ดํํ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_PAYMENT_PRICE = "%n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_BADGE = "%n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>%n%s%n";
+ public static final String OUTPUT_NONE = "์์";
+
+
+ public static final String ERROR_MESSAGE_PREFIX = "[ERROR]";
+ public static final String ERROR_INPUT_DATE = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String ERROR_INPUT_ORDER = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+} | Java | ์ถ๋ ฅ๋ถ๋ถ์ ๋ฉ์์ง ์์์ ๊ฒฝ์ฐ์๋ ๊ฐ๋ฐํ๋ฉด์ ํญ์ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์
๋๋ค. ์ฝ๋๋ฅผ ํ ๊ตฐ๋ฐ ๋ชจ์ ๊ฐ๋
์ฑ์ ๋์ผ์ง, ๋ถ๋ฆฌํด์ ๋ฉ์์ง๋ฅผ ์กฐ๊ธ๋ ์ ์ฐํ๊ฒ ์์ ๊ฐ๋ฅํ๊ฒ ํ ์ง ๊ณ ๋ฏผํ์ง๋ง ๋๋ถ๋ถ ์ถ๋ ฅ์์๋ ์ ํด์ง ๊ท๊ฒฉ์ ์ ์ ๋ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด์ค๋ค๊ณ ์๊ฐํ์ฌ ๋ณ๊ฒฝ๊ฐ๋ฅ์ฑ์ด ํฐ ๋ฉ์์ง ์์ฒด๋ฅผ ๋ถ๋ฆฌํ๋ ์ชฝ์ ์ ํํ์ต๋๋ค.
์ ๋ ๋ถ๋ฆฌํ๋๋ฐ ๋์ํฉ๋๋ค! ์ฒ์์๋ ์๋ฌ๋ฉ์์ง๋ฅผ ๋ค๋ฃจ๋ ํด๋์ค๋ฅผ ๋ณ๋๋ก ๋๊น ํ๋๋ฐ ์๊ฐ๋ณด๋ค ์ ์ ์๋ฌ๋ฉ์์ง ์ฌ์ฉ์ผ๋ก ์ด๋ฒ์๋ Message ํด๋์ค ๋ด์ ํฉ์ณ์ ์ฌ์ฉ์ ํ์ต๋๋ค! |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | ํจ์๋ช
์ง๊ธฐ์ ๊ด๋ จํด์๋ ์ด๋ฒ ํ๋ก์ ํธ์์ ๋ง์ด ๋ถ์กฑํ๋ค์... |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | ์ฒ์ ์ค๊ณ์์๋ Promotionํด๋์ค์์ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๊ณ ์ํ๋ฅผ ์ ์ฅํ๋ ํํ๋ฅผ ๊ฐ์ง๊ณ ์์๋๋ฐ
ํ์ ์ด์์ผ๋ก Promotionํด๋์ค๊ฐ ๋น๋ํด์ก๋ค๊ณ ์๊ฐ์ ํด์ ์ด๋ฅผ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๋ PromotionGeneratorํด๋์ค์ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ์ฒ๋ฆฌํ๋ Promotion ํด๋์ค๋ก ๋ถ๋ฆฌํ์ต๋๋ค. ์ด ๊ณผ์ ์์ Promotion์ ์ํ๋ฅผ ์กฐ์ํ๋ setter๋ฅผ ์ฌ์ฉํ๊ฒ ๋์๋๋ฐ ์คํ๋ ค ๊ฐ์ฒด ์งํฅ์ ์ด์ง ๋ชปํ ์ค๊ณ๊ฐ ๋์๋ค์ใ
ใ
|
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | MVCํจํด์ ๋ํ ๋ด์ฉ์ ํ๋ฆฌ์ฝ์ค๋ฅผ ์์ํ๋ฉด์ ์ ํ๋๋ฐ ์ํํ ์ง์์ด ์๋ชป๋ ์ฝ๋๋ฅผ ๋ง๋ค์๋ค์ ใ
ใ
;;
๋ค์ ๊ณต๋ถํด๋ณด๊ฒ ์ต๋๋ค! |
@@ -5,13 +5,15 @@
import com.somemore.domains.review.dto.response.ReviewDetailResponseDto;
import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto;
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
+import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
+import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -41,7 +43,7 @@ public ApiResponse<ReviewDetailResponseDto> getById(@PathVariable Long id) {
);
}
- @Operation(summary = "๊ธฐ๊ด๋ณ ๋ฆฌ๋ทฐ ์กฐํ", description = "๊ธฐ๊ด ID๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๋ทฐ ์กฐํ")
+ @Operation(summary = "ํน์ ๊ธฐ๊ด ๋ฆฌ๋ทฐ ์กฐํ", description = "๊ธฐ๊ด ID๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๋ทฐ ์กฐํ")
@GetMapping("/reviews/center/{centerId}")
public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByCenterId(
@PathVariable UUID centerId,
@@ -53,14 +55,34 @@ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByCenter
.pageable(pageable)
.build();
+ return ApiResponse.ok(
+ 200,
+ reviewQueryUseCase.getDetailsWithNicknameByCenterId(centerId, condition),
+ "ํน์ ๊ธฐ๊ด ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ ์ฑ๊ณต"
+ );
+ }
+
+ @Secured("ROLE_CENTER")
+ @Operation(summary = "๊ธฐ๊ด ๋ฆฌ๋ทฐ ์กฐํ", description = "๊ธฐ๊ด ์์ ์ ๋ฆฌ๋ทฐ ์กฐํ")
+ @GetMapping("/reviews/center/me")
+ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getMyCenterReviews(
+ @RoleId UUID centerId,
+ @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable,
+ @RequestParam(required = false) VolunteerCategory category
+ ) {
+ ReviewSearchCondition condition = ReviewSearchCondition.builder()
+ .category(category)
+ .pageable(pageable)
+ .build();
+
return ApiResponse.ok(
200,
reviewQueryUseCase.getDetailsWithNicknameByCenterId(centerId, condition),
"๊ธฐ๊ด ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ ์ฑ๊ณต"
);
}
- @Operation(summary = "๋ด์ฌ์ ๋ฆฌ๋ทฐ ์กฐํ", description = "๋ด์ฌ์ ID๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๋ทฐ ์กฐํ")
+ @Operation(summary = "ํน์ ๋ด์ฌ์ ๋ฆฌ๋ทฐ ์กฐํ", description = "๋ด์ฌ์ ID๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๋ทฐ ์กฐํ")
@GetMapping("/reviews/volunteer/{volunteerId}")
public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByVolunteerId(
@PathVariable UUID volunteerId,
@@ -75,7 +97,27 @@ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByVolunt
return ApiResponse.ok(
200,
reviewQueryUseCase.getDetailsWithNicknameByVolunteerId(volunteerId, condition),
- "์ ์ ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ ์ฑ๊ณต"
+ "ํน์ ๋ด์ฌ์ ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ ์ฑ๊ณต"
+ );
+ }
+
+ @Secured("ROLE_VOLUNTEER")
+ @Operation(summary = "๋ด์ฌ์ ๋ฆฌ๋ทฐ ์กฐํ", description = "๋ด์ฌ์ ์์ ์ ๋ฆฌ๋ทฐ ์กฐํ")
+ @GetMapping("/reviews/volunteer/me")
+ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getMyVolunteerReviews(
+ @RoleId UUID volunteerId,
+ @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable,
+ @RequestParam(required = false) VolunteerCategory category
+ ) {
+ ReviewSearchCondition condition = ReviewSearchCondition.builder()
+ .category(category)
+ .pageable(pageable)
+ .build();
+
+ return ApiResponse.ok(
+ 200,
+ reviewQueryUseCase.getDetailsWithNicknameByVolunteerId(volunteerId, condition),
+ "๋ด์ฌ์ ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ ์กฐํ ์ฑ๊ณต"
);
}
| Java | ๋น๋ ๋ก์ง์ ์ปจ๋์
ํด๋์ค์ of ์ ์ ๋ฉ์๋์์ ์งํํ๋ฉด ๋ ๊น๋ํ ๊ฒ ๊ฐ์์~
๊ตณ์ด ์์ ํ ํ์๋ ์๋ค๊ณ ์๊ฐํฉ๋๋ค! |
@@ -1,35 +1,34 @@
package com.somemore.domains.review.service;
-import com.somemore.domains.center.usecase.query.CenterQueryUseCase;
+import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW;
+
import com.somemore.domains.review.domain.Review;
import com.somemore.domains.review.dto.condition.ReviewSearchCondition;
import com.somemore.domains.review.dto.response.ReviewDetailResponseDto;
import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto;
import com.somemore.domains.review.repository.ReviewRepository;
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
-import com.somemore.domains.volunteer.domain.Volunteer;
-import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase;
+import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
import com.somemore.global.exception.NoSuchElementException;
+import com.somemore.volunteer.repository.record.VolunteerNicknameAndId;
+import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW;
-
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class ReviewQueryService implements ReviewQueryUseCase {
private final ReviewRepository reviewRepository;
- private final VolunteerQueryUseCase volunteerQueryUseCase;
- private final CenterQueryUseCase centerQueryUseCase;
+ private final NEWVolunteerQueryUseCase volunteerQueryUseCase;
+ private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase;
@Override
public boolean existsByVolunteerApplyId(Long volunteerApplyId) {
@@ -45,7 +44,9 @@ public Review getById(Long id) {
@Override
public ReviewDetailResponseDto getDetailById(Long id) {
Review review = getById(id);
- return ReviewDetailResponseDto.from(review);
+ Long recruitBoardId = volunteerApplyQueryUseCase.getRecruitBoardIdById(
+ review.getVolunteerApplyId());
+ return ReviewDetailResponseDto.of(review, recruitBoardId);
}
@Override
@@ -54,10 +55,11 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByVolunte
ReviewSearchCondition condition
) {
String nickname = volunteerQueryUseCase.getNicknameById(volunteerId);
- Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, condition);
+ Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId,
+ condition);
return reviews.map(
- review -> ReviewDetailWithNicknameResponseDto.from(review, nickname)
+ review -> ReviewDetailWithNicknameResponseDto.of(review, nickname)
);
}
@@ -66,28 +68,20 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByCenterI
UUID centerId,
ReviewSearchCondition condition
) {
- centerQueryUseCase.validateCenterExists(centerId);
-
Page<Review> reviews = reviewRepository.findAllByCenterIdAndSearch(centerId, condition);
List<UUID> volunteerIds = reviews.get().map(Review::getVolunteerId).toList();
- Map<UUID, String> volunteerNicknames = getVolunteerNicknames(volunteerIds);
+ Map<UUID, String> volunteerNicknames = mapVolunteerIdsToNicknames(volunteerIds);
- return reviews.map(
- review -> {
- String nickname = volunteerNicknames.getOrDefault(review.getVolunteerId(),
- "์ญ์ ๋ ์์ด๋");
- return ReviewDetailWithNicknameResponseDto.from(review, nickname);
- });
+ return reviews.map(review ->
+ ReviewDetailWithNicknameResponseDto.of(review,
+ volunteerNicknames.get(review.getVolunteerId()))
+ );
}
- private Map<UUID, String> getVolunteerNicknames(List<UUID> volunteerIds) {
- List<Volunteer> volunteers = volunteerQueryUseCase.getAllByIds(volunteerIds);
-
- Map<UUID, String> volunteerNicknames = new HashMap<>();
- for (Volunteer volunteer : volunteers) {
- volunteerNicknames.put(volunteer.getId(), volunteer.getNickname());
- }
-
- return volunteerNicknames;
+ private Map<UUID, String> mapVolunteerIdsToNicknames(List<UUID> volunteerIds) {
+ return volunteerQueryUseCase.getVolunteerNicknameAndIdsByIds(volunteerIds)
+ .stream()
+ .collect(Collectors.toMap(VolunteerNicknameAndId::id,
+ VolunteerNicknameAndId::nickname));
}
} | Java | ๋ฉ์๋๋ก ์ฝ๋๋ฅผ ํฌ์ฅํ๋ฉด ๊ฐ๋
์ฑ์ด ๋ ์ข์ ๊ฒ ๊ฐ์์~ |
@@ -1,35 +1,34 @@
package com.somemore.domains.review.service;
-import com.somemore.domains.center.usecase.query.CenterQueryUseCase;
+import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW;
+
import com.somemore.domains.review.domain.Review;
import com.somemore.domains.review.dto.condition.ReviewSearchCondition;
import com.somemore.domains.review.dto.response.ReviewDetailResponseDto;
import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto;
import com.somemore.domains.review.repository.ReviewRepository;
import com.somemore.domains.review.usecase.ReviewQueryUseCase;
-import com.somemore.domains.volunteer.domain.Volunteer;
-import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase;
+import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase;
import com.somemore.global.exception.NoSuchElementException;
+import com.somemore.volunteer.repository.record.VolunteerNicknameAndId;
+import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW;
-
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class ReviewQueryService implements ReviewQueryUseCase {
private final ReviewRepository reviewRepository;
- private final VolunteerQueryUseCase volunteerQueryUseCase;
- private final CenterQueryUseCase centerQueryUseCase;
+ private final NEWVolunteerQueryUseCase volunteerQueryUseCase;
+ private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase;
@Override
public boolean existsByVolunteerApplyId(Long volunteerApplyId) {
@@ -45,7 +44,9 @@ public Review getById(Long id) {
@Override
public ReviewDetailResponseDto getDetailById(Long id) {
Review review = getById(id);
- return ReviewDetailResponseDto.from(review);
+ Long recruitBoardId = volunteerApplyQueryUseCase.getRecruitBoardIdById(
+ review.getVolunteerApplyId());
+ return ReviewDetailResponseDto.of(review, recruitBoardId);
}
@Override
@@ -54,10 +55,11 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByVolunte
ReviewSearchCondition condition
) {
String nickname = volunteerQueryUseCase.getNicknameById(volunteerId);
- Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, condition);
+ Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId,
+ condition);
return reviews.map(
- review -> ReviewDetailWithNicknameResponseDto.from(review, nickname)
+ review -> ReviewDetailWithNicknameResponseDto.of(review, nickname)
);
}
@@ -66,28 +68,20 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByCenterI
UUID centerId,
ReviewSearchCondition condition
) {
- centerQueryUseCase.validateCenterExists(centerId);
-
Page<Review> reviews = reviewRepository.findAllByCenterIdAndSearch(centerId, condition);
List<UUID> volunteerIds = reviews.get().map(Review::getVolunteerId).toList();
- Map<UUID, String> volunteerNicknames = getVolunteerNicknames(volunteerIds);
+ Map<UUID, String> volunteerNicknames = mapVolunteerIdsToNicknames(volunteerIds);
- return reviews.map(
- review -> {
- String nickname = volunteerNicknames.getOrDefault(review.getVolunteerId(),
- "์ญ์ ๋ ์์ด๋");
- return ReviewDetailWithNicknameResponseDto.from(review, nickname);
- });
+ return reviews.map(review ->
+ ReviewDetailWithNicknameResponseDto.of(review,
+ volunteerNicknames.get(review.getVolunteerId()))
+ );
}
- private Map<UUID, String> getVolunteerNicknames(List<UUID> volunteerIds) {
- List<Volunteer> volunteers = volunteerQueryUseCase.getAllByIds(volunteerIds);
-
- Map<UUID, String> volunteerNicknames = new HashMap<>();
- for (Volunteer volunteer : volunteers) {
- volunteerNicknames.put(volunteer.getId(), volunteer.getNickname());
- }
-
- return volunteerNicknames;
+ private Map<UUID, String> mapVolunteerIdsToNicknames(List<UUID> volunteerIds) {
+ return volunteerQueryUseCase.getVolunteerNicknameAndIdsByIds(volunteerIds)
+ .stream()
+ .collect(Collectors.toMap(VolunteerNicknameAndId::id,
+ VolunteerNicknameAndId::nickname));
}
} | Java | ๋ณต์ํ ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋ |
@@ -0,0 +1,27 @@
+package christmas.domain.policy.discount;
+
+import christmas.domain.Orders;
+import christmas.domain.VisitDate;
+
+public class DdayDiscountPolicy implements DiscountPolicy {
+ public static final int CHRISTMAS_DATE = 25;
+ public static final int DISCOUNT_AMOUNT = 1000;
+ public static final int ADDITIONAL_DISCOUNT_AMOUNT = 100;
+ public static final int NOT_DISCOUNT_AMOUNT = 0;
+
+ @Override
+ public int discount(VisitDate visitDate, Orders orders) {
+ if (isNotAfter(visitDate)) {
+ return calculateDiscount(visitDate);
+ }
+ return NOT_DISCOUNT_AMOUNT;
+ }
+
+ private boolean isNotAfter(VisitDate visitDate) {
+ return visitDate.isNotAfter(CHRISTMAS_DATE);
+ }
+
+ private int calculateDiscount(VisitDate visitDate) {
+ return DISCOUNT_AMOUNT + visitDate.calculateDiscount(ADDITIONAL_DISCOUNT_AMOUNT);
+ }
+} | Java | DdayDiscountPolicy์ discount ๋ฉ์๋๊ฐ ๋จ๋
์ผ๋ก ์ฌ์ฉ๋ ์ ๋ ์๋๋ฐ ๋ง์ ์ดํ๋ฉด ์ ์ฉ์ด ๋ถ๊ฐ๋ฅํ๋ค๋ ์กฐ๊ฑด์ ์์ ํ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. DiscountPolicy๋ฅผ ์ถ์ํด๋์ค๋ก ํ์ฌ ๋ง์ ์ดํ ์ ์ฉ ๋ถ๊ฐ ์กฐ๊ฑด์ ๊ฑธ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | domain์ด ํน์ Dto์ ์ข
์๋๋ ๊ฒ์ ์ด๋ป๊ฒ ์๊ฐํ์๋์? ์ ๋ Dto๋ ๋ณ๋์ฑ์ด ํฐ ๊ฐ์ฒด๋ผ๊ณ ์๊ฐํด์ domain์ด ์์กดํ๋ ํํ๋ ์ข์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,36 @@
+package christmas.domain;
+
+import christmas.exception.NotExistsBadgeException;
+import java.util.Arrays;
+
+public enum Badge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0),
+ ;
+
+ private final String name;
+ private final int minimumAmount;
+
+ private Badge(String name, int minimumAmount) {
+ this.name = name;
+ this.minimumAmount = minimumAmount;
+ }
+
+ public static String getNameByBenefit(int amount) {
+ return from(amount).name;
+ }
+
+ public static Badge from(int amount) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.isGreaterThan(amount))
+ .findFirst()
+ .orElseThrow(NotExistsBadgeException::new);
+ }
+
+ private boolean isGreaterThan(int benefitAmount) {
+ return this.minimumAmount <= benefitAmount;
+ }
+}
+ | Java | enum์ ์์๊ฐ ๊ณ ์ ๋์ด์ผ ์ ์์คํ๋๋ ์ฝ๋๋ผ๊ณ ์๊ฐํฉ๋๋ค. ๋ค๋ฅธ ๋ฑ๊ธ์ด ์ถ๊ฐ๋๊ฑฐ๋ ํ์ ๋ ์ํฅ์ด ์๋๋ก minimumAmount๋ก ์ ๋ ฌ์ ํ๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,18 @@
+package christmas.domain;
+
+public enum DiscountType {
+ CHRISTMAS_DDAY("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY("ํ์ผ ํ ์ธ"),
+ WEEKEND("์ฃผ๋ง ํ ์ธ"),
+ SPECIAL("ํน๋ณ ํ ์ธ");
+
+ private final String name;
+
+ DiscountType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ด๋ฏธ Policies๋ก ํด๋์ค๋ณ ๊ตฌ๋ถ์ด ๋์ด ์๋๋ฐ enum์ผ๋ก ์ ๋ชฉ๋ง ๊ฐ์ง๊ณ ์์ ํ์๊ฐ ์์๊น์? ์ ๋ชฉ์ ๊ฐ Policy ๋ด๋ถ๋ก ๋ฃ๋ ๊ฒ๋ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | ์ ๋ ๋๊ฐํฉ๋๋ค ๐ค
์ฌ์ค ์ ๋ ๋๋ฉ์ธ์ toDto ๋ฉ์๋๋ฅผ ๋ง๋ค์ด์ ๊ตฌํํ๊ธด ํ์ด์
DTO์์๋ Mapper๋ฅผ ํตํด์๋ ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก DTO๋ฅผ ์์ฑํ๋ ค๋ฉด getter๋ฅผ ์ด์ด์ผ ํ๋๋ฐ getter๋ฅผ ์ต๋ํ ์ง์ํด๋ณผ๋ ค๊ณ ๊ทธ๋ ๊ฒ ํ์ต๋๋ค.
๊ทธ๋ฐ๋ฐ ํ๋ฆฌ์ฝ์ค๋ ๋ค๋ฅธ ๊ธ๋ค ๋ณด๋ ๋ง์ ๋ถ๋ค์ด ์ค์ํ ๊ฐ์ฒด๊ฐ(๋๋ฉ์ธ) ๋ ์ค์ํ ๊ฐ์ฒด(DTO)๋ฅผ ์์กดํ๋ ๊ฒ์ด ์ข์ง ์๋ค๊ณ ๋ง์ํ์๋๋ผ๊ณ ์ ๊ทธ๋์ ์ ๋ DTO์ ์์ฑ๋ฐฉ์์ ๋ํด์ ์๋กญ๊ฒ ๊ณ ๋ฏผํ๊ฒ ๋์๋ค์ |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | 10000์ ์ด์์ด์ฌ์ผ๋ง ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋๋ ๊ณตํต ์กฐ๊ฑด์ Bill์ ์์น์ํค์
จ๋ค์..!
ํด๋น ์กฐ๊ฑด์ด ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ ์ง ๋ง์ง๋ฅผ ์ ํ๋ค๋ ์ธก๋ฉด์์ Bill์ ์์นํ๊ธฐ์๋ ์ฑ
์์ด ๋ฒ์ด๋ ๋๋์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ฐ ์ด๋ฒคํธ๋ฅผ ํด๋์ค๋ก ๊ตฌํํ์ ๊ฒ ๊ฐ์๋ฐ 10000์ ์ด์์ธ์ง ๊ฒ์ฆํ๋ ์ฝ๋์ ์์น๋ DiscountPolicy๋ค์ ์์น์ํค์๋ ๊ฒ์ ์ด๋จ๊น์ ๐ค |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | ํ ์ธ๋ ๊ฐ๊ฒฉ์ ๊ตฌํ๋ ๋ฉ์๋์ ์์น๋ Orders๊ฐ ์ ์ ํ ๊น์ Bill์ด ์ ์ ํ ๊น์ ๐ค
์ ๋ ์ด๊ฒ์ ์ฐธ ๋ง์ด ๊ณ ๋ฏผํ๋๋ฐ์ ..! ์ ๋ Order์ ์์น์ํค๊ธด ํ๋๋ฐ ๊ด๋ จํด์ ํ๋๋ ์๊ฐ๋ ๊ถ๊ธํฉ๋๋ค!
๋ Orders๋ผ๋ ๋๋ฉ์ธ์ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๊ณ ์๋๋ฐ int๋ฅผ ๋ฐ๋ ๊ฒ์ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง๋ ๊ถ๊ธํด์ ๊ด๋ จํ ๊ธฐ์ค ๊ณต์ ํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค ๐๐ป |
@@ -0,0 +1,25 @@
+package christmas.domain;
+
+import java.util.Map;
+
+public class Discount {
+ private final DiscountType type;
+ private final int amount;
+
+ public Discount(DiscountType type, int amount) {
+ this.type = type;
+ this.amount = amount;
+ }
+
+ public boolean isDiscount() {
+ return amount != 0;
+ }
+
+ public int getAmount() {
+ return amount;
+ }
+
+ public String getName() {
+ return type.getName();
+ }
+} | Java | ํ ์ธ๋ด์ญ์ ํ ์ธ ์ข
๋ฅ์ ํ ์ธ ๊ธ์ก์ ์์ผ๋ก ์ ์ํ ์ ์๊ตฐ์ ๐๐ป
์ ๋ ๋น์ทํ๊ฒ ์์ฑํ์ง๋ง ์ ๋ String ํ์
์ description๊ณผ int amount๋ก ์์ฑํ๋ค์..
์ด๋ ๊ฒ ๋ณด๋ enum์ผ๋ก ๊ด๋ฆฌํ์ ๊ฒ ์ ๋ง ์ข์๋ณด์ด๋ค์ ์ธ์ธํ ์ฝ๋ ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค ๐๐ป ๐๐ป |
@@ -0,0 +1,25 @@
+package christmas.domain;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Discounts {
+ private final List<Discount> discounts;
+
+ public Discounts(List<Discount> discounts) {
+ this.discounts = discounts;
+ }
+
+ public int sumDiscount() {
+ return discounts.stream()
+ .mapToInt(Discount::getAmount)
+ .sum();
+ }
+
+ public Map<String, Integer> getResult() {
+ return discounts.stream()
+ .filter(Discount::isDiscount)
+ .collect(Collectors.toUnmodifiableMap(Discount::getName, Discount::getAmount));
+ }
+} | Java | ์ผ๊ธ ์ปฌ๋ ์
์ ์ถ์ถํ์๊ณ ๊ด๋ จ๋ ๋ก์ง๋ ๊น๋ํ๊ฒ ์ ๋ชจ์์ฃผ์ ๊ฒ ๊ฐ์์ ๐๐ป
์ข์๋ณด์
๋๋ค ๐ |
@@ -0,0 +1,21 @@
+package christmas.domain;
+
+public enum GiftType {
+ CHAMPAGNE("์ดํ์ธ", 25_000);
+
+ private final String name;
+ private final int price;
+
+ private GiftType(String name, int price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ public int calculatePrice(int quantity) {
+ return this.price * quantity;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ๋ฉ๋ด์ด๊ธฐ๋ ํ๋ฉด์ ์ฆ์ ํ์ด๊ธฐ๋ ํ ์ดํ์ธ์ GiftType์๋ ์์นํ๊ณ Menu์๋ ์์นํ๋ค์ ๐ค
๋ณ๊ฒฝ ์๊ตฌ์ฌํญ์ผ๋ก ์ดํ์ธ์ ํ๋งค๊ฐ๊ฒฉ์ด ์์ ๋๋ค๋ฉด ํด๋น ์์น๋ ์์ ๋์ด์ผ ํ ๊ฒ ๊ฐ์์ ์์ ์ง์ ์ด ํผ์ง๋ ๋ถ๋ถ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,57 @@
+package christmas.domain;
+
+import static christmas.domain.MenuType.APPETIZER;
+import static christmas.domain.MenuType.DESSERT;
+import static christmas.domain.MenuType.DRINK;
+import static christmas.domain.MenuType.MAIN;
+
+import christmas.exception.InvalidOrderException;
+import java.util.Arrays;
+
+public enum Menu {
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, APPETIZER),
+ TAPAS("ํํ์ค", 5_500, APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, APPETIZER),
+
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, MAIN),
+ BBQ_RIBS("๋ฐ๋นํ๋ฆฝ", 54_000, MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, MAIN),
+
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, DESSERT),
+
+ ZERO_COLA("์ ๋ก์ฝ๋ผ", 3_000, DRINK),
+ RED_WINE("๋ ๋์์ธ", 60_000, DRINK),
+ CHAMPAGNE("์ดํ์ธ", 25_000, DRINK);
+
+ private final String name;
+ private final int price;
+ private final MenuType type;
+
+ Menu(String menuName, int price, MenuType type) {
+ this.name = menuName;
+ this.price = price;
+ this.type = type;
+ }
+
+ public static Menu from(String menuName) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menuName.equals(menu.name))
+ .findFirst()
+ .orElseThrow(InvalidOrderException::new);
+ }
+
+ public boolean isEqualsMenuType(MenuType menuType) {
+ return this.type == menuType;
+ }
+
+ public int calculatePrice(int quantity) {
+ return this.price * quantity;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
+ | Java | ๊ฒํฐ๋ฅผ ์ต๋ํ ์ง์ํ์
จ๋ค์..! ์ ๋ ์ด๋ ๊ฒ ๊น์ง ์๊ฐ ๋ชปํด๋ณด๊ณ enum์๋ Getter๋ฅผ ์ ๋ถ ์ด์๋ค์ ๐ญ
์ข์๋ณด์
๋๋ค! ๐๐ป |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+import static christmas.exception.ErrorMessages.INVALID_ORDER;
+
+import christmas.utils.IntegerConverter;
+import christmas.exception.InvalidOrderException;
+
+public class Order {
+ public static final int MIN_ORDER_QUANTITY = 1;
+
+ private final Menu menu;
+ private final int quantity;
+
+ public Order(String menuName, String quantity) {
+ this.menu = Menu.from(menuName);
+ this.quantity = convertType(quantity);
+
+ validateMinQuantity();
+ }
+
+ private int convertType(String quantity) {
+ return IntegerConverter.convert(quantity, INVALID_ORDER);
+ }
+
+ private void validateMinQuantity() {
+ if (quantity < MIN_ORDER_QUANTITY) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ public boolean isEqualsMenuType(MenuType type) {
+ return menu.isEqualsMenuType(type);
+ }
+
+ public int calculatePrice() {
+ return menu.calculatePrice(quantity);
+ }
+
+ public String getMenuName() {
+ return menu.getName();
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public Menu getMenu() {
+ return menu;
+ }
+} | Java | String์ผ๋ก ๋ค์ด์จ quantity๋ฅผ ์ ์๋ก ์ปจ๋ฒํ
ํ๊ณ ์์ฑ์๋ฅผ ํตํด ํ ๋น์ด ๊ฐ๋ฅํ๋๋ก ๋ณํํด์ฃผ๋ ๋ถ๋ถ์ด๋ค์!
๋๋ฉ์ธ ๊ด๋ จ ๋ก์ง์ด ์๋์๋ Order ๋๋ฉ์ธ์ ์์นํ์ฌ Order ๋๋ฉ์ธ์ ์ฑ
์์ ํ๋ฆด ์๋ ์๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์ ๐ค ๋ณํ์ ์ธ๋ถ์์ ์ผ์ด๋๊ณ ์์ฑ์์ฒญ์ ๋ฐ์ ๋์๋ ์ ์ ๋ ์ํ๋ก ๋ฐ์์ผ ํ์ง ์๋๋ผ๋ ๊ฐ์ธ์ ์ธ ์๊ฐ์
๋๋ค ๐๐ป |
@@ -0,0 +1,104 @@
+package christmas.domain;
+
+import christmas.dto.OrdersDto;
+import christmas.exception.InvalidOrderException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class Orders {
+ public static final String ORDER_DELIMITER = ",";
+ public static final String MENU_AND_QUANTITY_DELIMITER = "-";
+ public static final int MAX_ORDER_QUANTITY = 20;
+
+ private final List<Order> orders;
+
+ public Orders(String orders) {
+ validateFormat(orders);
+ this.orders = createOrders(orders);
+
+ validateOverQuantity();
+ validateDuplicate();
+ validateAllDrink();
+ }
+
+ private List<Order> createOrders(String value) {
+ return getOrdersStream(value)
+ .map(order -> new Order(order[0], order[1]))
+ .toList();
+ }
+
+ private void validateFormat(String value) {
+ if (isInvalidFormat(value)) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ private boolean isInvalidFormat(String value) {
+ return getOrdersStream(value)
+ .anyMatch(order -> order.length != 2);
+ }
+
+ private Stream<String[]> getOrdersStream(String value) {
+ return Arrays.stream(value.split(ORDER_DELIMITER))
+ .map(order -> order.split(MENU_AND_QUANTITY_DELIMITER));
+ }
+
+ private void validateOverQuantity() {
+ if (sumOrderQuantity() > MAX_ORDER_QUANTITY) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ private int sumOrderQuantity() {
+ return orders.stream()
+ .mapToInt(Order::getQuantity)
+ .sum();
+ }
+
+ private void validateDuplicate() {
+ if (countUniqueOrderMenu() != orders.size()) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ private int countUniqueOrderMenu() {
+ return (int) orders.stream()
+ .map(Order::getMenu)
+ .distinct()
+ .count();
+ }
+
+ private void validateAllDrink() {
+ if (isAllDrinkMenu()) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ private boolean isAllDrinkMenu() {
+ return orders.stream()
+ .allMatch(order -> order.isEqualsMenuType(MenuType.DRINK));
+ }
+
+ public int getTotalPrice() {
+ return orders.stream()
+ .mapToInt(Order::calculatePrice)
+ .sum();
+ }
+
+ public int getQuantityByMenuType(MenuType type) {
+ return orders.stream()
+ .filter(order -> order.isEqualsMenuType(type))
+ .mapToInt(Order::getQuantity)
+ .sum();
+ }
+
+ public OrdersDto getOrders() {
+ Map<String, Integer> result = orders.stream()
+ .collect(Collectors.toUnmodifiableMap(Order::getMenuName, Order::getQuantity));
+
+ return new OrdersDto(result);
+ }
+} | Java | ๋ฐ๋ก ์์ ๋ง์ฐฌ๊ฐ์ง๋ก String์ ๊ธฐ๋ฐ์ผ๋ก ์์ฑํ๋ ค๊ณ ํ๋ค๋ณด๋ String์ splitํ๊ณ ๊ฐ์ ํ์ฑํ๋ ๋ฑ์ ์ฑ
์์ด Orders ๋๋ฉ์ธ์ ์์นํ๋๋ก ์ ๋ํ๊ณ ์๋ค์!
List<Order>๋ฅผ ๋ฐ์์ ๋ฐ๋ก ์์ฑํ๋๋ก ์ ๋ํ์๋ ๊ฒ๋ ์ข์๋ณด์
๋๋ค ๐ |
@@ -0,0 +1,48 @@
+package christmas.domain;
+
+import christmas.exception.InvalidDateException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.List;
+
+public class VisitDate {
+ private static final int YEAR = 2023;
+ public static final int MONTH = 12;
+ private static final int MIN_DATE = 1;
+ private static final int MAX_DATE = 31;
+
+ private final int date;
+
+ public VisitDate(int date) {
+ validateDateRange(date);
+ this.date = date;
+ }
+
+ private void validateDateRange(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw new InvalidDateException();
+ }
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate localDate = LocalDate.of(YEAR, MONTH, date);
+ return localDate.getDayOfWeek();
+ }
+
+ public boolean isContainDayOfDay(List<DayOfWeek> weekDay) {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ return weekDay.contains(dayOfWeek);
+ }
+
+ public boolean isEqualsDate(int date) {
+ return this.date == date;
+ }
+
+ public boolean isNotAfter(int date) {
+ return this.date <= date;
+ }
+
+ public int calculateDiscount(int discountAmount) {
+ return (date - 1) * discountAmount;
+ }
+} | Java | ์ฃผ๋ง์ธ์ง ํ์ผ์ธ์ง ๋ฌผ์ด๋ณด๊ธฐ ์ํด์ getDayOfWeek๋ฅผ ์ฌ์ฉํ์ ๊ฒ ๊ฐ์๋ฐ isWeekend()์ ๊ฐ์ ๋ฉ์๋๊ฐ TDA ์ธก๋ฉด์์ ์ข์๋ณด์ธ๋ค๋ ์๊ฐ์
๋๋ค ๐ |
@@ -0,0 +1,27 @@
+package christmas.domain.policy.discount;
+
+import christmas.domain.Orders;
+import christmas.domain.VisitDate;
+
+public class DdayDiscountPolicy implements DiscountPolicy {
+ public static final int CHRISTMAS_DATE = 25;
+ public static final int DISCOUNT_AMOUNT = 1000;
+ public static final int ADDITIONAL_DISCOUNT_AMOUNT = 100;
+ public static final int NOT_DISCOUNT_AMOUNT = 0;
+
+ @Override
+ public int discount(VisitDate visitDate, Orders orders) {
+ if (isNotAfter(visitDate)) {
+ return calculateDiscount(visitDate);
+ }
+ return NOT_DISCOUNT_AMOUNT;
+ }
+
+ private boolean isNotAfter(VisitDate visitDate) {
+ return visitDate.isNotAfter(CHRISTMAS_DATE);
+ }
+
+ private int calculateDiscount(VisitDate visitDate) {
+ return DISCOUNT_AMOUNT + visitDate.calculateDiscount(ADDITIONAL_DISCOUNT_AMOUNT);
+ }
+} | Java | ์ถ์ ํด๋์ค ์ ํ ๋๋ฌด ์ข์ ์์ด๋์ด์ธ๊ฑฐ ๊ฐ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ข ๋ ์ฐพ์๋ณด๋ ์ธํฐํ์ด์ค์ default ๋ฉ์๋๋ฅผ ๊ตฌํํ ์ ์๋๋ผ๊ตฌ์. ์ธํฐํ์ด์ค default ๋ฉ์๋๋ฅผ ๊ตฌํํด ์กฐ๊ฑด์ ๊ฒ์ฌํ ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์ธํฐํ์ด์ค์ ์ฅ์ ๋ ๊ฐ์ ธ๊ฐ๊ณ , ์กฐ๊ฑด ๊ฒ์ฌ์ ์ฑ
์๋ ๋ถ์ฌํ ์ ์์๊ฑฐ ๊ฐ๋ค์. ๋ฆฌ๋ทฐ ๋๋ถ์ ์ถ์ ํด๋์ค, ์ธํฐํ์ด์ค์ ๋ํด ์ฐพ์๋ณด๊ณ ๊ณต๋ถํ ์ ์์์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค ๐ |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | > Dto๋ ๋ณ๋์ฑ์ด ํฐ ๊ฐ์ฒด๋ผ๊ณ ์๊ฐํด์ domain์ด ์์กดํ๋ ํํ๋ ์ข์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
> ์ค์ํ ๊ฐ์ฒด๊ฐ(๋๋ฉ์ธ) ๋ ์ค์ํ ๊ฐ์ฒด(DTO)๋ฅผ ์์กดํ๋ ๊ฒ์ด ์ข์ง ์๋ค
๋๋ฌด ๊ณต๊ฐ๋๋ ๋ด์ฉ์ด๋ค์! ํ์ฌ๋ DTO์ Domain์ ๊ฐํ ๊ฒฐํฉ๋๋ก ์ธํด DTO ๋ณ๊ฒฝ ์ Domain ์ฝ๋๋ฅผ ์์ ํด์ผํ๋ค๋ ๋ฌธ์ ๊ฐ ์๋๊ฑฐ ๊ฐ์์. Domain์์๋ DTO ์์ฑ์ ํ์ํ ๊ฐ์ ๋ฐํํ๊ณ , Controller์์ DTO๋ฅผ ์์ฑํ๋ ๊ฒ์ด ์ข์๊ฑฐ ๊ฐ๋ค์!!! ๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,36 @@
+package christmas.domain;
+
+import christmas.exception.NotExistsBadgeException;
+import java.util.Arrays;
+
+public enum Badge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0),
+ ;
+
+ private final String name;
+ private final int minimumAmount;
+
+ private Badge(String name, int minimumAmount) {
+ this.name = name;
+ this.minimumAmount = minimumAmount;
+ }
+
+ public static String getNameByBenefit(int amount) {
+ return from(amount).name;
+ }
+
+ public static Badge from(int amount) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.isGreaterThan(amount))
+ .findFirst()
+ .orElseThrow(NotExistsBadgeException::new);
+ }
+
+ private boolean isGreaterThan(int benefitAmount) {
+ return this.minimumAmount <= benefitAmount;
+ }
+}
+ | Java | ์ด ๋ถ๋ถ์ ๊ณ ๋ ค ํด๋ณด์ง ๋ชปํ๋ค์ ๐ฎ ํ์ฌ Enum์ minimumAmount ๋ด๋ฆผ์ฐจ์์ผ๋ก ์์๋ฅผ ์ ์ธํ๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ์์ง๋ง, ์ถํ ๋ค๋ฅธ ์ฌ๋์ด ํด๋น ์ฝ๋์ ๋ํ ์ถ๊ฐ์ ์ธ ๊ตฌํ์ ํ๋ ๊ฒฝ์ฐ ์์ ์ ์ธ ๊ท์น์ ์ธ์งํ์ง ๋ชปํ ์ ์์๊ฑฐ ๊ฐ๋ค์. @Arachneee ๋ง์์ฒ๋ผ ์ด๋ ํ ์ํฉ์์๋ ์ฝ๋์ ๋์์ ๋ช
ํํ๊ฒ ํ๊ธฐ ์ํด ์ ๋ ฌํ๋ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค. ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,18 @@
+package christmas.domain;
+
+public enum DiscountType {
+ CHRISTMAS_DDAY("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY("ํ์ผ ํ ์ธ"),
+ WEEKEND("์ฃผ๋ง ํ ์ธ"),
+ SPECIAL("ํน๋ณ ํ ์ธ");
+
+ private final String name;
+
+ DiscountType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ ๋ ๊ฐ DiscountPolicy ๊ตฌํ์ฒด์์ ํ ์ธ ์ ๋ชฉ์ ๋ฐํํ๋ ๊ตฌ์กฐ๋ฅผ ์๊ฐํด๋ดค๋๋ฐ, ์ด ๊ตฌ์กฐ๋ DiscountPolicy์ ํ ์ธ ์ ๋ชฉ์ด ์ผ๋์ผ๋ก ๋งคํ๋๊ธฐ ๋๋ฌธ์ DiscountPolicy๋ฅผ ์ฌ๋ฌ ํ ์ธ์์ ์ฌ์ฌ์ฉํ ์ ์๋ค๋ ๋จ์ ์ด ์์์ต๋๋ค. ์ถํ ์ถ๊ฐ๋ ์ ์๋ ์๊ตฌ์ฌํญ์ ๊ณ ๋ คํ์ ๋ ํ์ฅ์ฑ ๋ฉด์์ ์ข์ง ์์๊ฒ์ด๋ผ ์๊ฐํด DiscountPolicy์ ํ ์ธ ์ ๋ชฉ์ ๋ฐ๋ก ๊ด๋ฆฌํ์ต๋๋ค. ํ์ง๋ง, ์ด๋ค ์ฝ๋๊ฐ ๋ ์ข์ ์ฝ๋์ธ์ง ์ ๋ต์ ์๋๊ฑฐ ๊ฐ์์. ์ด๋ฒ ๋ฏธ์
์ ์งํํ๋ฉฐ ์๊ตฌ์ฌํญ ํ์ฅ์ ์ผ๋ง๋ ๊ณ ๋ คํด์ผํ ์ง์ ๋ํ ๊ณ ๋ฏผ์ด ๋ง์๊ธฐ์ ์ ์๊ฐ์ ํ ๋ฒ ๊ณต์ ๋๋ ค๋ด
๋๋ค!
์ถ๊ฐ๋ก, Enum์ผ๋ก ํ ์ธ ์ข
๋ฅ๋ฅผ ํ ๊ณณ์์ ๊ด๋ฆฌํ๋ ๊ฒ์ด ๊ฐ๋
์ฑ ๋ฉด์์ ๋ ์ข๋ค๊ณ ์๊ฐํ์ด์. ๋ํ, ํ ์ธ ์ ๋ชฉ์ String์ผ๋ก ๊ด๋ฆฌํ๋ฉด ์๋ชป๋ ๊ฐ์ด ๋ค์ด๊ฐ ์ ์๊ธฐ ๋๋ฌธ์ Enum์ ์ฌ์ฉํ์ต๋๋ค. ๐ |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | @Libienz ๋ง์์ฒ๋ผ Bill๋ ์ฃผ๋ฌธ์ ๋ํ ํ ์ธ ๋ด์ญ์ ๊ฐ๋ ๊ฐ์ฒด์ธ๋ฐ ํด๋น ๊ฐ์ฒด์์ ํ ์ธ ์กฐ๊ฑด์ ๊ฒ์ฌํ๋ ๊ฒ์ ๋ง์ ์ฑ
์์ ๊ฐ๊ณ ์๋๊ฑฐ ๊ฐ๋ค๋ ์๊ฐ์ด ๋๋ค์. DiscountPolicy์ default ๋ฉ์๋๋ก ์กฐ๊ฑด์ ๊ฒ์ฌํ๋ ๊ฒ์ด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค ๐ |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | Bill ๊ฐ์ฒด๋ Order์ Discount, Gift ๊ฐ์ฒด ์ฌ์ด์ ํ๋ ฅ์ ์ํ ์ค๊ฐ ๊ฐ์ฒด๋ก, ์ฃผ๋ฌธ์ ๋ํ ํ ์ธ ํํ์ ๋ฐํํ๊ธฐ ์ํด ์ค๊ณํ์ด์. ๋ฐ๋ผ์, ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ๋ํ ๊ณ์ฐ์ Bill ๊ฐ์ฒด์ ์ฑ
์์ด๋ผ๊ณ ์๊ฐํ์ต๋๋ค. ์ฝ๋๋ฅผ ๋ค์ ์ดํด๋ณด๋ ์๋์ ๊ฐ์ด Order ๊ฐ์ฒด์ ํ ์ธ ๊ธ์ก์ ๋๊ฒจ์ค์ผ๋ก์จ Order ๊ฐ์ฒด ๋ด๋ถ์์ ํ ์ธ๋ ๊ฐ๊ฒฉ์ ๋ฐํํ๋ ๋ฐฉ๋ฒ๋ ์์๊ฑฐ ๊ฐ์ต๋๋ค. ์๋ ์ฝ๋๊ฐ ๋ ๊ฐ์ฒด๊ฐ ๋ฉ์์ง๋ฅผ ์ฃผ๊ณ ๋ฐ์ผ๋ฉฐ ํ๋ ฅํ๋ ๊ตฌ์กฐ๋ผ๊ณ ์๊ฐ๋๋ค์. ๋๋ถ์ ๋ ๋์ ์ฝ๋๋ก ๋ฆฌํฉํ ๋ง ํ ์ ์๊ฒ ๋์๋ค์ ๊ฐ์ฌํฉ๋๋ค ๐ถ
```java
public int getDiscountPrice(Orders orders) {
int discount = discounts.sumDiscount();
return orders.getDiscountPrice(discount);
}
```
๊ทธ๋ฆฌ๊ณ , Bill ๊ฐ์ฒด๋ ์ค๊ฐ ๊ฐ์ฒด์ด๊ธฐ ๋๋ฌธ์ Orders ๋๋ฉ์ธ์ ์์๋ ๋๋ค๊ณ ์๊ฐํ์ด์. ๋ง์ฝ, Orders๊ฐ ์๋ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ์ธ์๋ก ๋ฐ๋๋ค๋ฉด ์ธ๋ถ์์ getTotalPrice ๋ฉ์๋๋ฅผ ํธ์ถํด์ผํ๋๋ฐ, ์ธ๋ถ์์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ์๊ณ ์์ด์ผ ํ ๊น? ๋ผ๋ ์๋ฌธ์ด ๋ค์์ต๋๋ค. ๋ฐ๋ผ์, Restaurant ๊ฐ์ฒด๋ ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ๋ฐ๊ธฐ๋ง ํ๊ณ , ์ด๋ฅผ Bill ๊ฐ์ฒด์๊ฒ ํ ์ธ๋ ๊ฐ๊ฒฉ์ ์๋ ค์ค ~ ๋ผ๊ณ ์ฑ
์์ ์์ํ๋ ๊ฒ์ด ๋ ๊ฐ์ฒด์งํฅ์ค๋ฝ๋ค๊ณ ์๊ฐํ์ด์. @Libienz ๋ฆฌ๋ทฐ๋ฅผ ํตํด ์ ์ฝ๋์ ๋ํ ๊ทผ๊ฑฐ๋ฅผ ๋ค์ ํ๋ฒ ์๊ฐํด๋ณผ ์ ์์๋ค์ ๊ฐ์ฌํฉ๋๋ค !!!! |
@@ -0,0 +1,50 @@
+package christmas.domain;
+
+import static christmas.exception.ErrorMessages.INVALID_ORDER;
+
+import christmas.utils.IntegerConverter;
+import christmas.exception.InvalidOrderException;
+
+public class Order {
+ public static final int MIN_ORDER_QUANTITY = 1;
+
+ private final Menu menu;
+ private final int quantity;
+
+ public Order(String menuName, String quantity) {
+ this.menu = Menu.from(menuName);
+ this.quantity = convertType(quantity);
+
+ validateMinQuantity();
+ }
+
+ private int convertType(String quantity) {
+ return IntegerConverter.convert(quantity, INVALID_ORDER);
+ }
+
+ private void validateMinQuantity() {
+ if (quantity < MIN_ORDER_QUANTITY) {
+ throw new InvalidOrderException();
+ }
+ }
+
+ public boolean isEqualsMenuType(MenuType type) {
+ return menu.isEqualsMenuType(type);
+ }
+
+ public int calculatePrice() {
+ return menu.calculatePrice(quantity);
+ }
+
+ public String getMenuName() {
+ return menu.getName();
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public Menu getMenu() {
+ return menu;
+ }
+} | Java | @Libienz ๋ฆฌ๋ทฐ์ ์ ๊ทน ๊ณต๊ฐํ๋ ๋ฐ์
๋๋ค! ์
๋ ฅ์ ๋ํ ํ์์ View ๊ณ์ธต์์ ๊ฒ์ฆํ๋ ๊ฒ์ด ๋ ์ข๋ค๊ณ ์๊ฐ๋๋ค์. ํ์ฌ๋ ์
๋ ฅ๊ฐ์ ๊ทธ๋๋ก ์์ฑ์ ์ธ์๋ก ์ ๋ฌํ๊ธฐ ๋๋ฌธ์ ๋๋ฉ์ธ ๊ฐ์ฒด ๋ด๋ถ์์ ํ์์ ๋ง์ถฐ ๊ฐ์ ํ์ฑํ๋ ๋ก์ง์ ์ํํ๊ณ ์์ด์. @Libienz ๋ง์์ฒ๋ผ ์ด๋ฌํ ๊ตฌ์กฐ๋ ๋๋ฉ์ธ์ ์ฑ
์์ ํ๋ฆด ์ ์๋ค๊ณ ์๊ฐํด์. ์ถ๊ฐ๋ก, ํ์ฑ ๋ก์ง์ ์ํด ๋๋ฉ์ธ ๋ก์ง์ ํ ๋์ ํ์
ํ ์ ์๋ค๋ ๋จ์ ์ด ์์๊ฑฐ ๊ฐ์์.
๊ทผํฌ๋ ์ฝ๋๋ฅผ ๋ณด๋ ์
๋ ฅ๊ฐ์ ๋ํ ํ์ ๊ฒ์ฆ ๋ฐ ํ์ฑ ๊ฐ์ฒด๊ฐ ๋ถ๋ฆฌ๋์ด ์๋๋ผ๊ตฌ์. ์ ๋ง ์ธ์๊น๊ฒ ๋ดค์ต๋๋ค. ์ ๋ ์์ผ๋ก๋ View ๊ณ์ธต์ผ๋ก ํด๋น ๋ก์ง์ ๋ถ๋ฆฌํด ๋ณผ ์๊ฐ์
๋๋ค. ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค ๐๐ป |
@@ -0,0 +1,48 @@
+package christmas.domain;
+
+import christmas.exception.InvalidDateException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.List;
+
+public class VisitDate {
+ private static final int YEAR = 2023;
+ public static final int MONTH = 12;
+ private static final int MIN_DATE = 1;
+ private static final int MAX_DATE = 31;
+
+ private final int date;
+
+ public VisitDate(int date) {
+ validateDateRange(date);
+ this.date = date;
+ }
+
+ private void validateDateRange(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw new InvalidDateException();
+ }
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate localDate = LocalDate.of(YEAR, MONTH, date);
+ return localDate.getDayOfWeek();
+ }
+
+ public boolean isContainDayOfDay(List<DayOfWeek> weekDay) {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ return weekDay.contains(dayOfWeek);
+ }
+
+ public boolean isEqualsDate(int date) {
+ return this.date == date;
+ }
+
+ public boolean isNotAfter(int date) {
+ return this.date <= date;
+ }
+
+ public int calculateDiscount(int discountAmount) {
+ return (date - 1) * discountAmount;
+ }
+} | Java | ์ ์ด ๋ฉ์๋๋ VisitDate ๋ด๋ถ์์๋ง ์ฌ์ฉํ๋ ๋ฉ์๋์ธ๋ฐ ์ ๊ทผ ์ ํ์๋ฅผ ์๋ชป ์ค์ ํ๊ตฐ์ .. ์ธ์ธํ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | ์์ฐ ๋๋ฉ์ธ๊ณผ ์ฑ
์๊ณผ ์ญํ ์ ๋ํด์ ๊น์ ๊ณ ๋ฏผ์ ํ์ ๊ฒ์ด ๋๊ปด์ง๋ค์.. ๐๐ป ๐๐ป ์ฑ
์๊ณผ ์ญํ ์ ๋ถ๋ฆฌํ๊ณ ๋ถ์ฌํ๋ ๊ฒ์ ์ ๋ ์ต์์น๊ฐ ์์๋ฐ ์ ์ฑ์ค๋ฌ์ด ๋ต๋ณ ์ฃผ์
์ ์ ๋ ์ ๋ง์ ๊ธฐ์ค์ ํ๋ฒ ๊ฒํ ํด๋ณด์์ผ๊ฒ ๋ค๋ ์๊ฐ์ด ๋๋ค์ ๐ |
@@ -0,0 +1,55 @@
+package christmas.controller;
+
+import static christmas.utils.RepeatReader.repeatRead;
+
+import christmas.domain.Bill;
+import christmas.domain.Orders;
+import christmas.domain.Restaurant;
+import christmas.domain.VisitDate;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class EventController {
+ private final Restaurant restaurant;
+ private final InputView inputView;
+ private final OutputView outputView;
+
+ public EventController(Restaurant restaurant, InputView inputView, OutputView outputView) {
+ this.restaurant = restaurant;
+ this.inputView = inputView;
+ this.outputView = outputView;
+ }
+
+ public void run() {
+ VisitDate visitDate = repeatRead(this::readDate);
+ Orders orders = repeatRead(this::readOrders);
+
+ Bill bill = restaurant.order(visitDate, orders);
+
+ printOrders(orders);
+ printBill(bill, orders);
+ }
+
+ private VisitDate readDate() {
+ int date = inputView.readDate();
+ return new VisitDate(date);
+ }
+
+ private Orders readOrders() {
+ String orders = inputView.readOrders();
+ return new Orders(orders);
+ }
+
+ private void printOrders(Orders orders) {
+ outputView.printOrders(orders.getOrders());
+ outputView.printPrice(orders.getTotalPrice());
+ }
+
+ private void printBill(Bill bill, Orders orders) {
+ outputView.printGifts(bill.getGiftDto());
+ outputView.printBenefit(bill.getBenefitDto());
+ outputView.printBenefitAmount(bill.getTotalBenefit(orders));
+ outputView.printDiscountPrice(bill.getDiscountPrice(orders));
+ outputView.printBadge(bill.getBadgeName());
+ }
+} | Java | ์ฐ์.. ์ ๋ฐ์ ์ผ๋ก ์ฝ๋ ํ๋ฆ์ด ์ ์ฝํ๋ค์..!!
ํ ์ธ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋ ํจ์์ ์ด๋ฆ์ ์ด๋ป๊ฒ ํด์ผํ ๊น ๊ณ ๋ฏผ์ ๋ง์ด ํ๋๋ฐ, printBill()์ด๋ผ๋ ์ด๋ฆ์ ๋ณด๋
๋จธ๋ฆฌ์ ๋ง์น๋ฅผ ํ ๋ ๋ง์ ๊ฒ ๊ฐ์ต๋๋ค.. ๐ |
@@ -0,0 +1,84 @@
+import { Console } from '@woowacourse/mission-utils';
+import { PROMOTION_CATEGORIES } from '../constant/index.js';
+
+const MESSAGE = {
+ GREETINGS: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.',
+ INTRO_PREVIEW: '12์ 26์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n',
+ ORDER_MENU_TITLE: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ TOTAL_PRICE_WITHOUT_DISCOUNT_TITLE: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ BENEFIT_DETAILS_TITLE: '<ํํ ๋ด์ญ>',
+ TOTAL_PRICE_WITH_DISCOUNT_TITLE: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT_TITLE: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT_TOTAL_PRICE_TITLE: '<์ดํํ ๊ธ์ก>',
+ BADGE_TITLE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ NONE: '์์',
+ MENU: (name, count) => `${name} ${count}๊ฐ`,
+ PRICE: (price) => `${price.toLocaleString()}์`,
+ GIFT: (name, count) => `${name} ${count}๊ฐ`,
+ DISCOUNT: (name, price) => `${name} ํ ์ธ: -${price.toLocaleString()}์`,
+ TOTAL_BENEFIT_PRICE: (price) => (price > 0 ? `-${price.toLocaleString()}์` : '0์'),
+};
+
+const OutputView = {
+ printGreetings() {
+ Console.print(MESSAGE.GREETINGS);
+ },
+ printPreviewMessage() {
+ Console.print(MESSAGE.INTRO_PREVIEW);
+ Console.print('');
+ },
+ printOrderMenus(orders) {
+ Console.print(MESSAGE.ORDER_MENU_TITLE);
+
+ orders.forEach((order) => {
+ Console.print(MESSAGE.MENU(order.name, order.count));
+ });
+
+ Console.print('');
+ },
+ printTotalPriceWithoutDiscount(totalPrice) {
+ Console.print(MESSAGE.TOTAL_PRICE_WITHOUT_DISCOUNT_TITLE);
+ Console.print(MESSAGE.PRICE(totalPrice));
+ Console.print('');
+ },
+ printBenefitDetails(promotions) {
+ Console.print(MESSAGE.BENEFIT_DETAILS_TITLE);
+
+ const printData = [];
+
+ promotions.forEach((promotion) => {
+ const { NAME, promotionBenefitPrice } = promotion;
+ const isApplied = promotionBenefitPrice > 0;
+ if (isApplied) printData.push(MESSAGE.DISCOUNT(NAME, promotionBenefitPrice));
+ });
+ if (printData.length === 0) printData.push(MESSAGE.NONE);
+
+ Console.print(printData.join('\n'));
+ Console.print('');
+ },
+ printTotalPriceWithDiscount(totalPriceWithDiscount) {
+ Console.print(MESSAGE.TOTAL_PRICE_WITH_DISCOUNT_TITLE);
+ Console.print(MESSAGE.PRICE(totalPriceWithDiscount));
+ Console.print('');
+ },
+ printGiveWayMenu(promotions) {
+ const giftMenu = promotions.find((promotion) => promotion.EVENT === PROMOTION_CATEGORIES.GIFT);
+ const { PRODUCT, promotionBenefitPrice } = giftMenu;
+ const isApplied = promotionBenefitPrice > 0;
+
+ Console.print(MESSAGE.GIFT_TITLE);
+ Console.print(isApplied ? MESSAGE.GIFT(PRODUCT.NAME, 1) : MESSAGE.NONE);
+ Console.print('');
+ },
+ printTotalBenefitPrice(totalBenefitPrice) {
+ Console.print(MESSAGE.BENEFIT_TOTAL_PRICE_TITLE);
+ Console.print(MESSAGE.TOTAL_BENEFIT_PRICE(totalBenefitPrice));
+ Console.print('');
+ },
+ printBadge(badge) {
+ Console.print(MESSAGE.BADGE_TITLE);
+ Console.print(badge);
+ },
+};
+
+export default OutputView; | JavaScript | ์ ๋ ์ด ๋ถ๋ถ ์ค์ํ๋๋ฐ, ์ผ์๊ฐ ๋ฐ๋์ด์ ์ถ๋ ฅ๋๋๋ก ํด์ผํด์..ใ
ใ
|
@@ -0,0 +1,126 @@
+import { isDuplicate, isEveryInclude, isMoreThanLimit, isNotMatchRegex, isSomeNotInclude } from '../util/index.js';
+import { LIMIT_ORDER_COUNT, MENU_CATEGORIES, MENUS, ORDER_REGEX } from '../constant/index.js';
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ IS_INVALID_ORDER: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+const { INVALID_DATE, IS_INVALID_ORDER } = ERROR_MESSAGE;
+
+class Order {
+ static validateOrder(orderMenus) {
+ const validators = [
+ () => Order.validateDuplicationOrder(orderMenus),
+ () => Order.validateOrderMenuFormat(orderMenus, ORDER_REGEX.ORDER_FORMAT),
+ () => Order.validateLimitOrderCount(orderMenus, LIMIT_ORDER_COUNT),
+ () => Order.validateIncludeMenu(orderMenus, MENUS),
+ () => Order.validateOrderOnlyOneCategory(orderMenus, MENUS, MENU_CATEGORIES.BEVERAGE),
+ ];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateDate(date) {
+ const validators = [() => Order.validateDayFormat(date, ORDER_REGEX.DAY_FORMAT)];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateOrderOnlyOneCategory(orderMenus, menus, category) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameListForCategory = Object.values(menus)
+ .filter((menu) => menu.CATEGORY === category)
+ .map((menu) => menu.NAME);
+
+ isEveryInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameListForCategory);
+ }
+ static validateIncludeMenu(orderMenus, menus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameList = Object.values(menus).map((menu) => menu.NAME);
+
+ isSomeNotInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameList);
+ }
+ static validateDuplicationOrder(orderMenus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+
+ isDuplicate(IS_INVALID_ORDER, orderMenuNameList);
+ }
+ static validateLimitOrderCount(orderMenus, limitOrderCount) {
+ const { totalOrderCount } = Order.parseOrders(orderMenus);
+
+ isMoreThanLimit(IS_INVALID_ORDER, totalOrderCount, limitOrderCount);
+ }
+ static validateOrderMenuFormat(orderMenus, regex) {
+ const { orderMenuList } = Order.parseOrders(orderMenus);
+
+ orderMenuList.forEach((orderMenu) => isNotMatchRegex(IS_INVALID_ORDER, orderMenu, regex));
+ }
+ static validateDayFormat(date, regex) {
+ isNotMatchRegex(INVALID_DATE, date, regex);
+ }
+ static parseOrders(orderMenu) {
+ const orderMenuList = orderMenu.split(',').map((menu) => menu.trim());
+ const orderMenuNameList = orderMenuList.map((menu) => menu.split('-')[0]);
+ const orderMenuCountList = orderMenuList.map((menu) => menu.split('-')[1]);
+ const totalOrderCount = orderMenuCountList.reduce((acc, cur) => acc + Number(cur), 0);
+
+ return {
+ orderMenuList,
+ orderMenuNameList,
+ orderMenuCountList,
+ totalOrderCount,
+ };
+ }
+
+ #orderDate;
+ #orderMenus = new Map();
+ #menus = new Map();
+
+ constructor(menus, orderMenus, orderDate) {
+ this.#menus = new Map(Object.entries(menus));
+ this.#orderDate = orderDate;
+ this.#setOrderMenus(orderMenus);
+ }
+
+ getOrderMenuList() {
+ return this.#getOrderMenuCategories()
+ .map((categoryName) => this.getOrderMenuByCategory(categoryName))
+ .flat();
+ }
+ getTotalPrice() {
+ return Array.from(this.#orderMenus.values()).reduce((acc, orderMenu) => {
+ const key = this.#getKeyByMenuName(orderMenu.name);
+ const menu = this.#menus.get(key);
+ return acc + menu.PRICE * orderMenu.count;
+ }, 0);
+ }
+ getOrderDate() {
+ return this.#orderDate;
+ }
+ getOrderMenuByCategory(categoryName) {
+ return Array.from(this.#orderMenus.values()).filter((orderMenu) => orderMenu.category === categoryName);
+ }
+ #setOrderMenus(orderMenus) {
+ const { orderMenuNameList, orderMenuCountList } = Order.parseOrders(orderMenus);
+
+ orderMenuNameList.forEach((menuName, index) => {
+ const category = this.#getCategoryByMenuName(menuName);
+ const key = this.#getKeyByMenuName(menuName);
+
+ this.#orderMenus.set(key, {
+ name: menuName,
+ count: orderMenuCountList[index],
+ category,
+ });
+ });
+ }
+ #getOrderMenuCategories() {
+ return Array.from(new Set(Array.from(this.#menus.values()).map((menu) => menu.CATEGORY)));
+ }
+ #getCategoryByMenuName(menuName) {
+ return Array.from(this.#menus.values()).find((menuMap) => menuMap.NAME === menuName).CATEGORY;
+ }
+ #getKeyByMenuName(menuName) {
+ return Array.from(this.#menus.keys()).find((key) => this.#menus.get(key).NAME === menuName);
+ }
+}
+export default Order; | JavaScript | Input์ ๋ํ ๋ชจ๋ ์ ํจ์ฑ ๊ฒ์ฆ์ Order ๋๋ฉ์ธ์์ ์ฒ๋ฆฌํ๊ณ ๊ณ์ ๋ฐ ์ด๋ ๊ฒ ๊ตฌํํ์ ์ด์ ๊ฐ ๊ถ๊ธํด์.
๊ณตํต ํผ๋๋ฐฑ์์ ๊ตฌํ ์์์ ๋ํ ์ด์ผ๊ธฐ๊ฐ ์๋๋ฐ,
์ด ํด๋์ค๋ ํ๋-์์ฑ์-๋ฉ์๋ ์์ผ๋ก ๊ตฌํ๋์ด์์ง ์์์ ์ด ๋ถ๋ถ์ ๊ฐ์ ํด์ผ ํ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,126 @@
+import { isDuplicate, isEveryInclude, isMoreThanLimit, isNotMatchRegex, isSomeNotInclude } from '../util/index.js';
+import { LIMIT_ORDER_COUNT, MENU_CATEGORIES, MENUS, ORDER_REGEX } from '../constant/index.js';
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ IS_INVALID_ORDER: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+const { INVALID_DATE, IS_INVALID_ORDER } = ERROR_MESSAGE;
+
+class Order {
+ static validateOrder(orderMenus) {
+ const validators = [
+ () => Order.validateDuplicationOrder(orderMenus),
+ () => Order.validateOrderMenuFormat(orderMenus, ORDER_REGEX.ORDER_FORMAT),
+ () => Order.validateLimitOrderCount(orderMenus, LIMIT_ORDER_COUNT),
+ () => Order.validateIncludeMenu(orderMenus, MENUS),
+ () => Order.validateOrderOnlyOneCategory(orderMenus, MENUS, MENU_CATEGORIES.BEVERAGE),
+ ];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateDate(date) {
+ const validators = [() => Order.validateDayFormat(date, ORDER_REGEX.DAY_FORMAT)];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateOrderOnlyOneCategory(orderMenus, menus, category) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameListForCategory = Object.values(menus)
+ .filter((menu) => menu.CATEGORY === category)
+ .map((menu) => menu.NAME);
+
+ isEveryInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameListForCategory);
+ }
+ static validateIncludeMenu(orderMenus, menus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameList = Object.values(menus).map((menu) => menu.NAME);
+
+ isSomeNotInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameList);
+ }
+ static validateDuplicationOrder(orderMenus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+
+ isDuplicate(IS_INVALID_ORDER, orderMenuNameList);
+ }
+ static validateLimitOrderCount(orderMenus, limitOrderCount) {
+ const { totalOrderCount } = Order.parseOrders(orderMenus);
+
+ isMoreThanLimit(IS_INVALID_ORDER, totalOrderCount, limitOrderCount);
+ }
+ static validateOrderMenuFormat(orderMenus, regex) {
+ const { orderMenuList } = Order.parseOrders(orderMenus);
+
+ orderMenuList.forEach((orderMenu) => isNotMatchRegex(IS_INVALID_ORDER, orderMenu, regex));
+ }
+ static validateDayFormat(date, regex) {
+ isNotMatchRegex(INVALID_DATE, date, regex);
+ }
+ static parseOrders(orderMenu) {
+ const orderMenuList = orderMenu.split(',').map((menu) => menu.trim());
+ const orderMenuNameList = orderMenuList.map((menu) => menu.split('-')[0]);
+ const orderMenuCountList = orderMenuList.map((menu) => menu.split('-')[1]);
+ const totalOrderCount = orderMenuCountList.reduce((acc, cur) => acc + Number(cur), 0);
+
+ return {
+ orderMenuList,
+ orderMenuNameList,
+ orderMenuCountList,
+ totalOrderCount,
+ };
+ }
+
+ #orderDate;
+ #orderMenus = new Map();
+ #menus = new Map();
+
+ constructor(menus, orderMenus, orderDate) {
+ this.#menus = new Map(Object.entries(menus));
+ this.#orderDate = orderDate;
+ this.#setOrderMenus(orderMenus);
+ }
+
+ getOrderMenuList() {
+ return this.#getOrderMenuCategories()
+ .map((categoryName) => this.getOrderMenuByCategory(categoryName))
+ .flat();
+ }
+ getTotalPrice() {
+ return Array.from(this.#orderMenus.values()).reduce((acc, orderMenu) => {
+ const key = this.#getKeyByMenuName(orderMenu.name);
+ const menu = this.#menus.get(key);
+ return acc + menu.PRICE * orderMenu.count;
+ }, 0);
+ }
+ getOrderDate() {
+ return this.#orderDate;
+ }
+ getOrderMenuByCategory(categoryName) {
+ return Array.from(this.#orderMenus.values()).filter((orderMenu) => orderMenu.category === categoryName);
+ }
+ #setOrderMenus(orderMenus) {
+ const { orderMenuNameList, orderMenuCountList } = Order.parseOrders(orderMenus);
+
+ orderMenuNameList.forEach((menuName, index) => {
+ const category = this.#getCategoryByMenuName(menuName);
+ const key = this.#getKeyByMenuName(menuName);
+
+ this.#orderMenus.set(key, {
+ name: menuName,
+ count: orderMenuCountList[index],
+ category,
+ });
+ });
+ }
+ #getOrderMenuCategories() {
+ return Array.from(new Set(Array.from(this.#menus.values()).map((menu) => menu.CATEGORY)));
+ }
+ #getCategoryByMenuName(menuName) {
+ return Array.from(this.#menus.values()).find((menuMap) => menuMap.NAME === menuName).CATEGORY;
+ }
+ #getKeyByMenuName(menuName) {
+ return Array.from(this.#menus.keys()).find((key) => this.#menus.get(key).NAME === menuName);
+ }
+}
+export default Order; | JavaScript | ์ง๊ธ ์ด menus๋ ์์ ๊ฐ์ฒด MENUS์ธ๋ฐ ๋ค์ Map์ผ๋ก ๋ง๋์ ์ด์ ๊ฐ ๊ถ๊ธํด์.
MENUS์ ํค๊ฐ์ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ผ๋ก ๊ฐ์ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,126 @@
+import { isDuplicate, isEveryInclude, isMoreThanLimit, isNotMatchRegex, isSomeNotInclude } from '../util/index.js';
+import { LIMIT_ORDER_COUNT, MENU_CATEGORIES, MENUS, ORDER_REGEX } from '../constant/index.js';
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ IS_INVALID_ORDER: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+const { INVALID_DATE, IS_INVALID_ORDER } = ERROR_MESSAGE;
+
+class Order {
+ static validateOrder(orderMenus) {
+ const validators = [
+ () => Order.validateDuplicationOrder(orderMenus),
+ () => Order.validateOrderMenuFormat(orderMenus, ORDER_REGEX.ORDER_FORMAT),
+ () => Order.validateLimitOrderCount(orderMenus, LIMIT_ORDER_COUNT),
+ () => Order.validateIncludeMenu(orderMenus, MENUS),
+ () => Order.validateOrderOnlyOneCategory(orderMenus, MENUS, MENU_CATEGORIES.BEVERAGE),
+ ];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateDate(date) {
+ const validators = [() => Order.validateDayFormat(date, ORDER_REGEX.DAY_FORMAT)];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateOrderOnlyOneCategory(orderMenus, menus, category) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameListForCategory = Object.values(menus)
+ .filter((menu) => menu.CATEGORY === category)
+ .map((menu) => menu.NAME);
+
+ isEveryInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameListForCategory);
+ }
+ static validateIncludeMenu(orderMenus, menus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameList = Object.values(menus).map((menu) => menu.NAME);
+
+ isSomeNotInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameList);
+ }
+ static validateDuplicationOrder(orderMenus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+
+ isDuplicate(IS_INVALID_ORDER, orderMenuNameList);
+ }
+ static validateLimitOrderCount(orderMenus, limitOrderCount) {
+ const { totalOrderCount } = Order.parseOrders(orderMenus);
+
+ isMoreThanLimit(IS_INVALID_ORDER, totalOrderCount, limitOrderCount);
+ }
+ static validateOrderMenuFormat(orderMenus, regex) {
+ const { orderMenuList } = Order.parseOrders(orderMenus);
+
+ orderMenuList.forEach((orderMenu) => isNotMatchRegex(IS_INVALID_ORDER, orderMenu, regex));
+ }
+ static validateDayFormat(date, regex) {
+ isNotMatchRegex(INVALID_DATE, date, regex);
+ }
+ static parseOrders(orderMenu) {
+ const orderMenuList = orderMenu.split(',').map((menu) => menu.trim());
+ const orderMenuNameList = orderMenuList.map((menu) => menu.split('-')[0]);
+ const orderMenuCountList = orderMenuList.map((menu) => menu.split('-')[1]);
+ const totalOrderCount = orderMenuCountList.reduce((acc, cur) => acc + Number(cur), 0);
+
+ return {
+ orderMenuList,
+ orderMenuNameList,
+ orderMenuCountList,
+ totalOrderCount,
+ };
+ }
+
+ #orderDate;
+ #orderMenus = new Map();
+ #menus = new Map();
+
+ constructor(menus, orderMenus, orderDate) {
+ this.#menus = new Map(Object.entries(menus));
+ this.#orderDate = orderDate;
+ this.#setOrderMenus(orderMenus);
+ }
+
+ getOrderMenuList() {
+ return this.#getOrderMenuCategories()
+ .map((categoryName) => this.getOrderMenuByCategory(categoryName))
+ .flat();
+ }
+ getTotalPrice() {
+ return Array.from(this.#orderMenus.values()).reduce((acc, orderMenu) => {
+ const key = this.#getKeyByMenuName(orderMenu.name);
+ const menu = this.#menus.get(key);
+ return acc + menu.PRICE * orderMenu.count;
+ }, 0);
+ }
+ getOrderDate() {
+ return this.#orderDate;
+ }
+ getOrderMenuByCategory(categoryName) {
+ return Array.from(this.#orderMenus.values()).filter((orderMenu) => orderMenu.category === categoryName);
+ }
+ #setOrderMenus(orderMenus) {
+ const { orderMenuNameList, orderMenuCountList } = Order.parseOrders(orderMenus);
+
+ orderMenuNameList.forEach((menuName, index) => {
+ const category = this.#getCategoryByMenuName(menuName);
+ const key = this.#getKeyByMenuName(menuName);
+
+ this.#orderMenus.set(key, {
+ name: menuName,
+ count: orderMenuCountList[index],
+ category,
+ });
+ });
+ }
+ #getOrderMenuCategories() {
+ return Array.from(new Set(Array.from(this.#menus.values()).map((menu) => menu.CATEGORY)));
+ }
+ #getCategoryByMenuName(menuName) {
+ return Array.from(this.#menus.values()).find((menuMap) => menuMap.NAME === menuName).CATEGORY;
+ }
+ #getKeyByMenuName(menuName) {
+ return Array.from(this.#menus.keys()).find((key) => this.#menus.get(key).NAME === menuName);
+ }
+}
+export default Order; | JavaScript | ์ ๊ฐ ์ ๋ชป ์ฐพ๋ ๊ฑด์ง ๋ชจ๋ฅด๊ฒ ๋๋ฐ, ์ด orderDate๋ Order ๋๋ฉ์ธ ๋ด์์ ์ฌ์ฉ๋๋ ๋ก์ง์ด ์๋ ๊ฒ ๊ฐ์์.
์ญํ ์ ๋ถ๋ฆฌํด์ผ ํ ๊ฒ ๊ฐ๋ค๊ณ ๋๊ปด์ง๋๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ๊ถ๊ธํด์..! |
@@ -0,0 +1,126 @@
+import { isDuplicate, isEveryInclude, isMoreThanLimit, isNotMatchRegex, isSomeNotInclude } from '../util/index.js';
+import { LIMIT_ORDER_COUNT, MENU_CATEGORIES, MENUS, ORDER_REGEX } from '../constant/index.js';
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ IS_INVALID_ORDER: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+const { INVALID_DATE, IS_INVALID_ORDER } = ERROR_MESSAGE;
+
+class Order {
+ static validateOrder(orderMenus) {
+ const validators = [
+ () => Order.validateDuplicationOrder(orderMenus),
+ () => Order.validateOrderMenuFormat(orderMenus, ORDER_REGEX.ORDER_FORMAT),
+ () => Order.validateLimitOrderCount(orderMenus, LIMIT_ORDER_COUNT),
+ () => Order.validateIncludeMenu(orderMenus, MENUS),
+ () => Order.validateOrderOnlyOneCategory(orderMenus, MENUS, MENU_CATEGORIES.BEVERAGE),
+ ];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateDate(date) {
+ const validators = [() => Order.validateDayFormat(date, ORDER_REGEX.DAY_FORMAT)];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateOrderOnlyOneCategory(orderMenus, menus, category) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameListForCategory = Object.values(menus)
+ .filter((menu) => menu.CATEGORY === category)
+ .map((menu) => menu.NAME);
+
+ isEveryInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameListForCategory);
+ }
+ static validateIncludeMenu(orderMenus, menus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameList = Object.values(menus).map((menu) => menu.NAME);
+
+ isSomeNotInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameList);
+ }
+ static validateDuplicationOrder(orderMenus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+
+ isDuplicate(IS_INVALID_ORDER, orderMenuNameList);
+ }
+ static validateLimitOrderCount(orderMenus, limitOrderCount) {
+ const { totalOrderCount } = Order.parseOrders(orderMenus);
+
+ isMoreThanLimit(IS_INVALID_ORDER, totalOrderCount, limitOrderCount);
+ }
+ static validateOrderMenuFormat(orderMenus, regex) {
+ const { orderMenuList } = Order.parseOrders(orderMenus);
+
+ orderMenuList.forEach((orderMenu) => isNotMatchRegex(IS_INVALID_ORDER, orderMenu, regex));
+ }
+ static validateDayFormat(date, regex) {
+ isNotMatchRegex(INVALID_DATE, date, regex);
+ }
+ static parseOrders(orderMenu) {
+ const orderMenuList = orderMenu.split(',').map((menu) => menu.trim());
+ const orderMenuNameList = orderMenuList.map((menu) => menu.split('-')[0]);
+ const orderMenuCountList = orderMenuList.map((menu) => menu.split('-')[1]);
+ const totalOrderCount = orderMenuCountList.reduce((acc, cur) => acc + Number(cur), 0);
+
+ return {
+ orderMenuList,
+ orderMenuNameList,
+ orderMenuCountList,
+ totalOrderCount,
+ };
+ }
+
+ #orderDate;
+ #orderMenus = new Map();
+ #menus = new Map();
+
+ constructor(menus, orderMenus, orderDate) {
+ this.#menus = new Map(Object.entries(menus));
+ this.#orderDate = orderDate;
+ this.#setOrderMenus(orderMenus);
+ }
+
+ getOrderMenuList() {
+ return this.#getOrderMenuCategories()
+ .map((categoryName) => this.getOrderMenuByCategory(categoryName))
+ .flat();
+ }
+ getTotalPrice() {
+ return Array.from(this.#orderMenus.values()).reduce((acc, orderMenu) => {
+ const key = this.#getKeyByMenuName(orderMenu.name);
+ const menu = this.#menus.get(key);
+ return acc + menu.PRICE * orderMenu.count;
+ }, 0);
+ }
+ getOrderDate() {
+ return this.#orderDate;
+ }
+ getOrderMenuByCategory(categoryName) {
+ return Array.from(this.#orderMenus.values()).filter((orderMenu) => orderMenu.category === categoryName);
+ }
+ #setOrderMenus(orderMenus) {
+ const { orderMenuNameList, orderMenuCountList } = Order.parseOrders(orderMenus);
+
+ orderMenuNameList.forEach((menuName, index) => {
+ const category = this.#getCategoryByMenuName(menuName);
+ const key = this.#getKeyByMenuName(menuName);
+
+ this.#orderMenus.set(key, {
+ name: menuName,
+ count: orderMenuCountList[index],
+ category,
+ });
+ });
+ }
+ #getOrderMenuCategories() {
+ return Array.from(new Set(Array.from(this.#menus.values()).map((menu) => menu.CATEGORY)));
+ }
+ #getCategoryByMenuName(menuName) {
+ return Array.from(this.#menus.values()).find((menuMap) => menuMap.NAME === menuName).CATEGORY;
+ }
+ #getKeyByMenuName(menuName) {
+ return Array.from(this.#menus.keys()).find((key) => this.#menus.get(key).NAME === menuName);
+ }
+}
+export default Order; | JavaScript | ๋ฉ์๋๋ง๋ค ๊ฐํ์ ๋ฃ์ด์ฃผ์๋ฉด ๊ฐ๋
์ฑ์ด ๋์์ง ๊ฒ ๊ฐ์์. |
@@ -1,5 +1,42 @@
+import { InputView, OutputView } from './view/index.js';
+import { MENUS, PROMOTION_MONTH, PROMOTION_YEAR } from './constant/index.js';
+import { Order, Planner, PromotionCalendar, Promotions } from './model/index.js';
+
class App {
- async run() {}
+ async run() {
+ OutputView.printGreetings();
+ const { order, planner } = await this.reserve();
+ OutputView.printPreviewMessage();
+ await this.preview(order, planner);
+ }
+
+ async reserve() {
+ const orderDate = await InputView.readOrderDate((input) => Order.validateDate(input));
+ const orderMenu = await InputView.readOrderMenus((input) => Order.validateOrder(input));
+ const order = new Order(MENUS, orderMenu, orderDate);
+ const planner = new Planner(order, new PromotionCalendar(PROMOTION_YEAR, PROMOTION_MONTH, Promotions));
+
+ return {
+ order,
+ planner,
+ };
+ }
+
+ async preview(order, planner) {
+ const orderMenuList = order.getOrderMenuList();
+ const totalPriceWithoutDiscount = order.getTotalPrice();
+ const promotions = planner.getPromotionsByOrderDate();
+ const totalBenefitPrice = planner.getTotalBenefitPrice();
+ const totalPriceWithDiscount = planner.getTotalPriceWithDiscount();
+ const badge = planner.getBadge();
+ OutputView.printOrderMenus(orderMenuList);
+ OutputView.printTotalPriceWithoutDiscount(totalPriceWithoutDiscount);
+ OutputView.printGiveWayMenu(promotions);
+ OutputView.printBenefitDetails(promotions);
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPriceWithDiscount(totalPriceWithDiscount);
+ OutputView.printBadge(badge);
+ }
}
export default App; | JavaScript | ์ง๊ทนํ ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ธ๋ฐ, ๋ฉ์๋๋ช
์ '์์ฝ'์ด๋ผ๊ณ ์ง์ผ์
จ๋๋ฐ oderDate๋ ์กฐ๊ธ ํผ๋์ ์ค ์ ์๋ ๊ฒ ๊ฐ์์.
'๋ฐฉ๋ฌธ'์ด๋ '์์ฝ'์ผ๋ก ๋ณ๊ฒฝํ์๋ ๊ฒ ์ด๋จ๊น์..? |
@@ -0,0 +1,126 @@
+import { isDuplicate, isEveryInclude, isMoreThanLimit, isNotMatchRegex, isSomeNotInclude } from '../util/index.js';
+import { LIMIT_ORDER_COUNT, MENU_CATEGORIES, MENUS, ORDER_REGEX } from '../constant/index.js';
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ IS_INVALID_ORDER: '์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+const { INVALID_DATE, IS_INVALID_ORDER } = ERROR_MESSAGE;
+
+class Order {
+ static validateOrder(orderMenus) {
+ const validators = [
+ () => Order.validateDuplicationOrder(orderMenus),
+ () => Order.validateOrderMenuFormat(orderMenus, ORDER_REGEX.ORDER_FORMAT),
+ () => Order.validateLimitOrderCount(orderMenus, LIMIT_ORDER_COUNT),
+ () => Order.validateIncludeMenu(orderMenus, MENUS),
+ () => Order.validateOrderOnlyOneCategory(orderMenus, MENUS, MENU_CATEGORIES.BEVERAGE),
+ ];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateDate(date) {
+ const validators = [() => Order.validateDayFormat(date, ORDER_REGEX.DAY_FORMAT)];
+
+ validators.forEach((validator) => validator());
+ }
+ static validateOrderOnlyOneCategory(orderMenus, menus, category) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameListForCategory = Object.values(menus)
+ .filter((menu) => menu.CATEGORY === category)
+ .map((menu) => menu.NAME);
+
+ isEveryInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameListForCategory);
+ }
+ static validateIncludeMenu(orderMenus, menus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+ const menuNameList = Object.values(menus).map((menu) => menu.NAME);
+
+ isSomeNotInclude(IS_INVALID_ORDER, orderMenuNameList, menuNameList);
+ }
+ static validateDuplicationOrder(orderMenus) {
+ const { orderMenuNameList } = Order.parseOrders(orderMenus);
+
+ isDuplicate(IS_INVALID_ORDER, orderMenuNameList);
+ }
+ static validateLimitOrderCount(orderMenus, limitOrderCount) {
+ const { totalOrderCount } = Order.parseOrders(orderMenus);
+
+ isMoreThanLimit(IS_INVALID_ORDER, totalOrderCount, limitOrderCount);
+ }
+ static validateOrderMenuFormat(orderMenus, regex) {
+ const { orderMenuList } = Order.parseOrders(orderMenus);
+
+ orderMenuList.forEach((orderMenu) => isNotMatchRegex(IS_INVALID_ORDER, orderMenu, regex));
+ }
+ static validateDayFormat(date, regex) {
+ isNotMatchRegex(INVALID_DATE, date, regex);
+ }
+ static parseOrders(orderMenu) {
+ const orderMenuList = orderMenu.split(',').map((menu) => menu.trim());
+ const orderMenuNameList = orderMenuList.map((menu) => menu.split('-')[0]);
+ const orderMenuCountList = orderMenuList.map((menu) => menu.split('-')[1]);
+ const totalOrderCount = orderMenuCountList.reduce((acc, cur) => acc + Number(cur), 0);
+
+ return {
+ orderMenuList,
+ orderMenuNameList,
+ orderMenuCountList,
+ totalOrderCount,
+ };
+ }
+
+ #orderDate;
+ #orderMenus = new Map();
+ #menus = new Map();
+
+ constructor(menus, orderMenus, orderDate) {
+ this.#menus = new Map(Object.entries(menus));
+ this.#orderDate = orderDate;
+ this.#setOrderMenus(orderMenus);
+ }
+
+ getOrderMenuList() {
+ return this.#getOrderMenuCategories()
+ .map((categoryName) => this.getOrderMenuByCategory(categoryName))
+ .flat();
+ }
+ getTotalPrice() {
+ return Array.from(this.#orderMenus.values()).reduce((acc, orderMenu) => {
+ const key = this.#getKeyByMenuName(orderMenu.name);
+ const menu = this.#menus.get(key);
+ return acc + menu.PRICE * orderMenu.count;
+ }, 0);
+ }
+ getOrderDate() {
+ return this.#orderDate;
+ }
+ getOrderMenuByCategory(categoryName) {
+ return Array.from(this.#orderMenus.values()).filter((orderMenu) => orderMenu.category === categoryName);
+ }
+ #setOrderMenus(orderMenus) {
+ const { orderMenuNameList, orderMenuCountList } = Order.parseOrders(orderMenus);
+
+ orderMenuNameList.forEach((menuName, index) => {
+ const category = this.#getCategoryByMenuName(menuName);
+ const key = this.#getKeyByMenuName(menuName);
+
+ this.#orderMenus.set(key, {
+ name: menuName,
+ count: orderMenuCountList[index],
+ category,
+ });
+ });
+ }
+ #getOrderMenuCategories() {
+ return Array.from(new Set(Array.from(this.#menus.values()).map((menu) => menu.CATEGORY)));
+ }
+ #getCategoryByMenuName(menuName) {
+ return Array.from(this.#menus.values()).find((menuMap) => menuMap.NAME === menuName).CATEGORY;
+ }
+ #getKeyByMenuName(menuName) {
+ return Array.from(this.#menus.keys()).find((key) => this.#menus.get(key).NAME === menuName);
+ }
+}
+export default Order; | JavaScript | ์ static method๋ผ ์๋ก ๋บด๋จ์ต๋๋ค. static์ ๊ฐ ๊ฐ์ฒด๋ง๋ค์ ๋ฐ์ดํฐ์ ์ ๊ทผํ ์ ์๊ณ ํจ์๋ก์์ ๊ธฐ๋ฅ๋ง ๊ฐ๋ฅํด์ ์๋ก ๋บด๋จ์ต๋๋ค.
๋ฐ๋ก Validation ๋นผ๊ธฐ์๋ ๋ชจ๋ ์์ฝ๊ด์ ์์ ์ ํจ์ฑ ๊ฒ์ฆ์ด๋ผ Order์ ๋ชจ๋ ๋ฃ์์ต๋๋ค. view์์ ๋ฐ๋ก ์ฒ๋ฆฌํ ์ ๋ ์์๋๋ฐ ์์ฝ์ ๊ด๋ จ๋ ๊ฒ์ฆ์ด๋ผ๊ณ ํํํ๊ณ ์ถ์์ต๋๋ค |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.