From 67f467aeed97927aa0a61b5d3264367ab34435d7 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:02:56 +0900 Subject: [PATCH 01/22] =?UTF-8?q?style:=20prettier=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..565da823 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "arrowParens": "always", + "useTabs": false, + "tabWidth": 2, + "singleQuote": true, + "semi": true, + "trailingComma": "es5", + "printWidth": 100, + "endOfLine": "auto" +} From 8c9be7a18bded9771b2f778d9d6184063455a1f7 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:18:36 +0900 Subject: [PATCH 02/22] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29b..5ae193b7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,30 @@ +# 점심 메뉴 추천 + +## 기능 구현 목록 + +- [ ] 메뉴 추천 시작 메시지 출력 +- [ ] 코치 이름 입력 요청 + + - `입력 유효성 검사` + - [ ] 이름 최소 2~4글자 + - [ ] 최대 2명 ~ 5명 + +- [ ] 코치 이름 저장 +- [ ] 코치 별 못 먹는 음식 입력 요청 + + - `입력 유효성 검사` + - [ ] 최소 0개 ~ 2개 + +- [ ] 코치 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) + + - [ ] 선택된 카테고리 중복 검사 (주 최대 2회 중복 가능) + - [ ] 추천할 수 없는 경우 === 다시 추천 + +- [ ] 코치 별 음식 종류 랜덤 선택 Randoms.shuffle(menus)[0]; + + - [ ] 메뉴 중복 검사 (중복 불가능) + +- [ ] 코치 별 추천 결과 출력 + +- [ ] 추천 완료 메세지 출력 + - [ ] 종료 From 522dbb0ec1ac6c0b7f88eddd67aa475950645f23 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:25:58 +0900 Subject: [PATCH 03/22] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=B0=EB=B3=B8=EA=B5=AC=EC=A1=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 13 +++++++------ src/Recommend.js | 3 +++ src/RecommendController.js | 3 +++ src/views/InputView.js | 13 +++++++++++++ src/views/OutputView.js | 11 +++++++++++ 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 src/Recommend.js create mode 100644 src/RecommendController.js create mode 100644 src/views/InputView.js create mode 100644 src/views/OutputView.js diff --git a/src/App.js b/src/App.js index b8a89a83..2600bd89 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,11 @@ +const RecommendController = require('./Recommend.js'); + const SAMPLE = { - 일식: '규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼', - 한식: '김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음', - 중식: '깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채', - 아시안: - '팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜', - 양식: '라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니', + 일식: '규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼', + 한식: '김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음', + 중식: '깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채', + 아시안: '팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜', + 양식: '라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니', }; class App { diff --git a/src/Recommend.js b/src/Recommend.js new file mode 100644 index 00000000..399fd85d --- /dev/null +++ b/src/Recommend.js @@ -0,0 +1,3 @@ +class Recommend {} + +module.exports = Recommend; diff --git a/src/RecommendController.js b/src/RecommendController.js new file mode 100644 index 00000000..21a9c7a7 --- /dev/null +++ b/src/RecommendController.js @@ -0,0 +1,3 @@ +class RecommendController {} + +module.exports = RecommendController; diff --git a/src/views/InputView.js b/src/views/InputView.js new file mode 100644 index 00000000..934dec1d --- /dev/null +++ b/src/views/InputView.js @@ -0,0 +1,13 @@ +const { Console } = require('@woowacourse/mission-utils'); + +const InputView = { + readCoachName(callback) { + Console.readLine('코치의 이름을 입력해 주세요. (, 로 구분)', callback); + }, + + readAntiFood(name, callback) { + Console.readLine(`${name}(이)가 못 먹는 메뉴를 입력해 주세요.`, callback); + }, +}; + +module.exports = InputView; diff --git a/src/views/OutputView.js b/src/views/OutputView.js new file mode 100644 index 00000000..a830f7b4 --- /dev/null +++ b/src/views/OutputView.js @@ -0,0 +1,11 @@ +const { Console } = require('@woowacourse/mission-utils'); + +const OutputView = { + printRecommendStartMsg() { + Console.print('점심 메뉴 추천을 시작합니다.'); + }, + + printRecommendResult(result) {}, +}; + +module.exports = OutputView; From 735bc20ef3deb86821063d4aaa22d3fbae1819ed Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:29:16 +0900 Subject: [PATCH 04/22] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/App.js | 8 ++++++-- src/RecommendController.js | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5ae193b7..aa78fc35 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ ## 기능 구현 목록 -- [ ] 메뉴 추천 시작 메시지 출력 +- [x] 메뉴 추천 시작 메시지 출력 - [ ] 코치 이름 입력 요청 - `입력 유효성 검사` diff --git a/src/App.js b/src/App.js index 2600bd89..d557d626 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -const RecommendController = require('./Recommend.js'); +const RecommendController = require('./RecommendController.js'); const SAMPLE = { 일식: '규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼', @@ -9,7 +9,11 @@ const SAMPLE = { }; class App { - play() {} + play() { + new RecommendController().play(); + } } +new App().play(); + module.exports = App; diff --git a/src/RecommendController.js b/src/RecommendController.js index 21a9c7a7..515e9036 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -1,3 +1,9 @@ -class RecommendController {} +const OutputView = require('./views/OutputView.js'); + +class RecommendController { + play() { + OutputView.printRecommendStartMsg(); + } +} module.exports = RecommendController; From c71f61ef2334c5bd383709cea891f95d5c4c1dfa Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:31:42 +0900 Subject: [PATCH 05/22] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=8B=9C=20=EC=9E=AC=EC=9A=94=EC=B2=AD=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/inputErrorHandler.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/utils/inputErrorHandler.js diff --git a/src/utils/inputErrorHandler.js b/src/utils/inputErrorHandler.js new file mode 100644 index 00000000..bc60ef80 --- /dev/null +++ b/src/utils/inputErrorHandler.js @@ -0,0 +1,13 @@ +const { Console } = require('@woowacourse/mission-utils'); + +const inputErrorHandler = (validate, input) => { + try { + validate(input); + return true; + } catch ({ message }) { + Console.print(message); + return false; + } +}; + +module.exports = inputErrorHandler; From 35ed33f25bba2f144e4d208ac9e03e28b672a93c Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:33:22 +0900 Subject: [PATCH 06/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EC=9A=94=EC=B2=AD=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/RecommendController.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index aa78fc35..64c17732 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,7 @@ ## 기능 구현 목록 - [x] 메뉴 추천 시작 메시지 출력 -- [ ] 코치 이름 입력 요청 +- [x] 코치 이름 입력 요청 - `입력 유효성 검사` - [ ] 이름 최소 2~4글자 diff --git a/src/RecommendController.js b/src/RecommendController.js index 515e9036..5246bf5e 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -1,8 +1,16 @@ const OutputView = require('./views/OutputView.js'); +const InputView = require('./views/InputView.js'); +const inputErrorHandler = require('./utils/inputErrorHandler.js'); class RecommendController { play() { OutputView.printRecommendStartMsg(); + + this.#requestCoachName(); + } + + #requestCoachName() { + InputView.readCoachName((coachName) => {}); } } From 68cf15678b5fc8e8a67c50c978aa8fc4a981185a Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:35:20 +0900 Subject: [PATCH 07/22] =?UTF-8?q?refactor(inputErrorHandler):=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 재입력 요청을 처리하도록 기능 변경 --- src/utils/inputErrorHandler.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/inputErrorHandler.js b/src/utils/inputErrorHandler.js index bc60ef80..e77560c0 100644 --- a/src/utils/inputErrorHandler.js +++ b/src/utils/inputErrorHandler.js @@ -1,12 +1,11 @@ const { Console } = require('@woowacourse/mission-utils'); -const inputErrorHandler = (validate, input) => { +const inputErrorHandler = (excution, reRequest) => { try { - validate(input); - return true; + excution(); } catch ({ message }) { Console.print(message); - return false; + reRequest(); } }; From a601e1e5ea2af220561ebeda18db2e0bb1bca364 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:44:59 +0900 Subject: [PATCH 08/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EA=B8=80=EC=9E=90=EC=88=98=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/RecommendController.js | 12 +++++++++++- src/Validation.js | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/Validation.js diff --git a/docs/README.md b/docs/README.md index 64c17732..ee5a21b9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,7 +6,7 @@ - [x] 코치 이름 입력 요청 - `입력 유효성 검사` - - [ ] 이름 최소 2~4글자 + - [x] 이름 최소 2~4글자 - [ ] 최대 2명 ~ 5명 - [ ] 코치 이름 저장 diff --git a/src/RecommendController.js b/src/RecommendController.js index 5246bf5e..79a8aeeb 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -1,5 +1,6 @@ const OutputView = require('./views/OutputView.js'); const InputView = require('./views/InputView.js'); +const Validation = require('./Validation.js'); const inputErrorHandler = require('./utils/inputErrorHandler.js'); class RecommendController { @@ -10,7 +11,16 @@ class RecommendController { } #requestCoachName() { - InputView.readCoachName((coachName) => {}); + InputView.readCoachName((coachNames) => { + inputErrorHandler( + () => this.#nameSavePhase(coachNames), + () => this.#requestCoachName() + ); + }); + } + + #nameSavePhase(coachNames) { + Validation.validateCoachNames(coachNames); } } diff --git a/src/Validation.js b/src/Validation.js new file mode 100644 index 00000000..93c5952c --- /dev/null +++ b/src/Validation.js @@ -0,0 +1,15 @@ +class Validation { + static validateCoachNames(coachNames) { + const coachNameArr = coachNames.split(','); + + if (!Validation.#isValidCoachNameLength(coachNameArr)) { + throw new Error('[ERROR] 코치 이름의 길이는 2~4글자 입니다.'); + } + } + + static #isValidCoachNameLength(coachNameArr) { + return coachNameArr.every((coachName) => 2 <= coachName.length && coachName.length <= 4); + } +} + +module.exports = Validation; From 5c2250323f9aa2ee01bfdc01b38e5e22c11d38ba Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:47:23 +0900 Subject: [PATCH 09/22] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=20=EC=BD=94=EC=B9=98=20=EC=88=98=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/Validation.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index ee5a21b9..1240996c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ - `입력 유효성 검사` - [x] 이름 최소 2~4글자 - - [ ] 최대 2명 ~ 5명 + - [x] 최대 2명 ~ 5명 - [ ] 코치 이름 저장 - [ ] 코치 별 못 먹는 음식 입력 요청 diff --git a/src/Validation.js b/src/Validation.js index 93c5952c..d2f4f120 100644 --- a/src/Validation.js +++ b/src/Validation.js @@ -5,11 +5,19 @@ class Validation { if (!Validation.#isValidCoachNameLength(coachNameArr)) { throw new Error('[ERROR] 코치 이름의 길이는 2~4글자 입니다.'); } + + if (!Validation.#isValidCoachCount(coachNameArr)) { + throw new Error('[ERROR] 코치는 2명에서 5명까지 입력 가능합니다.'); + } } static #isValidCoachNameLength(coachNameArr) { return coachNameArr.every((coachName) => 2 <= coachName.length && coachName.length <= 4); } + + static #isValidCoachCount(coachNameArr) { + return 2 <= coachNameArr.length && coachNameArr.length <= 5; + } } module.exports = Validation; From a14dff57bdfa88b24bb510ac4f44a85c419e47f0 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 13:53:49 +0900 Subject: [PATCH 10/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/Recommend.js | 8 +++++++- src/RecommendController.js | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1240996c..986f67fe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,7 +9,7 @@ - [x] 이름 최소 2~4글자 - [x] 최대 2명 ~ 5명 -- [ ] 코치 이름 저장 +- [x] 코치 이름 저장 - [ ] 코치 별 못 먹는 음식 입력 요청 - `입력 유효성 검사` diff --git a/src/Recommend.js b/src/Recommend.js index 399fd85d..32db0365 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -1,3 +1,9 @@ -class Recommend {} +class Recommend { + #coachNames; + + constructor(coachNames) { + this.#coachNames = coachNames; + } +} module.exports = Recommend; diff --git a/src/RecommendController.js b/src/RecommendController.js index 79a8aeeb..1b6a7cef 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -1,9 +1,12 @@ const OutputView = require('./views/OutputView.js'); const InputView = require('./views/InputView.js'); const Validation = require('./Validation.js'); +const Recommend = require('./Recommend.js'); const inputErrorHandler = require('./utils/inputErrorHandler.js'); class RecommendController { + #recommand; + play() { OutputView.printRecommendStartMsg(); @@ -21,6 +24,8 @@ class RecommendController { #nameSavePhase(coachNames) { Validation.validateCoachNames(coachNames); + + this.#recommand = new Recommend(coachNames.split(',')); } } From 93568bd907b596428eda6a9142facebf6e0e95d5 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 14:22:43 +0900 Subject: [PATCH 11/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EB=B3=84=20?= =?UTF-8?q?=EB=AA=BB=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=9A=94=EC=B2=AD=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/RecommendController.js | 42 +++++++++++++++++++++++++++++----- src/Validation.js | 2 ++ src/utils/inputErrorHandler.js | 7 +++--- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 986f67fe..d75b3822 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,7 @@ - [x] 최대 2명 ~ 5명 - [x] 코치 이름 저장 -- [ ] 코치 별 못 먹는 음식 입력 요청 +- [x] 코치 별 못 먹는 음식 입력 요청 - `입력 유효성 검사` - [ ] 최소 0개 ~ 2개 diff --git a/src/RecommendController.js b/src/RecommendController.js index 1b6a7cef..5f6c7a43 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -15,17 +15,47 @@ class RecommendController { #requestCoachName() { InputView.readCoachName((coachNames) => { - inputErrorHandler( - () => this.#nameSavePhase(coachNames), - () => this.#requestCoachName() - ); + const isValidInput = inputErrorHandler(Validation.validateCoachNames, coachNames); + + if (!isValidInput) { + this.#requestCoachName(); + return; + } + + this.#nameSavePhase(coachNames); }); } #nameSavePhase(coachNames) { - Validation.validateCoachNames(coachNames); + const coachNameArr = coachNames.split(','); + + this.#recommand = new Recommend(coachNameArr); + + this.#requestAntiFood(coachNameArr); + } + + #requestAntiFood(coachNameArr) { + coachNameArr.forEach((coachName) => { + InputView.readAntiFood(coachName, (antiFood) => { + const isValidInput = inputErrorHandler(Validation.validateAntiFood, antiFood); + + if (!isValidInput) { + this.#requestAntiFood(coachNameArr); + return; + } + + const remainCoachArr = coachNameArr.slice(1); + this.#antiFoodSavePhase(antiFood, remainCoachArr); + }); + }); + } + + #antiFoodSavePhase(antiFood, remainCoachArr) { + console.log(`성공!!!${antiFood}`); - this.#recommand = new Recommend(coachNames.split(',')); + if (remainCoachArr.length) { + this.#requestAntiFood(remainCoachArr); + } } } diff --git a/src/Validation.js b/src/Validation.js index d2f4f120..530ec236 100644 --- a/src/Validation.js +++ b/src/Validation.js @@ -18,6 +18,8 @@ class Validation { static #isValidCoachCount(coachNameArr) { return 2 <= coachNameArr.length && coachNameArr.length <= 5; } + + static validateAntiFood(antiFood) {} } module.exports = Validation; diff --git a/src/utils/inputErrorHandler.js b/src/utils/inputErrorHandler.js index e77560c0..bc60ef80 100644 --- a/src/utils/inputErrorHandler.js +++ b/src/utils/inputErrorHandler.js @@ -1,11 +1,12 @@ const { Console } = require('@woowacourse/mission-utils'); -const inputErrorHandler = (excution, reRequest) => { +const inputErrorHandler = (validate, input) => { try { - excution(); + validate(input); + return true; } catch ({ message }) { Console.print(message); - reRequest(); + return false; } }; From caff1381aa21914a5cc005f9e09b7c91a5b05625 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 14:27:33 +0900 Subject: [PATCH 12/22] =?UTF-8?q?feat:=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=20=EA=B0=AF=EC=88=98=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/Validation.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index d75b3822..dcbde7e9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,7 +13,7 @@ - [x] 코치 별 못 먹는 음식 입력 요청 - `입력 유효성 검사` - - [ ] 최소 0개 ~ 2개 + - [x] 최소 0개 ~ 2개 - [ ] 코치 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) diff --git a/src/Validation.js b/src/Validation.js index 530ec236..182f4a9f 100644 --- a/src/Validation.js +++ b/src/Validation.js @@ -19,7 +19,16 @@ class Validation { return 2 <= coachNameArr.length && coachNameArr.length <= 5; } - static validateAntiFood(antiFood) {} + static validateAntiFood(antiFood) { + const antiFoodArr = antiFood.split(','); + if (!Validation.#isValidAntiFoodCount(antiFoodArr)) { + throw new Error('[ERROR] 못 먹는 음식은 0개 ~ 2개 만 입력 가능합니다.'); + } + } + + static #isValidAntiFoodCount(antiFoodArr) { + return 0 <= antiFoodArr.length && antiFoodArr.length <= 2; + } } module.exports = Validation; From 3243d4bd0e3442999c6a6b1018b9b478448359a7 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 14:32:18 +0900 Subject: [PATCH 13/22] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/README.md b/docs/README.md index dcbde7e9..fb74d201 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,6 +15,8 @@ - `입력 유효성 검사` - [x] 최소 0개 ~ 2개 +- [ ] 코치 별 못 먹는 음식 저장 + - [ ] 코치 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) - [ ] 선택된 카테고리 중복 검사 (주 최대 2회 중복 가능) From 1b4f10b6eab652b1de8da314a2b3deb508cdc557 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 14:32:44 +0900 Subject: [PATCH 14/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EB=B3=84=20?= =?UTF-8?q?=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/Recommend.js | 6 ++++++ src/RecommendController.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index fb74d201..c5a8180f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,7 +15,7 @@ - `입력 유효성 검사` - [x] 최소 0개 ~ 2개 -- [ ] 코치 별 못 먹는 음식 저장 +- [x] 코치 별 못 먹는 음식 저장 - [ ] 코치 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) diff --git a/src/Recommend.js b/src/Recommend.js index 32db0365..c33c1c71 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -1,8 +1,14 @@ class Recommend { #coachNames; + #antiFoods; constructor(coachNames) { this.#coachNames = coachNames; + this.#antiFoods = []; + } + + setAntiFood(antiFoodArr) { + this.#antiFoods.push(antiFoodArr); } } diff --git a/src/RecommendController.js b/src/RecommendController.js index 5f6c7a43..30f76baf 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -51,7 +51,8 @@ class RecommendController { } #antiFoodSavePhase(antiFood, remainCoachArr) { - console.log(`성공!!!${antiFood}`); + const antiFoodArr = antiFood.split(','); + this.#recommand.setAntiFood(antiFoodArr); if (remainCoachArr.length) { this.#requestAntiFood(remainCoachArr); From 58b3511cd7330d385e8cdca71f7ebf9c93c63701 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 14:43:12 +0900 Subject: [PATCH 15/22] =?UTF-8?q?feat(condition):=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC,=20=EB=A9=94=EB=89=B4=20=EC=83=81=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 8 -------- src/constants/condition.js | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/constants/condition.js diff --git a/src/App.js b/src/App.js index d557d626..88907eaa 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,5 @@ const RecommendController = require('./RecommendController.js'); -const SAMPLE = { - 일식: '규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼', - 한식: '김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음', - 중식: '깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채', - 아시안: '팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜', - 양식: '라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니', -}; - class App { play() { new RecommendController().play(); diff --git a/src/constants/condition.js b/src/constants/condition.js new file mode 100644 index 00000000..ae023d84 --- /dev/null +++ b/src/constants/condition.js @@ -0,0 +1,20 @@ +const CATEGORIES = { + 1: '일식', + 2: '한식', + 3: '중식', + 4: '아시안', + 5: '양식', +}; + +const MENUS = { + 일식: '규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼', + 한식: '김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음', + 중식: '깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채', + 아시안: '팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜', + 양식: '라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니', +}; + +module.exports = { + CATEGORIES, + MENUS, +}; From e75fe6fd5ce83fa38b70b46102fd9a30eb348d53 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 15:17:01 +0900 Subject: [PATCH 16/22] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A4=91=EB=B3=B5=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EB=B0=8F=20=EC=A0=80=EC=9E=A5=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++--- src/Recommend.js | 29 +++++++++++++++++++++++++++++ src/RecommendController.js | 9 +++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index c5a8180f..0624c2e6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,10 +17,10 @@ - [x] 코치 별 못 먹는 음식 저장 -- [ ] 코치 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) +- [ ] 날짜 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) - - [ ] 선택된 카테고리 중복 검사 (주 최대 2회 중복 가능) - - [ ] 추천할 수 없는 경우 === 다시 추천 + - [x] 선택된 카테고리 중복 검사 (주 최대 2회 중복 가능) + - [x] 추천할 수 없는 경우 === 다시 추천 - [ ] 코치 별 음식 종류 랜덤 선택 Randoms.shuffle(menus)[0]; diff --git a/src/Recommend.js b/src/Recommend.js index c33c1c71..8b0fd596 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -1,15 +1,44 @@ +const { CATEGORIES, MENUS } = require('./constants/condition.js'); +const { Random } = require('@woowacourse/mission-utils'); + class Recommend { #coachNames; #antiFoods; + #categories; constructor(coachNames) { this.#coachNames = coachNames; this.#antiFoods = []; + this.#categories = []; } setAntiFood(antiFoodArr) { this.#antiFoods.push(antiFoodArr); } + + getCategories() { + return this.#categories; + } + + recommandCategory() { + while (true) { + const randomCategoryNumber = Random.pickNumberInRange(1, 5); + const recommendedCategory = CATEGORIES[randomCategoryNumber]; + + if (this.categoryDuplicateCheck) { + this.#categories.push(recommendedCategory); + return; + } + } + } + + categoryDuplicateCheck(recommendedCategory) { + const duplicateCount = this.#categories.filter((category) => { + return category === recommendedCategory; + }).length; + + return duplicateCount < 2; + } } module.exports = Recommend; diff --git a/src/RecommendController.js b/src/RecommendController.js index 30f76baf..10d47ce0 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -56,7 +56,16 @@ class RecommendController { if (remainCoachArr.length) { this.#requestAntiFood(remainCoachArr); + return; } + + this.#recommandCategoryPhase(); + } + + #recommandCategoryPhase() { + this.#recommand.recommandCategory(); + + console.log(this.#recommand.getCategories()); } } From 4adaf6847f234a5c2ec56a0e1dbcf1927be51c96 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 15:20:26 +0900 Subject: [PATCH 17/22] =?UTF-8?q?fix:=20=EC=B2=A0=EC=9E=90=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit recommand => recommend --- src/Recommend.js | 4 +++- src/RecommendController.js | 14 ++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Recommend.js b/src/Recommend.js index 8b0fd596..65234b8e 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -20,7 +20,7 @@ class Recommend { return this.#categories; } - recommandCategory() { + recommendCategory() { while (true) { const randomCategoryNumber = Random.pickNumberInRange(1, 5); const recommendedCategory = CATEGORIES[randomCategoryNumber]; @@ -39,6 +39,8 @@ class Recommend { return duplicateCount < 2; } + + recommendFood() {} } module.exports = Recommend; diff --git a/src/RecommendController.js b/src/RecommendController.js index 10d47ce0..4ee3fbb5 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -5,7 +5,7 @@ const Recommend = require('./Recommend.js'); const inputErrorHandler = require('./utils/inputErrorHandler.js'); class RecommendController { - #recommand; + #recommend; play() { OutputView.printRecommendStartMsg(); @@ -29,7 +29,7 @@ class RecommendController { #nameSavePhase(coachNames) { const coachNameArr = coachNames.split(','); - this.#recommand = new Recommend(coachNameArr); + this.#recommend = new Recommend(coachNameArr); this.#requestAntiFood(coachNameArr); } @@ -52,20 +52,18 @@ class RecommendController { #antiFoodSavePhase(antiFood, remainCoachArr) { const antiFoodArr = antiFood.split(','); - this.#recommand.setAntiFood(antiFoodArr); + this.#recommend.setAntiFood(antiFoodArr); if (remainCoachArr.length) { this.#requestAntiFood(remainCoachArr); return; } - this.#recommandCategoryPhase(); + this.#recommendCategoryPhase(); } - #recommandCategoryPhase() { - this.#recommand.recommandCategory(); - - console.log(this.#recommand.getCategories()); + #recommendCategoryPhase() { + this.#recommend.recommendCategory(); } } From 4c1ae7ac8d0f5071a5d86ef5dc2572eca6d4e324 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 16:45:27 +0900 Subject: [PATCH 18/22] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 못먹는 메뉴, 중복메뉴 검사 후 추천 --- docs/README.md | 3 ++- src/Recommend.js | 27 ++++++++++++++++++++++++++- src/RecommendController.js | 6 ++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0624c2e6..b1e5d6c2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,7 +24,8 @@ - [ ] 코치 별 음식 종류 랜덤 선택 Randoms.shuffle(menus)[0]; - - [ ] 메뉴 중복 검사 (중복 불가능) + - [x] 메뉴 중복 검사 (중복 불가능) + - [x] 못 먹는 음식인지 검사 - [ ] 코치 별 추천 결과 출력 diff --git a/src/Recommend.js b/src/Recommend.js index 65234b8e..f8e57e0c 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -5,11 +5,17 @@ class Recommend { #coachNames; #antiFoods; #categories; + #menus; constructor(coachNames) { this.#coachNames = coachNames; this.#antiFoods = []; this.#categories = []; + this.#menus = []; + } + + getMenus() { + return this.#menus; } setAntiFood(antiFoodArr) { @@ -40,7 +46,26 @@ class Recommend { return duplicateCount < 2; } - recommendFood() {} + recommendMenu() { + this.#antiFoods.map((antiFoodArr, idx) => { + while (true) { + const latestCategory = this.#categories[this.#categories.length - 1]; + const targetMenus = MENUS[latestCategory].split(', '); + const targetMenuIdxArr = targetMenus.map((_, idx) => idx); + const recommendedMenu = targetMenus[Random.shuffle(targetMenuIdxArr)[0]]; + + if (antiFoodArr.includes(recommendedMenu)) continue; + if (this.#menus[idx] && this.#menus[idx].includes(recommendedMenu)) continue; + + if (this.#menus[idx]) { + this.#menus[idx].push(recommendedMenu); + } else { + this.#menus.push([recommendedMenu]); + } + return; + } + }); + } } module.exports = Recommend; diff --git a/src/RecommendController.js b/src/RecommendController.js index 4ee3fbb5..6528fc01 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -64,6 +64,12 @@ class RecommendController { #recommendCategoryPhase() { this.#recommend.recommendCategory(); + + this.#recommendMenu(); + } + + #recommendMenu() { + this.#recommend.recommendMenu(); } } From 569e9bb8c83720222852a8ec0d6f0b92727bfac8 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 16:53:14 +0900 Subject: [PATCH 19/22] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC,=EB=A9=94=EB=89=B4=EC=B6=94=EC=B2=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=9A=94=EC=9D=BC=EB=A7=8C=ED=81=BC=20=EB=B0=98?= =?UTF-8?q?=EB=B3=B5=ED=95=98=EC=97=AC=20=EB=8F=99=EC=9E=91=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 ++++-- src/RecommendController.js | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index b1e5d6c2..b12184cf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,16 +17,18 @@ - [x] 코치 별 못 먹는 음식 저장 -- [ ] 날짜 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) +- [x] 날짜 별 음식 카테고리 랜덤 선택 pickNumberInRange(1, 5) - [x] 선택된 카테고리 중복 검사 (주 최대 2회 중복 가능) - [x] 추천할 수 없는 경우 === 다시 추천 -- [ ] 코치 별 음식 종류 랜덤 선택 Randoms.shuffle(menus)[0]; +- [x] 코치 별 음식 종류 랜덤 선택 Randoms.shuffle(menus)[0]; - [x] 메뉴 중복 검사 (중복 불가능) - [x] 못 먹는 음식인지 검사 +- [x] 카테고리,메뉴추천 기능 요일(월,화,수,목,금)만큼 반복하여 동작 + - [ ] 코치 별 추천 결과 출력 - [ ] 추천 완료 메세지 출력 diff --git a/src/RecommendController.js b/src/RecommendController.js index 6528fc01..19e8bce1 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -70,6 +70,11 @@ class RecommendController { #recommendMenu() { this.#recommend.recommendMenu(); + const recommendedMenuCount = this.#recommend.getMenus()[0].length; + if (recommendedMenuCount < 5) { + this.#recommendCategoryPhase(); + return; + } } } From c47f4617a4263ab8eb13a11f1b9d4c3c497fd8b1 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 17:33:10 +0900 Subject: [PATCH 20/22] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=20=EB=B3=84=20?= =?UTF-8?q?=EC=B6=94=EC=B2=9C=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A2=85=EB=A3=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 ++--- src/Recommend.js | 12 ++++++---- src/RecommendController.js | 13 +++++++++++ src/utils/resultTemplateMaker.js | 39 ++++++++++++++++++++++++++++++++ src/views/OutputView.js | 7 +++++- 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 src/utils/resultTemplateMaker.js diff --git a/docs/README.md b/docs/README.md index b12184cf..1475cb24 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,7 +29,7 @@ - [x] 카테고리,메뉴추천 기능 요일(월,화,수,목,금)만큼 반복하여 동작 -- [ ] 코치 별 추천 결과 출력 +- [x] 코치 별 추천 결과 출력 -- [ ] 추천 완료 메세지 출력 - - [ ] 종료 +- [x] 추천 완료 메세지 출력 + - [x] 종료 diff --git a/src/Recommend.js b/src/Recommend.js index f8e57e0c..f6971d45 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -14,18 +14,22 @@ class Recommend { this.#menus = []; } - getMenus() { - return this.#menus; + getCoachNames() { + return this.#coachNames; } - setAntiFood(antiFoodArr) { - this.#antiFoods.push(antiFoodArr); + getMenus() { + return this.#menus; } getCategories() { return this.#categories; } + setAntiFood(antiFoodArr) { + this.#antiFoods.push(antiFoodArr); + } + recommendCategory() { while (true) { const randomCategoryNumber = Random.pickNumberInRange(1, 5); diff --git a/src/RecommendController.js b/src/RecommendController.js index 19e8bce1..dabc15d5 100644 --- a/src/RecommendController.js +++ b/src/RecommendController.js @@ -2,6 +2,7 @@ const OutputView = require('./views/OutputView.js'); const InputView = require('./views/InputView.js'); const Validation = require('./Validation.js'); const Recommend = require('./Recommend.js'); +const { Console } = require('@woowacourse/mission-utils'); const inputErrorHandler = require('./utils/inputErrorHandler.js'); class RecommendController { @@ -70,11 +71,23 @@ class RecommendController { #recommendMenu() { this.#recommend.recommendMenu(); + const recommendedMenuCount = this.#recommend.getMenus()[0].length; if (recommendedMenuCount < 5) { this.#recommendCategoryPhase(); return; } + + this.#endPhase(); + } + + #endPhase() { + const categories = this.#recommend.getCategories(); + const coachNames = this.#recommend.getCoachNames(); + const menus = this.#recommend.getMenus(); + + OutputView.printRecommendResult(categories, coachNames, menus); + Console.close(); } } diff --git a/src/utils/resultTemplateMaker.js b/src/utils/resultTemplateMaker.js new file mode 100644 index 00000000..0dcecbc5 --- /dev/null +++ b/src/utils/resultTemplateMaker.js @@ -0,0 +1,39 @@ +const resultTemplateMaker = { + getRecommendResultTemplate(categories, coachNames, menus) { + const templates = [ + '메뉴 추천 결과입니다.', + '[ 구분 | 월요일 | 화요일 | 수요일 | 목요일 | 금요일 ]', + ]; + + templates.push(resultTemplateMaker.getCategoryTemplate(categories)); + resultTemplateMaker + .getMenusTemplate(coachNames, menus) + .forEach((temp) => templates.push(`[ ${temp} ]`)); + + templates.push('추천을 완료했습니다.'); + return templates; + }, + + getCategoryTemplate(categories) { + const template = ['카테고리']; + categories.forEach((category) => template.push(category)); + + return `[ ${template.join(' | ')} ]`; + }, + + getMenusTemplate(coachNames, menus) { + const template = []; + menus.forEach((menu, idx) => { + const temp = []; + temp.push(coachNames[idx]); + const str = menu.join(' | '); + temp.push(str); + + template.push(temp.join(' | ')); + }); + + return template; + }, +}; + +module.exports = resultTemplateMaker; diff --git a/src/views/OutputView.js b/src/views/OutputView.js index a830f7b4..04064b3f 100644 --- a/src/views/OutputView.js +++ b/src/views/OutputView.js @@ -1,11 +1,16 @@ const { Console } = require('@woowacourse/mission-utils'); +const resultTemplateMaker = require('../utils/resultTemplateMaker.js'); const OutputView = { printRecommendStartMsg() { Console.print('점심 메뉴 추천을 시작합니다.'); }, - printRecommendResult(result) {}, + printRecommendResult(categories, coachNames, menus) { + const templates = resultTemplateMaker.getRecommendResultTemplate(categories, coachNames, menus); + + templates.forEach((template) => Console.print(template)); + }, }; module.exports = OutputView; From 57dd6b156ec12aaf0706e94baafbe60ee9bd1f14 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 17:57:48 +0900 Subject: [PATCH 21/22] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Recommend.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Recommend.js b/src/Recommend.js index f6971d45..481bce5d 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -53,10 +53,14 @@ class Recommend { recommendMenu() { this.#antiFoods.map((antiFoodArr, idx) => { while (true) { - const latestCategory = this.#categories[this.#categories.length - 1]; + const latestCategory = this.#categories.length ? [this.#categories.length - 1] : null; + const targetMenus = MENUS[latestCategory].split(', '); + const targetMenuIdxArr = targetMenus.map((_, idx) => idx); - const recommendedMenu = targetMenus[Random.shuffle(targetMenuIdxArr)[0]]; + const randomNum = Random.shuffle(targetMenuIdxArr)[0]; + + const recommendedMenu = targetMenus[randomNum]; if (antiFoodArr.includes(recommendedMenu)) continue; if (this.#menus[idx] && this.#menus[idx].includes(recommendedMenu)) continue; From d02ea4300cbdf45d98453cb1d6e612ab18c7b9f5 Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Sat, 17 Dec 2022 17:59:07 +0900 Subject: [PATCH 22/22] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Recommend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Recommend.js b/src/Recommend.js index 481bce5d..d9b6c047 100644 --- a/src/Recommend.js +++ b/src/Recommend.js @@ -53,7 +53,7 @@ class Recommend { recommendMenu() { this.#antiFoods.map((antiFoodArr, idx) => { while (true) { - const latestCategory = this.#categories.length ? [this.#categories.length - 1] : null; + const latestCategory = this.#categories[this.#categories.length - 1]; const targetMenus = MENUS[latestCategory].split(', ');