From 5ef5ab1fa8832ddeb7dfcadc8ce8e5fe887dc231 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:24:10 +0900 Subject: [PATCH 01/16] docs: Update README.md --- docs/README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..2e3223636 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,49 @@ +# Flow +1. 기능을 선택한다. + - **1 ~ 3, Q가 아닌 경우 예외 발생** +2. 페어 매칭 + - 페어 매칭을 위한 정보를 입력받는다. + - 정보는 파일 입출력으로 입력된다. + - 입력된 정보를 바탕으로 페어를 매칭한다. + - 입력된 정보를 Shuffle을 통해 섞는다. + - 짝수로 나누어 페어를 매칭한다. + - 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다. + - 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다. + - **3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 발생** + - 과정(백엔드/프론트엔드)와 레벨을 입력받는다. + - 매칭된 결과를 출력한다. + - 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다. + - 네,아니오가 아닐 경우 예외 발생 +3. 페어 조회 + - 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키# 다시 입력 받는다. + - 매칭된 적이 있다면, 페어를 조회한다. +4. 페어 초기화 + - 페어를 초기화한다. +5. 종료 + - 페어 매칭을 종료한다. + +# 기능 명세서 +- 기능을 선택한다. + - [ ] 기능 입력받기 + - [ ] 1 ~ 3, Q가 아닌 경우 예외 처리 +- 페어 매칭 + - [ ] 파일 입출력 + - [ ] 입력된 정보를 바탕으로 페어를 매칭한다. + - [ ] 과정(백엔드/프론트엔드)와 레벨을 입력받는다. + - [ ] 셔플 + - [ ] 짝수로 나누어 페어를 매칭한다. + - [ ] 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다. + - [ ] 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다. + - [ ] 3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 처리 + - [ ] 매칭된 결과를 출력한다. + - [ ] 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다. + - [ ] 재 매칭 여부를 입력받는다. + - [ ] 네, 아니오가 아닐 경우, 예외 발생 + - [ ] 네일 경우, 다시 매칭한다. +- 페어 조회 + - [ ] 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키고 다시 입력 받는다. + - [ ] 매칭된 적이 있다면, 페어를 조회한다. +- 페어 초기화 + - [ ] 페어를 초기화한다. +- 종료 + - [ ] 페어 매칭을 종료한다. \ No newline at end of file From 1b27a3fac171a9338437a3c80eee4b06f6fe3be4 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:00:18 +0900 Subject: [PATCH 02/16] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EB=B0=9B=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/pairmatching/Application.java | 7 ++++- .../java/pairmatching/constants/FilePath.java | 15 +++++++++++ .../controller/PairMatchingController.java | 19 +++++++++++++ src/main/java/pairmatching/domain/people.java | 9 +++++++ .../repository/BackendRepository.java | 15 +++++++++++ .../repository/FrontendRepository.java | 20 ++++++++++++++ .../pairmatching/service/PeopleService.java | 27 +++++++++++++++++++ src/main/java/pairmatching/utils/Reader.java | 23 ++++++++++++++++ 8 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pairmatching/constants/FilePath.java create mode 100644 src/main/java/pairmatching/controller/PairMatchingController.java create mode 100644 src/main/java/pairmatching/domain/people.java create mode 100644 src/main/java/pairmatching/repository/BackendRepository.java create mode 100644 src/main/java/pairmatching/repository/FrontendRepository.java create mode 100644 src/main/java/pairmatching/service/PeopleService.java create mode 100644 src/main/java/pairmatching/utils/Reader.java diff --git a/src/main/java/pairmatching/Application.java b/src/main/java/pairmatching/Application.java index 6f56e741c..b353ff796 100644 --- a/src/main/java/pairmatching/Application.java +++ b/src/main/java/pairmatching/Application.java @@ -1,7 +1,12 @@ package pairmatching; +import pairmatching.controller.PairMatchingController; +import pairmatching.service.PeopleService; + public class Application { public static void main(String[] args) { - // TODO 구현 진행 + PeopleService peopleService = new PeopleService(); + PairMatchingController pairMatchingController = new PairMatchingController(peopleService); + pairMatchingController.run(); } } diff --git a/src/main/java/pairmatching/constants/FilePath.java b/src/main/java/pairmatching/constants/FilePath.java new file mode 100644 index 000000000..74890bc5d --- /dev/null +++ b/src/main/java/pairmatching/constants/FilePath.java @@ -0,0 +1,15 @@ +package pairmatching.constants; + +public enum FilePath { + FRONT_FILE_PATH("/Users/2sh/Desktop/java-pairmatching-precourse/src/main/resources/frontend-crew.md"), + BACK_FILE_PATH("/Users/2sh/Desktop/java-pairmatching-precourse/src/main/resources/backend-crew.md"); + private final String path; + + FilePath(String path) { + this.path = path; + } + + public String getPath() { + return path; + } +} diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java new file mode 100644 index 000000000..b85b50040 --- /dev/null +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -0,0 +1,19 @@ +package pairmatching.controller; + +import pairmatching.service.PeopleService; + +public class PairMatchingController { + private final PeopleService peopleService; + + public PairMatchingController(PeopleService peopleService) { + this.peopleService = peopleService; + } + + public void run(){ + InputPeople(); + } + + private void InputPeople(){ + peopleService.initPeople(); + } +} diff --git a/src/main/java/pairmatching/domain/people.java b/src/main/java/pairmatching/domain/people.java new file mode 100644 index 000000000..7c7d30ee1 --- /dev/null +++ b/src/main/java/pairmatching/domain/people.java @@ -0,0 +1,9 @@ +package pairmatching.domain; + +public class people { + private final String name; + + public people(String name) { + this.name = name; + } +} diff --git a/src/main/java/pairmatching/repository/BackendRepository.java b/src/main/java/pairmatching/repository/BackendRepository.java new file mode 100644 index 000000000..a4eeb9d20 --- /dev/null +++ b/src/main/java/pairmatching/repository/BackendRepository.java @@ -0,0 +1,15 @@ +package pairmatching.repository; + +import java.util.List; + +public class BackendRepository { + private List backend; + + public void save(List backend) { + this.backend = backend; + } + + public List getBackend() { + return backend; + } +} diff --git a/src/main/java/pairmatching/repository/FrontendRepository.java b/src/main/java/pairmatching/repository/FrontendRepository.java new file mode 100644 index 000000000..72807dd72 --- /dev/null +++ b/src/main/java/pairmatching/repository/FrontendRepository.java @@ -0,0 +1,20 @@ +package pairmatching.repository; + +import java.util.ArrayList; +import java.util.List; + +public class FrontendRepository { + private List frontend = new ArrayList<>(); + + public FrontendRepository() { + + } + + public void save(List frontend) { + this.frontend = frontend; + } + + public List getFrontend() { + return frontend; + } +} diff --git a/src/main/java/pairmatching/service/PeopleService.java b/src/main/java/pairmatching/service/PeopleService.java new file mode 100644 index 000000000..e82cef22b --- /dev/null +++ b/src/main/java/pairmatching/service/PeopleService.java @@ -0,0 +1,27 @@ +package pairmatching.service; + +import static pairmatching.constants.FilePath.*; + +import java.util.List; +import pairmatching.constants.FilePath; +import pairmatching.repository.BackendRepository; +import pairmatching.repository.FrontendRepository; +import pairmatching.utils.Reader; + +public class PeopleService { + private final FrontendRepository frontendRepository; + private final BackendRepository backendRepository; + + public PeopleService() { + this.frontendRepository = new FrontendRepository(); + this.backendRepository = new BackendRepository(); + } + + public void initPeople(){ + List Frontend = Reader.readFile(FRONT_FILE_PATH.getPath()); + frontendRepository.save(Frontend); + List Backend = Reader.readFile(BACK_FILE_PATH.getPath()); + backendRepository.save(Backend); + } + +} diff --git a/src/main/java/pairmatching/utils/Reader.java b/src/main/java/pairmatching/utils/Reader.java new file mode 100644 index 000000000..30ad68cab --- /dev/null +++ b/src/main/java/pairmatching/utils/Reader.java @@ -0,0 +1,23 @@ +package pairmatching.utils; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Reader { + + public static List readFile(String filePath) { + List lines = new ArrayList<>(); + try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + } catch (IOException e) { + throw new IllegalArgumentException("[ERROR] 파일을 읽을 수 없습니다."); + } + return lines; + } +} From 37ef23f6e2ac792399fca82cd13b6eac216b4d60 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:44:53 +0900 Subject: [PATCH 03/16] =?UTF-8?q?feat:=20course=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pairmatching/constants/ErrorMessage.java | 15 +++++++ .../constants/ProgressMessage.java | 26 +++++++++++++ .../controller/PairMatchingController.java | 39 ++++++++++++++++++- .../pairmatching/service/PeopleService.java | 1 - .../validator/InputChoiceValidator.java | 15 +++++++ .../validator/InputCourseValidator.java | 7 ++++ .../java/pairmatching/view/InputView.java | 19 +++++++++ .../java/pairmatching/view/OutputView.java | 9 +++++ .../pairmatching/view/common/Printer.java | 7 ++++ 9 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/main/java/pairmatching/constants/ErrorMessage.java create mode 100644 src/main/java/pairmatching/constants/ProgressMessage.java create mode 100644 src/main/java/pairmatching/validator/InputChoiceValidator.java create mode 100644 src/main/java/pairmatching/validator/InputCourseValidator.java create mode 100644 src/main/java/pairmatching/view/InputView.java create mode 100644 src/main/java/pairmatching/view/OutputView.java create mode 100644 src/main/java/pairmatching/view/common/Printer.java diff --git a/src/main/java/pairmatching/constants/ErrorMessage.java b/src/main/java/pairmatching/constants/ErrorMessage.java new file mode 100644 index 000000000..5eceb6090 --- /dev/null +++ b/src/main/java/pairmatching/constants/ErrorMessage.java @@ -0,0 +1,15 @@ +package pairmatching.constants; + +public enum ErrorMessage { + INPUT_CHOICE_ERROR("[ERROR] 1, 2, 3, Q 중에 입력해주세요."); + + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/pairmatching/constants/ProgressMessage.java b/src/main/java/pairmatching/constants/ProgressMessage.java new file mode 100644 index 000000000..8d7c3b6d0 --- /dev/null +++ b/src/main/java/pairmatching/constants/ProgressMessage.java @@ -0,0 +1,26 @@ +package pairmatching.constants; + +public enum ProgressMessage { + START_CHOICE("기능을 선택하세요.\n1. 페어 매칭\n2. 페어 조회\n3. 페어 초기화\nQ. 종료"), + LINE("\n"), + COURSE_CHOICE("#############################################\n" + + "과정: 백엔드 | 프론트엔드\n" + + "미션:\n" + + " - 레벨1: 자동차경주 | 로또 | 숫자야구게임\n" + + " - 레벨2: 장바구니 | 결제 | 지하철노선도\n" + + " - 레벨3:\n" + + " - 레벨4: 성능개선 | 배포\n" + + " - 레벨5:\n" + + "############################################\n" + + "과정, 레벨, 미션을 선택하세요.\n" + + "ex) 백엔드, 레벨1, 자동차경주"); + private final String message; + + ProgressMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index b85b50040..ff055b8d5 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -1,6 +1,12 @@ package pairmatching.controller; +import static pairmatching.validator.InputChoiceValidator.*; +import static pairmatching.view.OutputView.*; + import pairmatching.service.PeopleService; +import pairmatching.validator.InputChoiceValidator; +import pairmatching.view.InputView; +import pairmatching.view.OutputView; public class PairMatchingController { private final PeopleService peopleService; @@ -9,11 +15,40 @@ public PairMatchingController(PeopleService peopleService) { this.peopleService = peopleService; } - public void run(){ + public void run() { InputPeople(); + while (true) { + String choice = InputChoice(); + if (choice.equals("Q")) { + break; + } + if(choice.equals("1")){ + pairMatching(); + } + } } - private void InputPeople(){ + private void InputPeople() { peopleService.initPeople(); } + + private String InputChoice() { + while (true) { + try { + return validateInputChoice(InputView.chooseFunction()); + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); + } + } + } + + private String pairMatching(){ + while(true){ + try{ + return InputView.chooseCourse(); + }catch(IllegalArgumentException e){ + printErrorMessage(e.getMessage()); + } + } + } } diff --git a/src/main/java/pairmatching/service/PeopleService.java b/src/main/java/pairmatching/service/PeopleService.java index e82cef22b..65684c92e 100644 --- a/src/main/java/pairmatching/service/PeopleService.java +++ b/src/main/java/pairmatching/service/PeopleService.java @@ -23,5 +23,4 @@ public void initPeople(){ List Backend = Reader.readFile(BACK_FILE_PATH.getPath()); backendRepository.save(Backend); } - } diff --git a/src/main/java/pairmatching/validator/InputChoiceValidator.java b/src/main/java/pairmatching/validator/InputChoiceValidator.java new file mode 100644 index 000000000..0ce9db360 --- /dev/null +++ b/src/main/java/pairmatching/validator/InputChoiceValidator.java @@ -0,0 +1,15 @@ +package pairmatching.validator; + +import static pairmatching.constants.ErrorMessage.*; + +import pairmatching.constants.ErrorMessage; + +public class InputChoiceValidator { + + public static String validateInputChoice(String choice) { + if (!choice.equals("1") && !choice.equals("2") && !choice.equals("3") && !choice.equals("Q")) { + throw new IllegalArgumentException(INPUT_CHOICE_ERROR.getMessage()); + } + return choice; + } +} diff --git a/src/main/java/pairmatching/validator/InputCourseValidator.java b/src/main/java/pairmatching/validator/InputCourseValidator.java new file mode 100644 index 000000000..1b7b96141 --- /dev/null +++ b/src/main/java/pairmatching/validator/InputCourseValidator.java @@ -0,0 +1,7 @@ +package pairmatching.validator; + +public class InputCourseValidator { + public void validateInputCourse(String course) { + + } +} diff --git a/src/main/java/pairmatching/view/InputView.java b/src/main/java/pairmatching/view/InputView.java new file mode 100644 index 000000000..5a3955a6f --- /dev/null +++ b/src/main/java/pairmatching/view/InputView.java @@ -0,0 +1,19 @@ +package pairmatching.view; + +import static pairmatching.constants.ProgressMessage.COURSE_CHOICE; +import static pairmatching.constants.ProgressMessage.START_CHOICE; + +import camp.nextstep.edu.missionutils.Console; +import pairmatching.view.common.Printer; + +public class InputView { + public static String chooseFunction() { + Printer.printer(START_CHOICE.getMessage()); + return Console.readLine(); + } + + public static String chooseCourse() { + Printer.printer(COURSE_CHOICE.getMessage()); + return Console.readLine(); + } +} diff --git a/src/main/java/pairmatching/view/OutputView.java b/src/main/java/pairmatching/view/OutputView.java new file mode 100644 index 000000000..256fec7a6 --- /dev/null +++ b/src/main/java/pairmatching/view/OutputView.java @@ -0,0 +1,9 @@ +package pairmatching.view; + +import static pairmatching.view.common.Printer.printer; + +public class OutputView { + public static void printErrorMessage(String message) { + printer(message); + } +} diff --git a/src/main/java/pairmatching/view/common/Printer.java b/src/main/java/pairmatching/view/common/Printer.java new file mode 100644 index 000000000..1b7f23ee4 --- /dev/null +++ b/src/main/java/pairmatching/view/common/Printer.java @@ -0,0 +1,7 @@ +package pairmatching.view.common; + +public class Printer { + public static void printer(String message) { + System.out.println(message); + } +} From 87973c6fb1f517d633e2a9ddc807893ac3d70b3c Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Thu, 30 Nov 2023 22:08:35 +0900 Subject: [PATCH 04/16] =?UTF-8?q?feat:=20course=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PairMatchingController.java | 10 ++-- src/main/java/pairmatching/domain/Course.java | 16 ++++++ .../domain/{people.java => People.java} | 4 +- .../pairmatching/domain/constants/Level.java | 28 ++++++++++ .../domain/constants/Position.java | 16 ++++++ .../pairmatching/service/PeopleService.java | 5 ++ .../validator/InputCourseValidator.java | 53 ++++++++++++++++++- 7 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 src/main/java/pairmatching/domain/Course.java rename src/main/java/pairmatching/domain/{people.java => People.java} (63%) create mode 100644 src/main/java/pairmatching/domain/constants/Level.java create mode 100644 src/main/java/pairmatching/domain/constants/Position.java diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index ff055b8d5..35eddd3c1 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -1,12 +1,12 @@ package pairmatching.controller; import static pairmatching.validator.InputChoiceValidator.*; +import static pairmatching.validator.InputCourseValidator.*; import static pairmatching.view.OutputView.*; +import pairmatching.domain.Course; import pairmatching.service.PeopleService; -import pairmatching.validator.InputChoiceValidator; import pairmatching.view.InputView; -import pairmatching.view.OutputView; public class PairMatchingController { private final PeopleService peopleService; @@ -23,7 +23,7 @@ public void run() { break; } if(choice.equals("1")){ - pairMatching(); + peopleService.pairMatching(InputCourse()); } } } @@ -42,10 +42,10 @@ private String InputChoice() { } } - private String pairMatching(){ + private Course InputCourse(){ while(true){ try{ - return InputView.chooseCourse(); + return validateInputCourse(InputView.chooseCourse()); }catch(IllegalArgumentException e){ printErrorMessage(e.getMessage()); } diff --git a/src/main/java/pairmatching/domain/Course.java b/src/main/java/pairmatching/domain/Course.java new file mode 100644 index 000000000..7c0d5f32b --- /dev/null +++ b/src/main/java/pairmatching/domain/Course.java @@ -0,0 +1,16 @@ +package pairmatching.domain; + +import pairmatching.domain.constants.Level; +import pairmatching.domain.constants.Position; + +public class Course { + private final Level level; + private final Position position; + private final String mission; + + public Course(Level level, Position position, String mission) { + this.level = level; + this.position = position; + this.mission = mission; + } +} diff --git a/src/main/java/pairmatching/domain/people.java b/src/main/java/pairmatching/domain/People.java similarity index 63% rename from src/main/java/pairmatching/domain/people.java rename to src/main/java/pairmatching/domain/People.java index 7c7d30ee1..9d5e938be 100644 --- a/src/main/java/pairmatching/domain/people.java +++ b/src/main/java/pairmatching/domain/People.java @@ -1,9 +1,9 @@ package pairmatching.domain; -public class people { +public class People { private final String name; - public people(String name) { + public People(String name) { this.name = name; } } diff --git a/src/main/java/pairmatching/domain/constants/Level.java b/src/main/java/pairmatching/domain/constants/Level.java new file mode 100644 index 000000000..a89115401 --- /dev/null +++ b/src/main/java/pairmatching/domain/constants/Level.java @@ -0,0 +1,28 @@ +package pairmatching.domain.constants; + +import java.util.Arrays; +import java.util.List; + +public enum Level { + LEVEL1("레벨1", Arrays.asList("자동차경주", "로또", "숫자야구게임")), + LEVEL2("레벨2", Arrays.asList("장바구니", "결제", "지하철노선도")), + LEVEL3("레벨3", null), + LEVEL4("레벨4", Arrays.asList("성능개선", "배포")), + LEVEL5("레벨5", null); + + private String name; + private List missions; + + Level(String name, List missions) { + this.name = name; + this.missions = missions; + } + + public String getName() { + return name; + } + + public List getMissions() { + return missions; + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/domain/constants/Position.java b/src/main/java/pairmatching/domain/constants/Position.java new file mode 100644 index 000000000..e06262f9a --- /dev/null +++ b/src/main/java/pairmatching/domain/constants/Position.java @@ -0,0 +1,16 @@ +package pairmatching.domain.constants; + +public enum Position { + BACKEND("백엔드"), + FRONTEND("프론트엔드"); + + private String position; + + Position(String position) { + this.position = position; + } + + public String getPosition() { + return position; + } +} diff --git a/src/main/java/pairmatching/service/PeopleService.java b/src/main/java/pairmatching/service/PeopleService.java index 65684c92e..ab375d6ea 100644 --- a/src/main/java/pairmatching/service/PeopleService.java +++ b/src/main/java/pairmatching/service/PeopleService.java @@ -4,6 +4,7 @@ import java.util.List; import pairmatching.constants.FilePath; +import pairmatching.domain.Course; import pairmatching.repository.BackendRepository; import pairmatching.repository.FrontendRepository; import pairmatching.utils.Reader; @@ -23,4 +24,8 @@ public void initPeople(){ List Backend = Reader.readFile(BACK_FILE_PATH.getPath()); backendRepository.save(Backend); } + + public void pairMatching(Course inputCourse) { + + } } diff --git a/src/main/java/pairmatching/validator/InputCourseValidator.java b/src/main/java/pairmatching/validator/InputCourseValidator.java index 1b7b96141..0d6723af6 100644 --- a/src/main/java/pairmatching/validator/InputCourseValidator.java +++ b/src/main/java/pairmatching/validator/InputCourseValidator.java @@ -1,7 +1,58 @@ package pairmatching.validator; +import pairmatching.domain.Course; +import pairmatching.domain.constants.Position; +import pairmatching.domain.constants.Level; + public class InputCourseValidator { - public void validateInputCourse(String course) { + public static Course validateInputCourse(String inputCourse) { + validateInput(inputCourse); + String[] parts = inputCourse.split(", "); + + if (parts.length != 3) { + throw new IllegalArgumentException("[ERROR] 입력 형식이 잘못되었습니다."); + } + + Position position = validatePosition(parts[0]); + Level level = validateLevel(parts[1]); + String mission = validateMission(level, parts[2]); + return new Course(level, position, mission); + } + + private static void validateInput(String course){ + if(course == null || course.isEmpty()){ + throw new IllegalArgumentException("[ERROR] 입력값이 없습니다."); + } + } + private static Position validatePosition(String part) { + for (Position position : Position.values()) { + if (position.getPosition().equals(part)) { + return position; + } + } + throw new IllegalArgumentException("[ERROR] 백엔드, 프론트엔드 중에 입력해주세요."); } + + private static Level validateLevel(String part) { + for (Level level : Level.values()) { + if (level.getName().equals(part)) { + return level; + } + } + throw new IllegalArgumentException("[ERROR] 레벨1, 레벨2, 레벨3, 레벨4, 레벨5 중에 입력해주세요."); + } + + private static String validateMission(Level level, String part) { + if (level.getMissions() == null) { + throw new IllegalArgumentException("[ERROR] 현재 " + level.getName() + "은 미션을 지원하지 않습니다."); + } + for (String mission : level.getMissions()) { + if (mission.equals(part)) { + return mission; + } + } + throw new IllegalArgumentException("[ERROR] " + level.getName() + "의 미션 중에 입력해주세요."); + } + } From 1978602a79c734bee9c0627764afe947467b2ba3 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:34:05 +0900 Subject: [PATCH 05/16] =?UTF-8?q?feat:=20=ED=8E=98=EC=96=B4=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=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 --- build.gradle | 4 +- src/main/java/pairmatching/Application.java | 6 +- .../constants/ProgressMessage.java | 8 +- .../controller/PairMatchingController.java | 61 +++++++-- src/main/java/pairmatching/domain/Course.java | 12 ++ .../pairmatching/domain/MatchingHistory.java | 21 +++ src/main/java/pairmatching/domain/Pair.java | 22 ++++ src/main/java/pairmatching/domain/People.java | 9 -- .../repository/FrontendRepository.java | 5 +- .../repository/MatchingHistoryRepository.java | 42 ++++++ .../pairmatching/service/MatchingService.java | 120 ++++++++++++++++++ .../pairmatching/service/PeopleService.java | 31 ----- .../java/pairmatching/view/InputView.java | 11 +- .../java/pairmatching/view/OutputView.java | 19 ++- 14 files changed, 306 insertions(+), 65 deletions(-) create mode 100644 src/main/java/pairmatching/domain/MatchingHistory.java create mode 100644 src/main/java/pairmatching/domain/Pair.java delete mode 100644 src/main/java/pairmatching/domain/People.java create mode 100644 src/main/java/pairmatching/repository/MatchingHistoryRepository.java create mode 100644 src/main/java/pairmatching/service/MatchingService.java delete mode 100644 src/main/java/pairmatching/service/PeopleService.java diff --git a/build.gradle b/build.gradle index 449e0350a..82925122b 100644 --- a/build.gradle +++ b/build.gradle @@ -11,12 +11,12 @@ repositories { } dependencies { - implementation 'com.github.woowacourse-projects:mission-utils:1.0.0' + implementation 'com.github.woowacourse-projects:mission-utils:1.1.0' } java { toolchain { - languageVersion = JavaLanguageVersion.of(8) + languageVersion = JavaLanguageVersion.of(17) } } diff --git a/src/main/java/pairmatching/Application.java b/src/main/java/pairmatching/Application.java index b353ff796..d28479213 100644 --- a/src/main/java/pairmatching/Application.java +++ b/src/main/java/pairmatching/Application.java @@ -1,12 +1,12 @@ package pairmatching; import pairmatching.controller.PairMatchingController; -import pairmatching.service.PeopleService; +import pairmatching.service.MatchingService; public class Application { public static void main(String[] args) { - PeopleService peopleService = new PeopleService(); - PairMatchingController pairMatchingController = new PairMatchingController(peopleService); + MatchingService matchingService = new MatchingService(); + PairMatchingController pairMatchingController = new PairMatchingController(matchingService); pairMatchingController.run(); } } diff --git a/src/main/java/pairmatching/constants/ProgressMessage.java b/src/main/java/pairmatching/constants/ProgressMessage.java index 8d7c3b6d0..d6d45a4d1 100644 --- a/src/main/java/pairmatching/constants/ProgressMessage.java +++ b/src/main/java/pairmatching/constants/ProgressMessage.java @@ -3,7 +3,7 @@ public enum ProgressMessage { START_CHOICE("기능을 선택하세요.\n1. 페어 매칭\n2. 페어 조회\n3. 페어 초기화\nQ. 종료"), LINE("\n"), - COURSE_CHOICE("#############################################\n" + COURSE_CHOICE("\n#############################################\n" + "과정: 백엔드 | 프론트엔드\n" + "미션:\n" + " - 레벨1: 자동차경주 | 로또 | 숫자야구게임\n" @@ -13,7 +13,11 @@ public enum ProgressMessage { + " - 레벨5:\n" + "############################################\n" + "과정, 레벨, 미션을 선택하세요.\n" - + "ex) 백엔드, 레벨1, 자동차경주"); + + "ex) 백엔드, 레벨1, 자동차경주\n" + + "프론트엔드, 레벨1, 자동차경주\n"), + RETRY_COURSE("\n매칭 정보가 있습니다. 다시 매칭하시겠습니까?\n" + + "예 | 아니오"), + PAIR_MATCHING_RESULT("\n페어 매칭 결과입니다."); private final String message; ProgressMessage(String message) { diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 35eddd3c1..9c20b2839 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -1,18 +1,20 @@ package pairmatching.controller; -import static pairmatching.validator.InputChoiceValidator.*; -import static pairmatching.validator.InputCourseValidator.*; -import static pairmatching.view.OutputView.*; +import static pairmatching.validator.InputChoiceValidator.validateInputChoice; +import static pairmatching.validator.InputCourseValidator.validateInputCourse; +import static pairmatching.view.OutputView.printErrorMessage; import pairmatching.domain.Course; -import pairmatching.service.PeopleService; +import pairmatching.service.MatchingService; import pairmatching.view.InputView; +import pairmatching.view.OutputView; public class PairMatchingController { - private final PeopleService peopleService; + private final MatchingService matchingService; + private int retryCount = 0; - public PairMatchingController(PeopleService peopleService) { - this.peopleService = peopleService; + public PairMatchingController(MatchingService matchingService) { + this.matchingService = matchingService; } public void run() { @@ -22,14 +24,45 @@ public void run() { if (choice.equals("Q")) { break; } - if(choice.equals("1")){ - peopleService.pairMatching(InputCourse()); + if (choice.equals("1")) { + pairMatching(); } } } + private void pairMatching() { + Course course = InputCourse(); + boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); + + try { + if (!matchingHistoryByCourse) { + matchingService.pairMatching(course); + showPairMatchingResult(course); + } else { + processRetryCourse(matchingService, course); + } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); + } + } + + private void processRetryCourse(MatchingService matchingService, Course course) { + try { + if (InputView.inputRetryCourse().equals("예")) { + matchingService.updatePairMatching(course); + showPairMatchingResult(course); + } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); + } + } + + private void showPairMatchingResult(Course course) { + OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); + } + private void InputPeople() { - peopleService.initPeople(); + matchingService.initPeople(); } private String InputChoice() { @@ -42,11 +75,11 @@ private String InputChoice() { } } - private Course InputCourse(){ - while(true){ - try{ + private Course InputCourse() { + while (true) { + try { return validateInputCourse(InputView.chooseCourse()); - }catch(IllegalArgumentException e){ + } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); } } diff --git a/src/main/java/pairmatching/domain/Course.java b/src/main/java/pairmatching/domain/Course.java index 7c0d5f32b..cb649ace3 100644 --- a/src/main/java/pairmatching/domain/Course.java +++ b/src/main/java/pairmatching/domain/Course.java @@ -13,4 +13,16 @@ public Course(Level level, Position position, String mission) { this.position = position; this.mission = mission; } + + public Position getPosition() { + return position; + } + + public Level getLevel() { + return level; + } + + public String getMission() { + return mission; + } } diff --git a/src/main/java/pairmatching/domain/MatchingHistory.java b/src/main/java/pairmatching/domain/MatchingHistory.java new file mode 100644 index 000000000..0bdc64f0c --- /dev/null +++ b/src/main/java/pairmatching/domain/MatchingHistory.java @@ -0,0 +1,21 @@ +package pairmatching.domain; + +import java.util.List; + +public class MatchingHistory { + private Course course; + private List pair; + + public MatchingHistory(Course course, List pair) { + this.course = course; + this.pair = pair; + } + + public Course getCourse() { + return course; + } + + public List getPair() { + return pair; + } +} diff --git a/src/main/java/pairmatching/domain/Pair.java b/src/main/java/pairmatching/domain/Pair.java new file mode 100644 index 000000000..d330311cb --- /dev/null +++ b/src/main/java/pairmatching/domain/Pair.java @@ -0,0 +1,22 @@ +package pairmatching.domain; + +import java.util.ArrayList; +import java.util.List; + +public class Pair { + private List crews; + + public Pair(String one, String two) { + this.crews = new ArrayList<>(); + crews.add(one); + crews.add(two); + } + + public List getCrews() { + return crews; + } + + public void addCrew(String crew) { + this.crews.add(crew); + } +} diff --git a/src/main/java/pairmatching/domain/People.java b/src/main/java/pairmatching/domain/People.java deleted file mode 100644 index 9d5e938be..000000000 --- a/src/main/java/pairmatching/domain/People.java +++ /dev/null @@ -1,9 +0,0 @@ -package pairmatching.domain; - -public class People { - private final String name; - - public People(String name) { - this.name = name; - } -} diff --git a/src/main/java/pairmatching/repository/FrontendRepository.java b/src/main/java/pairmatching/repository/FrontendRepository.java index 72807dd72..c3e90c17b 100644 --- a/src/main/java/pairmatching/repository/FrontendRepository.java +++ b/src/main/java/pairmatching/repository/FrontendRepository.java @@ -1,5 +1,7 @@ package pairmatching.repository; +import camp.nextstep.edu.missionutils.Console; +import camp.nextstep.edu.missionutils.Randoms; import java.util.ArrayList; import java.util.List; @@ -15,6 +17,7 @@ public void save(List frontend) { } public List getFrontend() { - return frontend; + List shuffle = Randoms.shuffle(frontend); + return shuffle; } } diff --git a/src/main/java/pairmatching/repository/MatchingHistoryRepository.java b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java new file mode 100644 index 000000000..62eef91d5 --- /dev/null +++ b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java @@ -0,0 +1,42 @@ +package pairmatching.repository; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import pairmatching.domain.Course; +import pairmatching.domain.MatchingHistory; +import pairmatching.domain.constants.Level; + +public class MatchingHistoryRepository { + + Set matchingHistories = new HashSet<>(); + + public void deleteMatchingHistory(Course course) { + MatchingHistory matchingHistoryByCourse = findMatchingHistoryByCourse(course); + matchingHistories.remove(matchingHistoryByCourse); + } + + public void save(MatchingHistory matchingHistory) { + matchingHistories.add(matchingHistory); + } + + public MatchingHistory findMatchingHistoryByCourse(Course course) { + for (MatchingHistory matchingHistory : matchingHistories) { + if (matchingHistory.getCourse().getLevel().equals(course.getLevel()) && matchingHistory.getCourse().getPosition().equals(course.getPosition()) && matchingHistory.getCourse().getMission().equals(course.getMission())) { + return matchingHistory; + } + } + return null; + } + + public List findMatchingHistoryByLevel(Level level) { + List findMatchingHistories = new ArrayList<>(); + for (MatchingHistory matchingHistory : matchingHistories) { + if (matchingHistory.getCourse().getLevel().equals(level)) { + findMatchingHistories.add(matchingHistory); + } + } + return findMatchingHistories; + } +} diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java new file mode 100644 index 000000000..3627712c2 --- /dev/null +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -0,0 +1,120 @@ +package pairmatching.service; + +import static pairmatching.constants.FilePath.BACK_FILE_PATH; +import static pairmatching.constants.FilePath.FRONT_FILE_PATH; +import static pairmatching.domain.constants.Position.BACKEND; +import static pairmatching.domain.constants.Position.FRONTEND; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import pairmatching.domain.Course; +import pairmatching.domain.MatchingHistory; +import pairmatching.domain.Pair; +import pairmatching.domain.constants.Level; +import pairmatching.domain.constants.Position; +import pairmatching.repository.BackendRepository; +import pairmatching.repository.FrontendRepository; +import pairmatching.repository.MatchingHistoryRepository; +import pairmatching.utils.Reader; + +public class MatchingService { + private final FrontendRepository frontendRepository; + private final BackendRepository backendRepository; + private final MatchingHistoryRepository matchingHistoryRepository; + + + public MatchingService() { + this.frontendRepository = new FrontendRepository(); + this.backendRepository = new BackendRepository(); + this.matchingHistoryRepository = new MatchingHistoryRepository(); + } + + public void initPeople() { + List Frontend = Reader.readFile(FRONT_FILE_PATH.getPath()); + frontendRepository.save(Frontend); + List Backend = Reader.readFile(BACK_FILE_PATH.getPath()); + backendRepository.save(Backend); + } + + public boolean findMatchingHistoryByCourse(Course course) { + MatchingHistory matchingHistoryByCourse = matchingHistoryRepository.findMatchingHistoryByCourse(course); + if(matchingHistoryByCourse == null){ + return false; + } + Course foundCourse = matchingHistoryByCourse.getCourse(); + return true; + } + + public void pairMatching(Course course) { + Position position = course.getPosition(); + if (position.equals(FRONTEND)) { + frontendMatching(course); + } + if (position.equals(BACKEND)) { + backendMatching(course); + } + } + + private void frontendMatching(Course course) { + List pairs = new ArrayList<>(); + int count = 0; + do { + if((count++) == 3){ + throw new IllegalArgumentException("[ERROR] 매칭에 실패하였습니다."); + } + pairs.clear(); + List frontend = frontendRepository.getFrontend(); + for (int i = 0; i < frontend.size() - 1; i += 2) { + Pair pair = new Pair(frontend.get(i), frontend.get(i + 1)); + pairs.add(pair); + } + if (frontend.size() % 2 == 1) { + int lastIndex = pairs.size() - 1; + pairs.get(lastIndex).addCrew(frontend.get(frontend.size() - 1)); + } + }while(isMatched(course, pairs)); + matchingHistoryRepository.save(new MatchingHistory(course, pairs)); + } + + private void backendMatching(Course course) { + + } + + private boolean isMatched(Course course, List pairs) { + List matchingHistoryByLevel = matchingHistoryRepository.findMatchingHistoryByLevel(course.getLevel()); + for (MatchingHistory matchingHistory : matchingHistoryByLevel) { + List pairHistory = matchingHistory.getPair(); + if (isSamePair(pairs, pairHistory)) { + return true; + } + } + return false; + } + + private boolean isSamePair(List pairs, List pairHistory) { + return pairHistory.stream() + .anyMatch(storedPair -> pairs.stream() + .anyMatch(pair -> isSameCrews(storedPair.getCrews(), pair.getCrews()))); + } + + private boolean isSameCrews(List crewsHistory, List crews) { + long count = crewsHistory.stream() + .filter(crews::contains) + .count(); + + return count == 2 || count == 3; + } + + + public List pairMatchingResult(Course course){ + MatchingHistory matchingHistoryByCourse = matchingHistoryRepository.findMatchingHistoryByCourse(course); + return matchingHistoryByCourse.getPair(); + } + + public void updatePairMatching(Course course) { + matchingHistoryRepository.deleteMatchingHistory(course); + pairMatching(course); + } +} diff --git a/src/main/java/pairmatching/service/PeopleService.java b/src/main/java/pairmatching/service/PeopleService.java deleted file mode 100644 index ab375d6ea..000000000 --- a/src/main/java/pairmatching/service/PeopleService.java +++ /dev/null @@ -1,31 +0,0 @@ -package pairmatching.service; - -import static pairmatching.constants.FilePath.*; - -import java.util.List; -import pairmatching.constants.FilePath; -import pairmatching.domain.Course; -import pairmatching.repository.BackendRepository; -import pairmatching.repository.FrontendRepository; -import pairmatching.utils.Reader; - -public class PeopleService { - private final FrontendRepository frontendRepository; - private final BackendRepository backendRepository; - - public PeopleService() { - this.frontendRepository = new FrontendRepository(); - this.backendRepository = new BackendRepository(); - } - - public void initPeople(){ - List Frontend = Reader.readFile(FRONT_FILE_PATH.getPath()); - frontendRepository.save(Frontend); - List Backend = Reader.readFile(BACK_FILE_PATH.getPath()); - backendRepository.save(Backend); - } - - public void pairMatching(Course inputCourse) { - - } -} diff --git a/src/main/java/pairmatching/view/InputView.java b/src/main/java/pairmatching/view/InputView.java index 5a3955a6f..0a2e82a9c 100644 --- a/src/main/java/pairmatching/view/InputView.java +++ b/src/main/java/pairmatching/view/InputView.java @@ -1,19 +1,26 @@ package pairmatching.view; import static pairmatching.constants.ProgressMessage.COURSE_CHOICE; +import static pairmatching.constants.ProgressMessage.RETRY_COURSE; import static pairmatching.constants.ProgressMessage.START_CHOICE; +import static pairmatching.view.common.Printer.*; import camp.nextstep.edu.missionutils.Console; import pairmatching.view.common.Printer; public class InputView { public static String chooseFunction() { - Printer.printer(START_CHOICE.getMessage()); + printer(START_CHOICE.getMessage()); return Console.readLine(); } public static String chooseCourse() { - Printer.printer(COURSE_CHOICE.getMessage()); + printer(COURSE_CHOICE.getMessage()); + return Console.readLine(); + } + + public static String inputRetryCourse() { + printer(RETRY_COURSE.getMessage()); return Console.readLine(); } } diff --git a/src/main/java/pairmatching/view/OutputView.java b/src/main/java/pairmatching/view/OutputView.java index 256fec7a6..3db400865 100644 --- a/src/main/java/pairmatching/view/OutputView.java +++ b/src/main/java/pairmatching/view/OutputView.java @@ -1,9 +1,26 @@ package pairmatching.view; +import static pairmatching.constants.ProgressMessage.*; +import static pairmatching.view.common.Printer.*; import static pairmatching.view.common.Printer.printer; +import java.util.List; +import pairmatching.constants.ProgressMessage; +import pairmatching.domain.Pair; +import pairmatching.view.common.Printer; + public class OutputView { public static void printErrorMessage(String message) { - printer(message); + printer(message + LINE.getMessage()); + } + + public static void printMatchingResult(List pairMatchingResult) { + printer(PAIR_MATCHING_RESULT.getMessage()); + for (Pair pair : pairMatchingResult) { + List crews = pair.getCrews(); + String formattedOutput = String.join(" : ", crews); + printer(formattedOutput); + } + printer(LINE.getMessage()); } } From 4c514cf7a4843813bb7dd4d2ef9108b593482f88 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:40:12 +0900 Subject: [PATCH 06/16] =?UTF-8?q?feat:=20=EB=B0=B1=EC=97=94=EB=93=9C=20?= =?UTF-8?q?=ED=8E=98=EC=96=B4=EB=A7=A4=EC=B9=AD=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BackendRepository.java | 4 +- .../pairmatching/service/MatchingService.java | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/pairmatching/repository/BackendRepository.java b/src/main/java/pairmatching/repository/BackendRepository.java index a4eeb9d20..ef3ecd337 100644 --- a/src/main/java/pairmatching/repository/BackendRepository.java +++ b/src/main/java/pairmatching/repository/BackendRepository.java @@ -1,5 +1,6 @@ package pairmatching.repository; +import camp.nextstep.edu.missionutils.Randoms; import java.util.List; public class BackendRepository { @@ -10,6 +11,7 @@ public void save(List backend) { } public List getBackend() { - return backend; + List shuffle = Randoms.shuffle(backend); + return shuffle; } } diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java index 3627712c2..30dab721b 100644 --- a/src/main/java/pairmatching/service/MatchingService.java +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -61,27 +61,44 @@ private void frontendMatching(Course course) { List pairs = new ArrayList<>(); int count = 0; do { - if((count++) == 3){ + if ((count++) == 3) { throw new IllegalArgumentException("[ERROR] 매칭에 실패하였습니다."); } pairs.clear(); List frontend = frontendRepository.getFrontend(); - for (int i = 0; i < frontend.size() - 1; i += 2) { - Pair pair = new Pair(frontend.get(i), frontend.get(i + 1)); - pairs.add(pair); - } - if (frontend.size() % 2 == 1) { - int lastIndex = pairs.size() - 1; - pairs.get(lastIndex).addCrew(frontend.get(frontend.size() - 1)); - } - }while(isMatched(course, pairs)); + pairs = matching(frontend); + } while (isMatched(course, pairs)); matchingHistoryRepository.save(new MatchingHistory(course, pairs)); } private void backendMatching(Course course) { + List pairs = new ArrayList<>(); + int count = 0; + do { + if ((count++) == 3) { + throw new IllegalArgumentException("[ERROR] 매칭에 실패하였습니다."); + } + pairs.clear(); + List backend = backendRepository.getBackend(); + pairs = matching(backend); + } while (isMatched(course, pairs)); + matchingHistoryRepository.save(new MatchingHistory(course, pairs)); + } + private List matching(List pairByPosition){ + List pairs = new ArrayList<>(); + for (int i = 0; i < pairByPosition.size() - 1; i += 2) { + Pair pair = new Pair(pairByPosition.get(i), pairByPosition.get(i + 1)); + pairs.add(pair); + } + if(pairByPosition.size() % 2 == 1){ + int lastIndex = pairs.size() - 1; + pairs.get(lastIndex).addCrew(pairByPosition.get(pairByPosition.size() - 1)); + } + return pairs; } + private boolean isMatched(Course course, List pairs) { List matchingHistoryByLevel = matchingHistoryRepository.findMatchingHistoryByLevel(course.getLevel()); for (MatchingHistory matchingHistory : matchingHistoryByLevel) { From 1488aadc01f443d5a360fc7d124bb67da6b51f5e Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:44:03 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat:=20=ED=8E=98=EC=96=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PairMatchingController.java | 18 ++++++++++++++++++ .../repository/BackendRepository.java | 5 +++++ .../repository/FrontendRepository.java | 5 ++--- .../pairmatching/service/MatchingService.java | 15 ++++++--------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 9c20b2839..883cfe418 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -27,6 +27,24 @@ public void run() { if (choice.equals("1")) { pairMatching(); } + if(choice.equals("2")) { + showMatchingHistory(); + } + } + } + + private void showMatchingHistory() { + Course course = InputCourse(); + boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); + + try { + if (matchingHistoryByCourse) { + OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); + } else { + throw new IllegalArgumentException("[ERROR] 매칭 정보가 없습니다."); + } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); } } diff --git a/src/main/java/pairmatching/repository/BackendRepository.java b/src/main/java/pairmatching/repository/BackendRepository.java index ef3ecd337..c5c2b3980 100644 --- a/src/main/java/pairmatching/repository/BackendRepository.java +++ b/src/main/java/pairmatching/repository/BackendRepository.java @@ -1,11 +1,16 @@ package pairmatching.repository; import camp.nextstep.edu.missionutils.Randoms; +import java.util.ArrayList; import java.util.List; public class BackendRepository { private List backend; + public BackendRepository() { + backend = new ArrayList<>(); + } + public void save(List backend) { this.backend = backend; } diff --git a/src/main/java/pairmatching/repository/FrontendRepository.java b/src/main/java/pairmatching/repository/FrontendRepository.java index c3e90c17b..81c4feeeb 100644 --- a/src/main/java/pairmatching/repository/FrontendRepository.java +++ b/src/main/java/pairmatching/repository/FrontendRepository.java @@ -1,15 +1,14 @@ package pairmatching.repository; -import camp.nextstep.edu.missionutils.Console; import camp.nextstep.edu.missionutils.Randoms; import java.util.ArrayList; import java.util.List; public class FrontendRepository { - private List frontend = new ArrayList<>(); + private List frontend; public FrontendRepository() { - + frontend = new ArrayList<>(); } public void save(List frontend) { diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java index 30dab721b..131e4ccae 100644 --- a/src/main/java/pairmatching/service/MatchingService.java +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -7,12 +7,9 @@ import java.util.ArrayList; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import pairmatching.domain.Course; import pairmatching.domain.MatchingHistory; import pairmatching.domain.Pair; -import pairmatching.domain.constants.Level; import pairmatching.domain.constants.Position; import pairmatching.repository.BackendRepository; import pairmatching.repository.FrontendRepository; @@ -40,10 +37,9 @@ public void initPeople() { public boolean findMatchingHistoryByCourse(Course course) { MatchingHistory matchingHistoryByCourse = matchingHistoryRepository.findMatchingHistoryByCourse(course); - if(matchingHistoryByCourse == null){ + if (matchingHistoryByCourse == null) { return false; } - Course foundCourse = matchingHistoryByCourse.getCourse(); return true; } @@ -85,13 +81,13 @@ private void backendMatching(Course course) { matchingHistoryRepository.save(new MatchingHistory(course, pairs)); } - private List matching(List pairByPosition){ + private List matching(List pairByPosition) { List pairs = new ArrayList<>(); for (int i = 0; i < pairByPosition.size() - 1; i += 2) { Pair pair = new Pair(pairByPosition.get(i), pairByPosition.get(i + 1)); pairs.add(pair); } - if(pairByPosition.size() % 2 == 1){ + if (pairByPosition.size() % 2 == 1) { int lastIndex = pairs.size() - 1; pairs.get(lastIndex).addCrew(pairByPosition.get(pairByPosition.size() - 1)); } @@ -100,7 +96,8 @@ private List matching(List pairByPosition){ private boolean isMatched(Course course, List pairs) { - List matchingHistoryByLevel = matchingHistoryRepository.findMatchingHistoryByLevel(course.getLevel()); + List matchingHistoryByLevel = matchingHistoryRepository.findMatchingHistoryByLevel( + course.getLevel()); for (MatchingHistory matchingHistory : matchingHistoryByLevel) { List pairHistory = matchingHistory.getPair(); if (isSamePair(pairs, pairHistory)) { @@ -125,7 +122,7 @@ private boolean isSameCrews(List crewsHistory, List crews) { } - public List pairMatchingResult(Course course){ + public List pairMatchingResult(Course course) { MatchingHistory matchingHistoryByCourse = matchingHistoryRepository.findMatchingHistoryByCourse(course); return matchingHistoryByCourse.getPair(); } From f91e1dcf0100d22a8adc7739c89798bb05ea2181 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:46:07 +0900 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=EB=A7=A4=EC=B9=AD=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PairMatchingController.java | 61 +++++++++++-------- .../repository/MatchingHistoryRepository.java | 4 ++ .../pairmatching/service/MatchingService.java | 4 ++ 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 883cfe418..52da8fc64 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -30,21 +30,33 @@ public void run() { if(choice.equals("2")) { showMatchingHistory(); } + if(choice.equals("3")) { + clearMatchingHistory(); + } } } - private void showMatchingHistory() { - Course course = InputCourse(); - boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); + private void InputPeople() { + matchingService.initPeople(); + } - try { - if (matchingHistoryByCourse) { - OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); - } else { - throw new IllegalArgumentException("[ERROR] 매칭 정보가 없습니다."); + private String InputChoice() { + while (true) { + try { + return validateInputChoice(InputView.chooseFunction()); + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); + } + } + } + + private Course InputCourse() { + while (true) { + try { + return validateInputCourse(InputView.chooseCourse()); + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); } - } catch (IllegalArgumentException e) { - printErrorMessage(e.getMessage()); } } @@ -79,27 +91,22 @@ private void showPairMatchingResult(Course course) { OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); } - private void InputPeople() { - matchingService.initPeople(); - } + private void showMatchingHistory() { + Course course = InputCourse(); + boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); - private String InputChoice() { - while (true) { - try { - return validateInputChoice(InputView.chooseFunction()); - } catch (IllegalArgumentException e) { - printErrorMessage(e.getMessage()); + try { + if (matchingHistoryByCourse) { + OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); + } else { + throw new IllegalArgumentException("[ERROR] 매칭 정보가 없습니다."); } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); } } - private Course InputCourse() { - while (true) { - try { - return validateInputCourse(InputView.chooseCourse()); - } catch (IllegalArgumentException e) { - printErrorMessage(e.getMessage()); - } - } + private void clearMatchingHistory() { + matchingService.clearMatchingHistory(); } } diff --git a/src/main/java/pairmatching/repository/MatchingHistoryRepository.java b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java index 62eef91d5..c8ef7ad89 100644 --- a/src/main/java/pairmatching/repository/MatchingHistoryRepository.java +++ b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java @@ -39,4 +39,8 @@ public List findMatchingHistoryByLevel(Level level) { } return findMatchingHistories; } + + public void clearMatchingHistory() { + matchingHistories.clear(); + } } diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java index 131e4ccae..df7a9a00d 100644 --- a/src/main/java/pairmatching/service/MatchingService.java +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -131,4 +131,8 @@ public void updatePairMatching(Course course) { matchingHistoryRepository.deleteMatchingHistory(course); pairMatching(course); } + + public void clearMatchingHistory() { + matchingHistoryRepository.clearMatchingHistory(); + } } From beb6742b782b008c12edc23bb98815b019b1205d Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:47:14 +0900 Subject: [PATCH 09/16] docs: Update README.md --- docs/README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2e3223636..e2780a815 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,26 +24,26 @@ # 기능 명세서 - 기능을 선택한다. - - [ ] 기능 입력받기 - - [ ] 1 ~ 3, Q가 아닌 경우 예외 처리 + - [X] 기능 입력받기 + - [X] 1 ~ 3, Q가 아닌 경우 예외 처리 - 페어 매칭 - - [ ] 파일 입출력 - - [ ] 입력된 정보를 바탕으로 페어를 매칭한다. - - [ ] 과정(백엔드/프론트엔드)와 레벨을 입력받는다. - - [ ] 셔플 - - [ ] 짝수로 나누어 페어를 매칭한다. - - [ ] 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다. - - [ ] 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다. - - [ ] 3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 처리 - - [ ] 매칭된 결과를 출력한다. - - [ ] 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다. - - [ ] 재 매칭 여부를 입력받는다. + - [X] 파일 입출력 + - [X] 입력된 정보를 바탕으로 페어를 매칭한다. + - [X] 과정(백엔드/프론트엔드)와 레벨을 입력받는다. + - [X] 셔플 + - [X] 짝수로 나누어 페어를 매칭한다. + - [X] 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다. + - [X] 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다. + - [X] 3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 처리 + - [X] 매칭된 결과를 출력한다. + - [X] 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다. + - [X] 재 매칭 여부를 입력받는다. - [ ] 네, 아니오가 아닐 경우, 예외 발생 - - [ ] 네일 경우, 다시 매칭한다. + - [X] 네일 경우, 다시 매칭한다. - 페어 조회 - - [ ] 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키고 다시 입력 받는다. - - [ ] 매칭된 적이 있다면, 페어를 조회한다. + - [X] 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키고 다시 입력 받는다. + - [X] 매칭된 적이 있다면, 페어를 조회한다. - 페어 초기화 - - [ ] 페어를 초기화한다. + - [X] 페어를 초기화한다. - 종료 - - [ ] 페어 매칭을 종료한다. \ No newline at end of file + - [X] 페어 매칭을 종료한다. \ No newline at end of file From 22058f03ebcab19fa4ba5d44dd9deb7619a1d989 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:52:25 +0900 Subject: [PATCH 10/16] =?UTF-8?q?feat:=20=EC=9E=AC=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=97=AC=EB=B6=80=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PairMatchingController.java | 33 ++++++++++++------- .../validator/InputRetryValidator.java | 11 +++++++ 2 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 src/main/java/pairmatching/validator/InputRetryValidator.java diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 52da8fc64..99aa6f3bf 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -2,16 +2,18 @@ import static pairmatching.validator.InputChoiceValidator.validateInputChoice; import static pairmatching.validator.InputCourseValidator.validateInputCourse; +import static pairmatching.validator.InputRetryValidator.validateInputRetry; +import static pairmatching.view.InputView.chooseCourse; +import static pairmatching.view.InputView.chooseFunction; +import static pairmatching.view.InputView.inputRetryCourse; import static pairmatching.view.OutputView.printErrorMessage; import pairmatching.domain.Course; import pairmatching.service.MatchingService; -import pairmatching.view.InputView; import pairmatching.view.OutputView; public class PairMatchingController { private final MatchingService matchingService; - private int retryCount = 0; public PairMatchingController(MatchingService matchingService) { this.matchingService = matchingService; @@ -27,10 +29,10 @@ public void run() { if (choice.equals("1")) { pairMatching(); } - if(choice.equals("2")) { + if (choice.equals("2")) { showMatchingHistory(); } - if(choice.equals("3")) { + if (choice.equals("3")) { clearMatchingHistory(); } } @@ -43,7 +45,7 @@ private void InputPeople() { private String InputChoice() { while (true) { try { - return validateInputChoice(InputView.chooseFunction()); + return validateInputChoice(chooseFunction()); } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); } @@ -53,7 +55,7 @@ private String InputChoice() { private Course InputCourse() { while (true) { try { - return validateInputCourse(InputView.chooseCourse()); + return validateInputCourse(chooseCourse()); } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); } @@ -77,13 +79,20 @@ private void pairMatching() { } private void processRetryCourse(MatchingService matchingService, Course course) { - try { - if (InputView.inputRetryCourse().equals("예")) { - matchingService.updatePairMatching(course); - showPairMatchingResult(course); + while (true) { + try { + String inputRetry = validateInputRetry(inputRetryCourse()); + if (inputRetry.equals("예")) { + matchingService.updatePairMatching(course); + showPairMatchingResult(course); + break; + } + if (inputRetry.equals("아니오")) { + break; + } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); } - } catch (IllegalArgumentException e) { - printErrorMessage(e.getMessage()); } } diff --git a/src/main/java/pairmatching/validator/InputRetryValidator.java b/src/main/java/pairmatching/validator/InputRetryValidator.java new file mode 100644 index 000000000..7e480e9c4 --- /dev/null +++ b/src/main/java/pairmatching/validator/InputRetryValidator.java @@ -0,0 +1,11 @@ +package pairmatching.validator; + +public class InputRetryValidator { + + public static String validateInputRetry(String retry) { + if (!retry.equals("예") && !retry.equals("아니오")) { + throw new IllegalArgumentException("[ERROR] 예, 아니오 중에 입력해주세요."); + } + return retry; + } +} From d05a8fc063dcef2cb87dde242fa9ca85db566473 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:52:40 +0900 Subject: [PATCH 11/16] docs: Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index e2780a815..b3a1ec3f1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ - [X] 매칭된 결과를 출력한다. - [X] 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다. - [X] 재 매칭 여부를 입력받는다. - - [ ] 네, 아니오가 아닐 경우, 예외 발생 + - [X] 네, 아니오가 아닐 경우, 예외 발생 - [X] 네일 경우, 다시 매칭한다. - 페어 조회 - [X] 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키고 다시 입력 받는다. From 53ff293c3a6c2e7f63fb1264becc96b80a464f7a Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:06:04 +0900 Subject: [PATCH 12/16] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=83=81=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pairmatching/constants/ErrorMessage.java | 14 +++++++++-- .../controller/PairMatchingController.java | 3 ++- .../pairmatching/service/MatchingService.java | 5 ++-- src/main/java/pairmatching/utils/Reader.java | 4 ++- .../validator/InputChoiceValidator.java | 4 +-- .../validator/InputCourseValidator.java | 25 ++++++++++++------- .../validator/InputRetryValidator.java | 4 ++- 7 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/main/java/pairmatching/constants/ErrorMessage.java b/src/main/java/pairmatching/constants/ErrorMessage.java index 5eceb6090..a1accb57d 100644 --- a/src/main/java/pairmatching/constants/ErrorMessage.java +++ b/src/main/java/pairmatching/constants/ErrorMessage.java @@ -1,7 +1,17 @@ package pairmatching.constants; public enum ErrorMessage { - INPUT_CHOICE_ERROR("[ERROR] 1, 2, 3, Q 중에 입력해주세요."); + INPUT_CHOICE_ERROR("1, 2, 3, Q 중에 입력해주세요."), + NO_MATCHING_ERROR("매칭 정보가 없습니다."), + INPUT_FORMAT_ERROR("입력 형식이 잘못되었습니다."), + INPUT_NO_VALUE("입력값이 없습니다."), + INVALID_POSITION_ERROR("백엔드, 프론트엔드 중에 입력해주세요."), + INVALID_LEVEL_ERROR(" 레벨1, 레벨2, 레벨3, 레벨4, 레벨5 중에 입력해주세요."), + INVALID_MISSION_ERROR("현재 %s은 미션을 지원하지 않습니다."), + INVALID_LEVEL_MISSION_ERROR("%s의 미션중에서 입력해주세요."), + INPUT_RETRY_ERROR("예, 아니오 중에 입력해주세요."), + MATCHING_ERROR("매칭에 실패하였습니다."), + FILE_READER_ERROR("파일을 읽을 수 없습니다."); private final String message; @@ -10,6 +20,6 @@ public enum ErrorMessage { } public String getMessage() { - return message; + return "[ERROR] " + message; } } diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 99aa6f3bf..f7dd9c9ea 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -1,5 +1,6 @@ package pairmatching.controller; +import static pairmatching.constants.ErrorMessage.NO_MATCHING_ERROR; import static pairmatching.validator.InputChoiceValidator.validateInputChoice; import static pairmatching.validator.InputCourseValidator.validateInputCourse; import static pairmatching.validator.InputRetryValidator.validateInputRetry; @@ -108,7 +109,7 @@ private void showMatchingHistory() { if (matchingHistoryByCourse) { OutputView.printMatchingResult(matchingService.pairMatchingResult(course)); } else { - throw new IllegalArgumentException("[ERROR] 매칭 정보가 없습니다."); + throw new IllegalArgumentException(NO_MATCHING_ERROR.getMessage()); } } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java index df7a9a00d..af36c2cb7 100644 --- a/src/main/java/pairmatching/service/MatchingService.java +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -1,5 +1,6 @@ package pairmatching.service; +import static pairmatching.constants.ErrorMessage.MATCHING_ERROR; import static pairmatching.constants.FilePath.BACK_FILE_PATH; import static pairmatching.constants.FilePath.FRONT_FILE_PATH; import static pairmatching.domain.constants.Position.BACKEND; @@ -58,7 +59,7 @@ private void frontendMatching(Course course) { int count = 0; do { if ((count++) == 3) { - throw new IllegalArgumentException("[ERROR] 매칭에 실패하였습니다."); + throw new IllegalArgumentException(MATCHING_ERROR.getMessage()); } pairs.clear(); List frontend = frontendRepository.getFrontend(); @@ -72,7 +73,7 @@ private void backendMatching(Course course) { int count = 0; do { if ((count++) == 3) { - throw new IllegalArgumentException("[ERROR] 매칭에 실패하였습니다."); + throw new IllegalArgumentException(MATCHING_ERROR.getMessage()); } pairs.clear(); List backend = backendRepository.getBackend(); diff --git a/src/main/java/pairmatching/utils/Reader.java b/src/main/java/pairmatching/utils/Reader.java index 30ad68cab..e2092c882 100644 --- a/src/main/java/pairmatching/utils/Reader.java +++ b/src/main/java/pairmatching/utils/Reader.java @@ -1,5 +1,7 @@ package pairmatching.utils; +import static pairmatching.constants.ErrorMessage.FILE_READER_ERROR; + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@ -16,7 +18,7 @@ public static List readFile(String filePath) { lines.add(line); } } catch (IOException e) { - throw new IllegalArgumentException("[ERROR] 파일을 읽을 수 없습니다."); + throw new IllegalArgumentException(FILE_READER_ERROR.getMessage()); } return lines; } diff --git a/src/main/java/pairmatching/validator/InputChoiceValidator.java b/src/main/java/pairmatching/validator/InputChoiceValidator.java index 0ce9db360..ffe99da48 100644 --- a/src/main/java/pairmatching/validator/InputChoiceValidator.java +++ b/src/main/java/pairmatching/validator/InputChoiceValidator.java @@ -1,8 +1,6 @@ package pairmatching.validator; -import static pairmatching.constants.ErrorMessage.*; - -import pairmatching.constants.ErrorMessage; +import static pairmatching.constants.ErrorMessage.INPUT_CHOICE_ERROR; public class InputChoiceValidator { diff --git a/src/main/java/pairmatching/validator/InputCourseValidator.java b/src/main/java/pairmatching/validator/InputCourseValidator.java index 0d6723af6..c9efcac78 100644 --- a/src/main/java/pairmatching/validator/InputCourseValidator.java +++ b/src/main/java/pairmatching/validator/InputCourseValidator.java @@ -1,8 +1,15 @@ package pairmatching.validator; +import static pairmatching.constants.ErrorMessage.INPUT_FORMAT_ERROR; +import static pairmatching.constants.ErrorMessage.INPUT_NO_VALUE; +import static pairmatching.constants.ErrorMessage.INVALID_LEVEL_ERROR; +import static pairmatching.constants.ErrorMessage.INVALID_LEVEL_MISSION_ERROR; +import static pairmatching.constants.ErrorMessage.INVALID_MISSION_ERROR; +import static pairmatching.constants.ErrorMessage.INVALID_POSITION_ERROR; + import pairmatching.domain.Course; -import pairmatching.domain.constants.Position; import pairmatching.domain.constants.Level; +import pairmatching.domain.constants.Position; public class InputCourseValidator { public static Course validateInputCourse(String inputCourse) { @@ -10,7 +17,7 @@ public static Course validateInputCourse(String inputCourse) { String[] parts = inputCourse.split(", "); if (parts.length != 3) { - throw new IllegalArgumentException("[ERROR] 입력 형식이 잘못되었습니다."); + throw new IllegalArgumentException(INPUT_FORMAT_ERROR.getMessage()); } Position position = validatePosition(parts[0]); @@ -19,9 +26,9 @@ public static Course validateInputCourse(String inputCourse) { return new Course(level, position, mission); } - private static void validateInput(String course){ - if(course == null || course.isEmpty()){ - throw new IllegalArgumentException("[ERROR] 입력값이 없습니다."); + private static void validateInput(String course) { + if (course == null || course.isEmpty()) { + throw new IllegalArgumentException(INPUT_NO_VALUE.getMessage()); } } @@ -31,7 +38,7 @@ private static Position validatePosition(String part) { return position; } } - throw new IllegalArgumentException("[ERROR] 백엔드, 프론트엔드 중에 입력해주세요."); + throw new IllegalArgumentException(INVALID_POSITION_ERROR.getMessage()); } private static Level validateLevel(String part) { @@ -40,19 +47,19 @@ private static Level validateLevel(String part) { return level; } } - throw new IllegalArgumentException("[ERROR] 레벨1, 레벨2, 레벨3, 레벨4, 레벨5 중에 입력해주세요."); + throw new IllegalArgumentException(INVALID_LEVEL_ERROR.getMessage()); } private static String validateMission(Level level, String part) { if (level.getMissions() == null) { - throw new IllegalArgumentException("[ERROR] 현재 " + level.getName() + "은 미션을 지원하지 않습니다."); + throw new IllegalArgumentException(String.format(INVALID_MISSION_ERROR.getMessage(), level.getName())); } for (String mission : level.getMissions()) { if (mission.equals(part)) { return mission; } } - throw new IllegalArgumentException("[ERROR] " + level.getName() + "의 미션 중에 입력해주세요."); + throw new IllegalArgumentException(String.format(INVALID_LEVEL_MISSION_ERROR.getMessage(), level.getName())); } } diff --git a/src/main/java/pairmatching/validator/InputRetryValidator.java b/src/main/java/pairmatching/validator/InputRetryValidator.java index 7e480e9c4..09963d72f 100644 --- a/src/main/java/pairmatching/validator/InputRetryValidator.java +++ b/src/main/java/pairmatching/validator/InputRetryValidator.java @@ -1,10 +1,12 @@ package pairmatching.validator; +import static pairmatching.constants.ErrorMessage.INPUT_RETRY_ERROR; + public class InputRetryValidator { public static String validateInputRetry(String retry) { if (!retry.equals("예") && !retry.equals("아니오")) { - throw new IllegalArgumentException("[ERROR] 예, 아니오 중에 입력해주세요."); + throw new IllegalArgumentException(INPUT_RETRY_ERROR.getMessage()); } return retry; } From ddb0dd826d3729b1fdd58f0855e9c5c3da6dd796 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:16:47 +0900 Subject: [PATCH 13/16] =?UTF-8?q?refactor:=20=EB=A7=A4=EC=A7=81=20?= =?UTF-8?q?=EB=84=98=EB=B2=84=20=EC=83=81=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/ProgressConstants.java | 19 +++++++++++++++++++ .../controller/PairMatchingController.java | 18 ++++++++++++------ .../pairmatching/service/MatchingService.java | 14 +++++++++----- .../validator/InputChoiceValidator.java | 7 ++++++- .../validator/InputRetryValidator.java | 3 ++- 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/main/java/pairmatching/constants/ProgressConstants.java diff --git a/src/main/java/pairmatching/constants/ProgressConstants.java b/src/main/java/pairmatching/constants/ProgressConstants.java new file mode 100644 index 000000000..13c319b4e --- /dev/null +++ b/src/main/java/pairmatching/constants/ProgressConstants.java @@ -0,0 +1,19 @@ +package pairmatching.constants; + +public enum ProgressConstants { + PAIR_MATCHING("1"), + PAIR_SEARCH("2"), + PAIR_RESET("3"), + QUIT("Q"), + RETRY("예"), + NO_RETRY("아니오"); + private final String constName; + + ProgressConstants(String constName) { + this.constName = constName; + } + + public String getConstName() { + return constName; + } +} diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index f7dd9c9ea..6e54b5b02 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -1,6 +1,12 @@ package pairmatching.controller; import static pairmatching.constants.ErrorMessage.NO_MATCHING_ERROR; +import static pairmatching.constants.ProgressConstants.NO_RETRY; +import static pairmatching.constants.ProgressConstants.PAIR_MATCHING; +import static pairmatching.constants.ProgressConstants.PAIR_RESET; +import static pairmatching.constants.ProgressConstants.PAIR_SEARCH; +import static pairmatching.constants.ProgressConstants.QUIT; +import static pairmatching.constants.ProgressConstants.RETRY; import static pairmatching.validator.InputChoiceValidator.validateInputChoice; import static pairmatching.validator.InputCourseValidator.validateInputCourse; import static pairmatching.validator.InputRetryValidator.validateInputRetry; @@ -24,16 +30,16 @@ public void run() { InputPeople(); while (true) { String choice = InputChoice(); - if (choice.equals("Q")) { + if (choice.equals(QUIT.getConstName())) { break; } - if (choice.equals("1")) { + if (choice.equals(PAIR_MATCHING.getConstName())) { pairMatching(); } - if (choice.equals("2")) { + if (choice.equals(PAIR_SEARCH.getConstName())) { showMatchingHistory(); } - if (choice.equals("3")) { + if (choice.equals(PAIR_RESET.getConstName())) { clearMatchingHistory(); } } @@ -83,12 +89,12 @@ private void processRetryCourse(MatchingService matchingService, Course course) while (true) { try { String inputRetry = validateInputRetry(inputRetryCourse()); - if (inputRetry.equals("예")) { + if (inputRetry.equals(RETRY.getConstName())) { matchingService.updatePairMatching(course); showPairMatchingResult(course); break; } - if (inputRetry.equals("아니오")) { + if (inputRetry.equals(NO_RETRY.getConstName())) { break; } } catch (IllegalArgumentException e) { diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java index af36c2cb7..b06879f50 100644 --- a/src/main/java/pairmatching/service/MatchingService.java +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -18,6 +18,10 @@ import pairmatching.utils.Reader; public class MatchingService { + private static final int ZERO = 0; + private static final int MAX_MATCHING_COUNT = 3; + private static final int MIN_PAIR_COUNT = 2; + private static final int MAX_PAIR_COUNT = 3; private final FrontendRepository frontendRepository; private final BackendRepository backendRepository; private final MatchingHistoryRepository matchingHistoryRepository; @@ -56,9 +60,9 @@ public void pairMatching(Course course) { private void frontendMatching(Course course) { List pairs = new ArrayList<>(); - int count = 0; + int count = ZERO; do { - if ((count++) == 3) { + if ((count++) == MAX_MATCHING_COUNT) { throw new IllegalArgumentException(MATCHING_ERROR.getMessage()); } pairs.clear(); @@ -70,9 +74,9 @@ private void frontendMatching(Course course) { private void backendMatching(Course course) { List pairs = new ArrayList<>(); - int count = 0; + int count = ZERO; do { - if ((count++) == 3) { + if ((count++) == MAX_MATCHING_COUNT) { throw new IllegalArgumentException(MATCHING_ERROR.getMessage()); } pairs.clear(); @@ -119,7 +123,7 @@ private boolean isSameCrews(List crewsHistory, List crews) { .filter(crews::contains) .count(); - return count == 2 || count == 3; + return count == MIN_PAIR_COUNT || count == MAX_PAIR_COUNT; } diff --git a/src/main/java/pairmatching/validator/InputChoiceValidator.java b/src/main/java/pairmatching/validator/InputChoiceValidator.java index ffe99da48..d4403ddb5 100644 --- a/src/main/java/pairmatching/validator/InputChoiceValidator.java +++ b/src/main/java/pairmatching/validator/InputChoiceValidator.java @@ -1,11 +1,16 @@ package pairmatching.validator; import static pairmatching.constants.ErrorMessage.INPUT_CHOICE_ERROR; +import static pairmatching.constants.ProgressConstants.PAIR_MATCHING; +import static pairmatching.constants.ProgressConstants.PAIR_RESET; +import static pairmatching.constants.ProgressConstants.PAIR_SEARCH; +import static pairmatching.constants.ProgressConstants.QUIT; public class InputChoiceValidator { public static String validateInputChoice(String choice) { - if (!choice.equals("1") && !choice.equals("2") && !choice.equals("3") && !choice.equals("Q")) { + if (!choice.equals(PAIR_MATCHING.getConstName()) && !choice.equals(PAIR_SEARCH.getConstName()) && !choice.equals( + PAIR_RESET.getConstName()) && !choice.equals(QUIT.getConstName())) { throw new IllegalArgumentException(INPUT_CHOICE_ERROR.getMessage()); } return choice; diff --git a/src/main/java/pairmatching/validator/InputRetryValidator.java b/src/main/java/pairmatching/validator/InputRetryValidator.java index 09963d72f..6ef0073db 100644 --- a/src/main/java/pairmatching/validator/InputRetryValidator.java +++ b/src/main/java/pairmatching/validator/InputRetryValidator.java @@ -1,11 +1,12 @@ package pairmatching.validator; import static pairmatching.constants.ErrorMessage.INPUT_RETRY_ERROR; +import static pairmatching.constants.ProgressConstants.*; public class InputRetryValidator { public static String validateInputRetry(String retry) { - if (!retry.equals("예") && !retry.equals("아니오")) { + if (!retry.equals(RETRY.getConstName()) && !retry.equals(NO_RETRY.getConstName())) { throw new IllegalArgumentException(INPUT_RETRY_ERROR.getMessage()); } return retry; From 09c51495bcecff3180a616b20000fd0dc830c056 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:18:15 +0900 Subject: [PATCH 14/16] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pairmatching/repository/MatchingHistoryRepository.java | 4 +++- .../java/pairmatching/validator/InputChoiceValidator.java | 3 ++- .../java/pairmatching/validator/InputRetryValidator.java | 3 ++- src/main/java/pairmatching/view/InputView.java | 3 +-- src/main/java/pairmatching/view/OutputView.java | 6 ++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/pairmatching/repository/MatchingHistoryRepository.java b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java index c8ef7ad89..e94bc174a 100644 --- a/src/main/java/pairmatching/repository/MatchingHistoryRepository.java +++ b/src/main/java/pairmatching/repository/MatchingHistoryRepository.java @@ -23,7 +23,9 @@ public void save(MatchingHistory matchingHistory) { public MatchingHistory findMatchingHistoryByCourse(Course course) { for (MatchingHistory matchingHistory : matchingHistories) { - if (matchingHistory.getCourse().getLevel().equals(course.getLevel()) && matchingHistory.getCourse().getPosition().equals(course.getPosition()) && matchingHistory.getCourse().getMission().equals(course.getMission())) { + if (matchingHistory.getCourse().getLevel().equals(course.getLevel()) && matchingHistory.getCourse() + .getPosition().equals(course.getPosition()) && matchingHistory.getCourse().getMission() + .equals(course.getMission())) { return matchingHistory; } } diff --git a/src/main/java/pairmatching/validator/InputChoiceValidator.java b/src/main/java/pairmatching/validator/InputChoiceValidator.java index d4403ddb5..b191d6fb7 100644 --- a/src/main/java/pairmatching/validator/InputChoiceValidator.java +++ b/src/main/java/pairmatching/validator/InputChoiceValidator.java @@ -9,7 +9,8 @@ public class InputChoiceValidator { public static String validateInputChoice(String choice) { - if (!choice.equals(PAIR_MATCHING.getConstName()) && !choice.equals(PAIR_SEARCH.getConstName()) && !choice.equals( + if (!choice.equals(PAIR_MATCHING.getConstName()) && !choice.equals(PAIR_SEARCH.getConstName()) + && !choice.equals( PAIR_RESET.getConstName()) && !choice.equals(QUIT.getConstName())) { throw new IllegalArgumentException(INPUT_CHOICE_ERROR.getMessage()); } diff --git a/src/main/java/pairmatching/validator/InputRetryValidator.java b/src/main/java/pairmatching/validator/InputRetryValidator.java index 6ef0073db..1db5cd4f2 100644 --- a/src/main/java/pairmatching/validator/InputRetryValidator.java +++ b/src/main/java/pairmatching/validator/InputRetryValidator.java @@ -1,7 +1,8 @@ package pairmatching.validator; import static pairmatching.constants.ErrorMessage.INPUT_RETRY_ERROR; -import static pairmatching.constants.ProgressConstants.*; +import static pairmatching.constants.ProgressConstants.NO_RETRY; +import static pairmatching.constants.ProgressConstants.RETRY; public class InputRetryValidator { diff --git a/src/main/java/pairmatching/view/InputView.java b/src/main/java/pairmatching/view/InputView.java index 0a2e82a9c..60149b9e0 100644 --- a/src/main/java/pairmatching/view/InputView.java +++ b/src/main/java/pairmatching/view/InputView.java @@ -3,10 +3,9 @@ import static pairmatching.constants.ProgressMessage.COURSE_CHOICE; import static pairmatching.constants.ProgressMessage.RETRY_COURSE; import static pairmatching.constants.ProgressMessage.START_CHOICE; -import static pairmatching.view.common.Printer.*; +import static pairmatching.view.common.Printer.printer; import camp.nextstep.edu.missionutils.Console; -import pairmatching.view.common.Printer; public class InputView { public static String chooseFunction() { diff --git a/src/main/java/pairmatching/view/OutputView.java b/src/main/java/pairmatching/view/OutputView.java index 3db400865..9dc4a515c 100644 --- a/src/main/java/pairmatching/view/OutputView.java +++ b/src/main/java/pairmatching/view/OutputView.java @@ -1,13 +1,11 @@ package pairmatching.view; -import static pairmatching.constants.ProgressMessage.*; -import static pairmatching.view.common.Printer.*; +import static pairmatching.constants.ProgressMessage.LINE; +import static pairmatching.constants.ProgressMessage.PAIR_MATCHING_RESULT; import static pairmatching.view.common.Printer.printer; import java.util.List; -import pairmatching.constants.ProgressMessage; import pairmatching.domain.Pair; -import pairmatching.view.common.Printer; public class OutputView { public static void printErrorMessage(String message) { From 973499529ac417ffc824b44fcc06fc8062dd7743 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Sat, 2 Dec 2023 00:06:16 +0900 Subject: [PATCH 15/16] =?UTF-8?q?fix:=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=AF=B8=EC=85=98=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=9E=AC=EC=9E=85=EB=A0=A5=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 --- .../pairmatching/constants/ErrorMessage.java | 2 +- .../constants/ProgressConstants.java | 2 +- .../constants/ProgressMessage.java | 16 ++++--- .../controller/PairMatchingController.java | 48 +++++++++++++------ .../java/pairmatching/view/InputView.java | 17 +++++-- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/main/java/pairmatching/constants/ErrorMessage.java b/src/main/java/pairmatching/constants/ErrorMessage.java index a1accb57d..5aef846ed 100644 --- a/src/main/java/pairmatching/constants/ErrorMessage.java +++ b/src/main/java/pairmatching/constants/ErrorMessage.java @@ -9,7 +9,7 @@ public enum ErrorMessage { INVALID_LEVEL_ERROR(" 레벨1, 레벨2, 레벨3, 레벨4, 레벨5 중에 입력해주세요."), INVALID_MISSION_ERROR("현재 %s은 미션을 지원하지 않습니다."), INVALID_LEVEL_MISSION_ERROR("%s의 미션중에서 입력해주세요."), - INPUT_RETRY_ERROR("예, 아니오 중에 입력해주세요."), + INPUT_RETRY_ERROR("네, 아니오 중에 입력해주세요."), MATCHING_ERROR("매칭에 실패하였습니다."), FILE_READER_ERROR("파일을 읽을 수 없습니다."); diff --git a/src/main/java/pairmatching/constants/ProgressConstants.java b/src/main/java/pairmatching/constants/ProgressConstants.java index 13c319b4e..5deb99b2e 100644 --- a/src/main/java/pairmatching/constants/ProgressConstants.java +++ b/src/main/java/pairmatching/constants/ProgressConstants.java @@ -5,7 +5,7 @@ public enum ProgressConstants { PAIR_SEARCH("2"), PAIR_RESET("3"), QUIT("Q"), - RETRY("예"), + RETRY("네"), NO_RETRY("아니오"); private final String constName; diff --git a/src/main/java/pairmatching/constants/ProgressMessage.java b/src/main/java/pairmatching/constants/ProgressMessage.java index d6d45a4d1..6ca7748e7 100644 --- a/src/main/java/pairmatching/constants/ProgressMessage.java +++ b/src/main/java/pairmatching/constants/ProgressMessage.java @@ -3,7 +3,7 @@ public enum ProgressMessage { START_CHOICE("기능을 선택하세요.\n1. 페어 매칭\n2. 페어 조회\n3. 페어 초기화\nQ. 종료"), LINE("\n"), - COURSE_CHOICE("\n#############################################\n" + COURSE_INFO("\n#############################################\n" + "과정: 백엔드 | 프론트엔드\n" + "미션:\n" + " - 레벨1: 자동차경주 | 로또 | 숫자야구게임\n" @@ -11,13 +11,15 @@ public enum ProgressMessage { + " - 레벨3:\n" + " - 레벨4: 성능개선 | 배포\n" + " - 레벨5:\n" - + "############################################\n" - + "과정, 레벨, 미션을 선택하세요.\n" + + "############################################"), + RETRY_COURSE_CHECK("\n매칭 정보가 있습니다. 다시 매칭하시겠습니까?\n" + + "네 | 아니오"), + + CHOOSE_COURSE("과정, 레벨, 미션을 선택하세요.\n" + "ex) 백엔드, 레벨1, 자동차경주\n" - + "프론트엔드, 레벨1, 자동차경주\n"), - RETRY_COURSE("\n매칭 정보가 있습니다. 다시 매칭하시겠습니까?\n" - + "예 | 아니오"), - PAIR_MATCHING_RESULT("\n페어 매칭 결과입니다."); + + "프론트엔드, 레벨1, 자동차경주"), + PAIR_MATCHING_RESULT("\n페어 매칭 결과입니다."), + DELETE_MATCHING_RESULT("\n초기화 되었습니다.\n"); private final String message; ProgressMessage(String message) { diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 6e54b5b02..133613616 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -10,13 +10,14 @@ import static pairmatching.validator.InputChoiceValidator.validateInputChoice; import static pairmatching.validator.InputCourseValidator.validateInputCourse; import static pairmatching.validator.InputRetryValidator.validateInputRetry; -import static pairmatching.view.InputView.chooseCourse; import static pairmatching.view.InputView.chooseFunction; -import static pairmatching.view.InputView.inputRetryCourse; +import static pairmatching.view.InputView.chooseRetryCourse; +import static pairmatching.view.InputView.inputRetryCheck; import static pairmatching.view.OutputView.printErrorMessage; import pairmatching.domain.Course; import pairmatching.service.MatchingService; +import pairmatching.view.InputView; import pairmatching.view.OutputView; public class PairMatchingController { @@ -62,7 +63,7 @@ private String InputChoice() { private Course InputCourse() { while (true) { try { - return validateInputCourse(chooseCourse()); + return validateInputCourse(InputView.chooseCourse()); } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); } @@ -71,8 +72,35 @@ private Course InputCourse() { private void pairMatching() { Course course = InputCourse(); - boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); + chooseCourse(course); + } + private void processRetryCourse(MatchingService matchingService, Course course) { + while (true) { + try { + String inputRetry = validateInputRetry(inputRetryCheck()); + if (inputRetry.equals(RETRY.getConstName())) { + matchingService.updatePairMatching(course); + showPairMatchingResult(course); + break; + } + if (inputRetry.equals(NO_RETRY.getConstName())) { + retryCourse(); + break; + } + } catch (IllegalArgumentException e) { + printErrorMessage(e.getMessage()); + } + } + } + + private void retryCourse() { + Course course = InputRetryCourse(); + chooseCourse(course); + } + + private void chooseCourse(Course course) { + boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course); try { if (!matchingHistoryByCourse) { matchingService.pairMatching(course); @@ -85,18 +113,10 @@ private void pairMatching() { } } - private void processRetryCourse(MatchingService matchingService, Course course) { + private Course InputRetryCourse() { while (true) { try { - String inputRetry = validateInputRetry(inputRetryCourse()); - if (inputRetry.equals(RETRY.getConstName())) { - matchingService.updatePairMatching(course); - showPairMatchingResult(course); - break; - } - if (inputRetry.equals(NO_RETRY.getConstName())) { - break; - } + return validateInputCourse(chooseRetryCourse()); } catch (IllegalArgumentException e) { printErrorMessage(e.getMessage()); } diff --git a/src/main/java/pairmatching/view/InputView.java b/src/main/java/pairmatching/view/InputView.java index 60149b9e0..d9d43ba98 100644 --- a/src/main/java/pairmatching/view/InputView.java +++ b/src/main/java/pairmatching/view/InputView.java @@ -1,7 +1,8 @@ package pairmatching.view; -import static pairmatching.constants.ProgressMessage.COURSE_CHOICE; -import static pairmatching.constants.ProgressMessage.RETRY_COURSE; +import static pairmatching.constants.ProgressMessage.CHOOSE_COURSE; +import static pairmatching.constants.ProgressMessage.COURSE_INFO; +import static pairmatching.constants.ProgressMessage.RETRY_COURSE_CHECK; import static pairmatching.constants.ProgressMessage.START_CHOICE; import static pairmatching.view.common.Printer.printer; @@ -14,12 +15,18 @@ public static String chooseFunction() { } public static String chooseCourse() { - printer(COURSE_CHOICE.getMessage()); + printer(COURSE_INFO.getMessage()); + printer(CHOOSE_COURSE.getMessage()); return Console.readLine(); } - public static String inputRetryCourse() { - printer(RETRY_COURSE.getMessage()); + public static String chooseRetryCourse(){ + printer(CHOOSE_COURSE.getMessage()); + return Console.readLine(); + } + + public static String inputRetryCheck() { + printer(RETRY_COURSE_CHECK.getMessage()); return Console.readLine(); } } From 869bc8841e199713cb0233e52c234a13e0282337 Mon Sep 17 00:00:00 2001 From: "im2shandyou@gmail.com" <104557685+im2sh@users.noreply.github.com> Date: Sat, 2 Dec 2023 00:07:30 +0900 Subject: [PATCH 16/16] =?UTF-8?q?feat:=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pairmatching/controller/PairMatchingController.java | 1 + src/main/java/pairmatching/view/OutputView.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/pairmatching/controller/PairMatchingController.java b/src/main/java/pairmatching/controller/PairMatchingController.java index 133613616..e32d07642 100644 --- a/src/main/java/pairmatching/controller/PairMatchingController.java +++ b/src/main/java/pairmatching/controller/PairMatchingController.java @@ -144,5 +144,6 @@ private void showMatchingHistory() { private void clearMatchingHistory() { matchingService.clearMatchingHistory(); + OutputView.printMatchingHistory(); } } diff --git a/src/main/java/pairmatching/view/OutputView.java b/src/main/java/pairmatching/view/OutputView.java index 9dc4a515c..46afb5269 100644 --- a/src/main/java/pairmatching/view/OutputView.java +++ b/src/main/java/pairmatching/view/OutputView.java @@ -1,5 +1,6 @@ package pairmatching.view; +import static pairmatching.constants.ProgressMessage.DELETE_MATCHING_RESULT; import static pairmatching.constants.ProgressMessage.LINE; import static pairmatching.constants.ProgressMessage.PAIR_MATCHING_RESULT; import static pairmatching.view.common.Printer.printer; @@ -21,4 +22,8 @@ public static void printMatchingResult(List pairMatchingResult) { } printer(LINE.getMessage()); } + + public static void printMatchingHistory() { + printer(DELETE_MATCHING_RESULT.getMessage()); + } }