Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
49 changes: 49 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Flow
1. 기능을 선택한다.
- **1 ~ 3, Q가 아닌 경우 예외 발생**
2. 페어 매칭
- 페어 매칭을 위한 정보를 입력받는다.
- 정보는 파일 입출력으로 입력된다.
- 입력된 정보를 바탕으로 페어를 매칭한다.
- 입력된 정보를 Shuffle을 통해 섞는다.
- 짝수로 나누어 페어를 매칭한다.
- 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다.
- 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다.
- **3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 발생**
- 과정(백엔드/프론트엔드)와 레벨을 입력받는다.
- 매칭된 결과를 출력한다.
- 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다.
- 네,아니오가 아닐 경우 예외 발생
3. 페어 조회
- 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키# 다시 입력 받는다.
- 매칭된 적이 있다면, 페어를 조회한다.
4. 페어 초기화
- 페어를 초기화한다.
5. 종료
- 페어 매칭을 종료한다.

# 기능 명세서
- 기능을 선택한다.
- [X] 기능 입력받기
- [X] 1 ~ 3, Q가 아닌 경우 예외 처리
- 페어 매칭
- [X] 파일 입출력
- [X] 입력된 정보를 바탕으로 페어를 매칭한다.
- [X] 과정(백엔드/프론트엔드)와 레벨을 입력받는다.
- [X] 셔플
- [X] 짝수로 나누어 페어를 매칭한다.
- [X] 마지막에 남은 사람이 3명이라면 그 팀은 3명이 팀이다.
- [X] 같은 레벨에서 이미 페어로 만난 적이 있다면, 다시 랜덤으로 섞는다.
- [X] 3회 시도까지 매칭이 되지 않거나 매칭되는 경우의 수가 없다면, 에러 처리
- [X] 매칭된 결과를 출력한다.
- [X] 만약, 매칭이 되었는데 다시 1을 입력받는다면, 재 매칭 여부를 입력받는다.
- [X] 재 매칭 여부를 입력받는다.
- [X] 네, 아니오가 아닐 경우, 예외 발생
- [X] 네일 경우, 다시 매칭한다.
- 페어 조회
- [X] 매칭된 적이 없는 경우, 매칭 이력이 없다는 예외를 발생시키고 다시 입력 받는다.
- [X] 매칭된 적이 있다면, 페어를 조회한다.
- 페어 초기화
- [X] 페어를 초기화한다.
- 종료
- [X] 페어 매칭을 종료한다.
7 changes: 6 additions & 1 deletion src/main/java/pairmatching/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package pairmatching;

import pairmatching.controller.PairMatchingController;
import pairmatching.service.MatchingService;

public class Application {
public static void main(String[] args) {
// TODO 구현 진행
MatchingService matchingService = new MatchingService();
PairMatchingController pairMatchingController = new PairMatchingController(matchingService);
pairMatchingController.run();
}
}
25 changes: 25 additions & 0 deletions src/main/java/pairmatching/constants/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pairmatching.constants;

public enum ErrorMessage {
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;

ErrorMessage(String message) {
this.message = message;
}

public String getMessage() {
return "[ERROR] " + message;
}
}
15 changes: 15 additions & 0 deletions src/main/java/pairmatching/constants/FilePath.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/main/java/pairmatching/constants/ProgressConstants.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions src/main/java/pairmatching/constants/ProgressMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pairmatching.constants;

public enum ProgressMessage {
START_CHOICE("기능을 선택하세요.\n1. 페어 매칭\n2. 페어 조회\n3. 페어 초기화\nQ. 종료"),
LINE("\n"),
COURSE_INFO("\n#############################################\n"
+ "과정: 백엔드 | 프론트엔드\n"
+ "미션:\n"
+ " - 레벨1: 자동차경주 | 로또 | 숫자야구게임\n"
+ " - 레벨2: 장바구니 | 결제 | 지하철노선도\n"
+ " - 레벨3:\n"
+ " - 레벨4: 성능개선 | 배포\n"
+ " - 레벨5:\n"
+ "############################################"),
RETRY_COURSE_CHECK("\n매칭 정보가 있습니다. 다시 매칭하시겠습니까?\n"
+ "네 | 아니오"),

CHOOSE_COURSE("과정, 레벨, 미션을 선택하세요.\n"
+ "ex) 백엔드, 레벨1, 자동차경주\n"
+ "프론트엔드, 레벨1, 자동차경주"),
PAIR_MATCHING_RESULT("\n페어 매칭 결과입니다."),
DELETE_MATCHING_RESULT("\n초기화 되었습니다.\n");
private final String message;

ProgressMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
149 changes: 149 additions & 0 deletions src/main/java/pairmatching/controller/PairMatchingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
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;
import static pairmatching.view.InputView.chooseFunction;
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 {
private final MatchingService matchingService;

public PairMatchingController(MatchingService matchingService) {
this.matchingService = matchingService;
}

public void run() {
InputPeople();
while (true) {
String choice = InputChoice();
if (choice.equals(QUIT.getConstName())) {
break;
}
if (choice.equals(PAIR_MATCHING.getConstName())) {
pairMatching();
}
if (choice.equals(PAIR_SEARCH.getConstName())) {
showMatchingHistory();
}
if (choice.equals(PAIR_RESET.getConstName())) {
clearMatchingHistory();
}
}
}

private void InputPeople() {
matchingService.initPeople();
}

private String InputChoice() {
while (true) {
try {
return validateInputChoice(chooseFunction());
} catch (IllegalArgumentException e) {
printErrorMessage(e.getMessage());
}
}
}

private Course InputCourse() {
while (true) {
try {
return validateInputCourse(InputView.chooseCourse());
} catch (IllegalArgumentException e) {
printErrorMessage(e.getMessage());
}
}
}

private void pairMatching() {
Course course = InputCourse();
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);
showPairMatchingResult(course);
} else {
processRetryCourse(matchingService, course);
}
} catch (IllegalArgumentException e) {
printErrorMessage(e.getMessage());
}
}

private Course InputRetryCourse() {
while (true) {
try {
return validateInputCourse(chooseRetryCourse());
} catch (IllegalArgumentException e) {
printErrorMessage(e.getMessage());
}
}
}

private void showPairMatchingResult(Course course) {
OutputView.printMatchingResult(matchingService.pairMatchingResult(course));
}

private void showMatchingHistory() {
Course course = InputCourse();
boolean matchingHistoryByCourse = matchingService.findMatchingHistoryByCourse(course);

try {
if (matchingHistoryByCourse) {
OutputView.printMatchingResult(matchingService.pairMatchingResult(course));
} else {
throw new IllegalArgumentException(NO_MATCHING_ERROR.getMessage());
}
} catch (IllegalArgumentException e) {
printErrorMessage(e.getMessage());
}
}

private void clearMatchingHistory() {
matchingService.clearMatchingHistory();
OutputView.printMatchingHistory();
}
}
28 changes: 28 additions & 0 deletions src/main/java/pairmatching/domain/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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;
}

public Position getPosition() {
return position;
}

public Level getLevel() {
return level;
}

public String getMission() {
return mission;
}
}
21 changes: 21 additions & 0 deletions src/main/java/pairmatching/domain/MatchingHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pairmatching.domain;

import java.util.List;

public class MatchingHistory {
private Course course;
private List<Pair> pair;

public MatchingHistory(Course course, List<Pair> pair) {
this.course = course;
this.pair = pair;
}

public Course getCourse() {
return course;
}

public List<Pair> getPair() {
return pair;
}
}
22 changes: 22 additions & 0 deletions src/main/java/pairmatching/domain/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package pairmatching.domain;

import java.util.ArrayList;
import java.util.List;

public class Pair {
private List<String> crews;

public Pair(String one, String two) {
this.crews = new ArrayList<>();
crews.add(one);
crews.add(two);
}

public List<String> getCrews() {
return crews;
}

public void addCrew(String crew) {
this.crews.add(crew);
}
}
Loading