diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..6ffeea682 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,90 @@ +# ๐Ÿš€๋ฏธ์…˜ - ํŽ˜์–ด๋งค์นญ๊ด€๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ + +## ์ง„ํ–‰๋ฐฉ์‹ + +- ๋ฏธ์…˜์€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ, ๊ณผ์ œ ์š”๊ตฌ ์‚ฌํ•ญ ์„ธ๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. +- ์„ธ ๊ฐœ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค. + +--- + +### ๐Ÿ’™๊ตฌํ˜„ ๋ชฉํ‘œ + +- ๊ณผ์ •๊ณผ ๋ฏธ์…˜์— ํ•ด๋‹นํ•˜๋Š” ํŽ˜์–ด ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๊ตฌํ˜„ํ•œ๋‹ค. + +### ๐Ÿ“œ๊ตฌํ˜„ ๋™์ž‘ + +1. ๋ณด๊ธฐ ์ค‘์—์„œ ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•œ๋‹ค.(์ˆซ์ž๋กœ ์ž…๋ ฅ) +2. ๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์„ ์ถœ๋ ฅํ•œ๋‹ค. +3. ๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์„ ์ž…๋ ฅํ•œ๋‹ค.(ex. ๋ฐฑ์—”๋“œ, ๋ ˆ๋ฒจ1, ์ž๋™์ฐจ๊ฒฝ์ฃผ) +4. ํŽ˜์–ด ๋งค์นญ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. +5. Q(์ข…๋ฃŒ)๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋ฏธ์…˜์ด ์ข…๋ฃŒ๋œ๋‹ค. + +--- + +## ๐Ÿ”๊ตฌํ˜„ ๋กœ์ง + +- ### Main diagram + +- [x] Application - ์‹œ์ž‘ +- [x] controller - View ์™€ Service ์— ์œ„์น˜ํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ตœ์ข…์ ์ธ ๋‹จ์ผ ๊ธฐ๋Šฅ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + - [x] MainController - ์„ธ ๊ฐœ์˜ ์ปจํŠธ๋กค๋Ÿฌ์™€ ์—ฐ๊ฒฐ(์ค‘์•™ ์ œ์–ด) + - [x] MatchingController - ํŽ˜์–ด ๋งค์นญ + - [x] InquiryController - ํŽ˜์–ด ์กฐํšŒ + - [x] InitializeController - ํŽ˜์–ด ์ดˆ๊ธฐํ™” + +- [x] domain(model) - ํ•ด๋‹น ํ”„๋กœ๊ทธ๋žจ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ์ฒด ํด๋ž˜์Šค ํŒŒ์ผ์ด ๋‹ด๊ฒจ์žˆ์Šต๋‹ˆ๋‹ค. + - [x] Course - ๊ณผ์ •(๋ฐฑ์—”๋“œ, ํ”„๋ก ํŠธ์—”๋“œ) + - [x] Crew - ํฌ๋ฃจ ์ด๋ฆ„ + - [x] Level - ๋ ˆ๋ฒจ๋ณ„ ๋ฏธ์…˜๋“ค + - [x] Mission - ๊ฐ๊ฐ์˜ ๋ฏธ์…˜๋“ค + - [x] Missions - ๊ฐ๊ฐ์˜ ๋ฏธ์…˜๋“ค์„ ํŠธ๋ฆฌ๋งต์œผ๋กœ ์„ ์–ธํ•œ๋’ค, ๋ ˆ๋ฒจ๋ณ„๋กœ ArrayList ๋กœ ๋ฌถ์Œ + +- [x] repository - Entity(domain ์— ์žˆ๋Š” ํด๋ž˜์Šค)์— ์˜ํ•ด ์ƒ์„ฑ๋œ DB์— ์ ‘๊ทผํ•˜๋Š” ๋ฉ”์„œ๋“œ ๋“ค์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค. + - [x] CrewRepository + - [x] MatchingService + +- [x] service - Repository ์™€ Controller ์‚ฌ์ด์—์„œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๋“ค์ด ์œ„์น˜ํ•˜์—ฌ ์žˆ์Šต๋‹ˆ๋‹ค. +- Controller ๋กœ๋ถ€ํ„ฐ ์•Œ๋งž๋Š” ์ •๋ณด๋ฅผ ๊ฐ€๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์—ญํ• ์ž…๋‹ˆ๋‹ค. + - [x] InitializeService + - [x] InquiryService + - [x] MatchingService + +- ### Util diagram + +- [x] utils - ์•ž์—์„œ ๋งํ•œ ์ฝ”๋“œ ์™ธ์˜ ์ž…๋ ฅ ๊ฐ’์ด ์กฐ๊ฑด์— ๋งž๋Š” ๊ฐ’์ธ์ง€ ์ฒดํฌํ•˜๋Š” ๋กœ์ง์ด ๋‹ด๊ฒจ์žˆ์Šต๋‹ˆ๋‹ค. + - [x] ExceptionMessage + - [x] Validate + +- ### View diagram + +- [x] view - ์‚ฌ์šฉ์ž ์ž…์ถœ๋ ฅ์„ ํ•ด์ฃผ๋Š” ๋กœ์ง์ด ๋‹ด๊ฒจ์žˆ์Šต๋‹ˆ๋‹ค. + - [x] InputView + - [x] OutputView + +--- + +## โœ…๊ธฐ๋Šฅ ๋ชฉ๋ก checkList + +- [x] 1.๊ธฐ๋Šฅ ์„ ํƒ + - [x] ํ”„๋กœ๊ทธ๋žจ์ด ์‹œ์ž‘ํ•˜๋ฉด ๊ธฐ๋Šฅ์˜ ์ข…๋ฃŒ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. + - [x] ๊ธฐ๋Šฅ์˜ ์ข…๋ฃŒ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ , ๊ทธ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. +- [x] 2.ํŽ˜์–ด ๋งค์นญ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + - [x] ๊ณผ์ •๊ณผ ๋ฏธ์…˜์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•œ๋‹ค. + - [x] ๋งค์นญํ•˜๊ณ ์ž ํ•˜๋Š” ๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. + - [x] ๋งค์นญ์ด ์ •์ƒ์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๋ฉด ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค. +- [x] 3.ํŽ˜์–ด ์กฐํšŒ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + - [x] ๋งค์นญ ์ด๋ ฅ์ด ์žˆ์œผ๋ฉด ํ•ด๋‹น ๋ฏธ์…˜์˜ ํŽ˜์–ด ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. + - [x] ๋งค์นญ ์ด๋ ฅ์ด ์—†์œผ๋ฉด ๋งค์นญ ์ด๋ ฅ์ด ์—†๋‹ค๋Š” ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. +- [x] 4.ํŽ˜์–ด ์ดˆ๊ธฐํ™” ๊ธฐ๋Šฅ ๊ตฌํ˜„ + - [x] ํŽ˜์–ด ์ดˆ๊ธฐํ™” ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํŽ˜์–ด ๋ฏธ์…˜์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ดˆ๊ธฐํ™” ๋œ๋‹ค. + - [x] ์ดˆ๊ธฐํ™” ๋˜์—ˆ๋‹ค๋Š” ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•œ๋‹ค. +- [x] ์ข…๋ฃŒ(Q)๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๊ฒŒ์ž„์ด ์ข…๋ฃŒ๋œ๋‹ค. + +## โœ…์˜ˆ์™ธ ์ฒ˜๋ฆฌ + +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ IllegalArgumentException๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , + - [ERROR]๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ํ•ด๋‹น ๋ถ€๋ถ„๋ถ€ํ„ฐ ๋‹ค์‹œ ์ž…๋ ฅ์„ ๋ฐ›๋Š”๋‹ค. +- [x] 1.๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜๋Š” ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•  ๋•Œ, 1~3 ์ด์™ธ์— ๋‹ค๋ฅธ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ + - [x] Q ์ด์™ธ์— ๋‹ค๋ฅธ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ +- [x] 2.๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์— ์žˆ๋Š” ๋‹จ์–ด ์ด์™ธ์— ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ +- [x] 3.ํŽ˜์–ด ์กฐํšŒ ๊ธฐ๋Šฅ์—์„œ "๋„ค | ์•„๋‹ˆ์˜ค" ๋ฅผ ์ œ์™ธํ•œ ๋‹ค๋ฅธ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ \ No newline at end of file diff --git a/src/main/java/pairmatching/Application.java b/src/main/java/pairmatching/Application.java index 6f56e741c..d688faefa 100644 --- a/src/main/java/pairmatching/Application.java +++ b/src/main/java/pairmatching/Application.java @@ -1,7 +1,14 @@ package pairmatching; +import pairmatching.controller.MainController; + +import static pairmatching.repository.CrewRepository.initCrewInfo; + public class Application { + private static final MainController mainController = new MainController(); public static void main(String[] args) { // TODO ๊ตฌํ˜„ ์ง„ํ–‰ + initCrewInfo(); + mainController.run(); } } diff --git a/src/main/java/pairmatching/controller/InitializeController.java b/src/main/java/pairmatching/controller/InitializeController.java new file mode 100644 index 000000000..815a98e62 --- /dev/null +++ b/src/main/java/pairmatching/controller/InitializeController.java @@ -0,0 +1,14 @@ +package pairmatching.controller; + +import pairmatching.service.InitializeService; + +import static pairmatching.view.OutputView.printInitialize; + +public class InitializeController { + public static final InitializeService initializeService = new InitializeService(); + + public void run() { + initializeService.matchInfo(); + printInitialize(); + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/controller/InquiryController.java b/src/main/java/pairmatching/controller/InquiryController.java new file mode 100644 index 000000000..ea637d332 --- /dev/null +++ b/src/main/java/pairmatching/controller/InquiryController.java @@ -0,0 +1,29 @@ +package pairmatching.controller; + +import pairmatching.service.InquiryService; + +import static pairmatching.controller.MatchingController.missions; +import static pairmatching.view.InputView.getInquiryInfo; +import static pairmatching.view.OutputView.printMatchPair; +import static pairmatching.view.OutputView.printMissionInfo; + +public class InquiryController { + private static final InquiryService inquiryService = new InquiryService(); + + public void run() { + boolean flag = false; + while (!flag) { + try { + printMissionInfo(missions); + printMatchInfo(getInquiryInfo()); + flag = true; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + public void printMatchInfo(String input) { + printMatchPair(inquiryService.getMatchInfo(input)); + } +} diff --git a/src/main/java/pairmatching/controller/MainController.java b/src/main/java/pairmatching/controller/MainController.java new file mode 100644 index 000000000..6c0d0c462 --- /dev/null +++ b/src/main/java/pairmatching/controller/MainController.java @@ -0,0 +1,39 @@ +package pairmatching.controller; + +import pairmatching.utils.Validate; +import pairmatching.view.InputView; + +public class MainController { + public static final Validate validate = new Validate(); + public static final MatchingController matchingController = new MatchingController(); + public static final InquiryController inquiryController = new InquiryController(); + public static final InitializeController initializeController = new InitializeController(); + public static final InputView inputView = new InputView(); + + public void run() { + boolean flag = false; + while (!flag) { + try { + String input = validate.checkMissionInfo(inputView.getMainSelect()); + readSelect(input); + if (input.equals("Q")) { + flag = true; + } + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + private void readSelect(String input) { + if (input.equals("1")) { + matchingController.run(); + } + if (input.equals("2")) { + inquiryController.run(); + } + if (input.equals("3")) { + initializeController.run(); + } + } +} diff --git a/src/main/java/pairmatching/controller/MatchingController.java b/src/main/java/pairmatching/controller/MatchingController.java new file mode 100644 index 000000000..1ffb8fcd3 --- /dev/null +++ b/src/main/java/pairmatching/controller/MatchingController.java @@ -0,0 +1,64 @@ +package pairmatching.controller; + +import pairmatching.domain.*; +import pairmatching.service.MatchingService; + + +import static pairmatching.utils.Validate.checkInfoCount; +import static pairmatching.utils.Validate.checkRematchAnswer; +import static pairmatching.view.InputView.getConfirmRematch; +import static pairmatching.view.InputView.getMatchingInfo; +import static pairmatching.view.OutputView.printMatchPair; +import static pairmatching.view.OutputView.printMissionInfo; + +public class MatchingController { + public static final Missions missions = new Missions(); + public static final MatchingService matchingService = new MatchingService(); + + public void run() { + boolean flag = false; + while (!flag) { + try { + printMissionInfo(missions); + String input = getMatchingInfo(); + matchPair(input, missions); + flag = true; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + } + + public void matchPair(String input, Missions missions) { + String[] infoArr = input.split(", "); + checkInfoCount(infoArr); + Course course = matchingService.checkCourse(infoArr[0]); + Level level = matchingService.checkLevel(infoArr[1]); + Mission mission = matchingService.checkMission(infoArr[1], infoArr[2], missions); + + if (matchingService.checkExistPair(course,level,mission)) { + if (!getRematchAnswer()) { + return; + } + printMatchPair(matchingService.rematchAndSavePair(course, level, mission)); + return; + } + printMatchPair(matchingService.firstMatch(course, level, mission)); + } + + public boolean getRematchAnswer() { + boolean flag = false; + while (!flag) { + try { + String input = checkRematchAnswer(getConfirmRematch()); + if (input.equals("์•„๋‹ˆ์š”")) { + return false; + } + flag = true; + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + } + return true; + } +} diff --git a/src/main/java/pairmatching/domain/Course.java b/src/main/java/pairmatching/domain/Course.java new file mode 100644 index 000000000..74685c0c6 --- /dev/null +++ b/src/main/java/pairmatching/domain/Course.java @@ -0,0 +1,44 @@ +package pairmatching.domain; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public enum Course { + BACKEND("๋ฐฑ์—”๋“œ"), + FRONTEND("ํ”„๋ก ํŠธ์—”๋“œ"); + + private String name; + + Course(String name) { + this.name = name; + } + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + public String getName() { + return name; + } + + public static List getList() { + return Arrays.stream(Course.values()) + .map(Course::getName) + .sequential() + .collect(Collectors.toList()); + } + + public static boolean isExist(String name) { + List result = Arrays.stream(Course.values()) + .filter(course -> course.getName().equals(name)) + .collect(Collectors.toList()); + if (result.size() == 1) { + return true; + } + return false; + } + + public static Course getEnumCourse(String name) { + return Arrays.stream(Course.values()) + .filter((course -> course.getName().equals(name))) + .collect(Collectors.toList()).get(0); + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/domain/Crew.java b/src/main/java/pairmatching/domain/Crew.java new file mode 100644 index 000000000..379a0b4d1 --- /dev/null +++ b/src/main/java/pairmatching/domain/Crew.java @@ -0,0 +1,16 @@ +package pairmatching.domain; + +public class Crew { + private Course course; + private String name; + + public Crew(Course course, String name) { + this.course = course; + this.name = name; + } + + @Override + public String toString() { + return name; + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/domain/Level.java b/src/main/java/pairmatching/domain/Level.java new file mode 100644 index 000000000..43250abc5 --- /dev/null +++ b/src/main/java/pairmatching/domain/Level.java @@ -0,0 +1,46 @@ +package pairmatching.domain; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public enum Level { + LEVEL1("๋ ˆ๋ฒจ1"), + LEVEL2("๋ ˆ๋ฒจ2"), + LEVEL3("๋ ˆ๋ฒจ3"), + LEVEL4("๋ ˆ๋ฒจ4"), + LEVEL5("๋ ˆ๋ฒจ5"); + + private String name; + + Level(String name) { + this.name = name; + } + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + public String getName() { + return name; + } + + public static List getList() { + return Arrays.stream(Level.values()) + .sequential() + .collect(Collectors.toList()); + } + + public static Level getEnumLevel(String name) { + return Arrays.stream(Level.values()) + .filter(level -> level.getName().equals(name)) + .collect(Collectors.toList()).get(0); + } + + public static boolean isExist(String name) { + List result = Arrays.stream(Level.values()) + .filter(level -> level.getName().equals(name)) + .collect(Collectors.toList()); + if (result.size() == 1) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/domain/MatchInfo.java b/src/main/java/pairmatching/domain/MatchInfo.java new file mode 100644 index 000000000..9157a506c --- /dev/null +++ b/src/main/java/pairmatching/domain/MatchInfo.java @@ -0,0 +1,33 @@ +package pairmatching.domain; + +import java.util.List; + +public class MatchInfo { + private Course course; + private Level level; + private Mission mission; + private List> pair; + + public MatchInfo(Course course, Level level, Mission mission, List> pair) { + this.course = course; + this.level = level; + this.mission = mission; + this.pair = pair; + } + + public List> getPairInfo() { + return pair; + } + + public Course getCourse() { + return course; + } + + public Level getLevel() { + return level; + } + + public Mission getMission() { + return mission; + } +} diff --git a/src/main/java/pairmatching/domain/Mission.java b/src/main/java/pairmatching/domain/Mission.java new file mode 100644 index 000000000..dbd35c476 --- /dev/null +++ b/src/main/java/pairmatching/domain/Mission.java @@ -0,0 +1,37 @@ +package pairmatching.domain; + +import java.util.Arrays; +import java.util.Optional; + +import static pairmatching.utils.ExceptionMessage.ERROR_MISSION_NOT_EXIST; + +public enum Mission { + CAR_RACE("์ž๋™์ฐจ๊ฒฝ์ฃผ"), + LOTTO("๋กœ๋˜"), + BASEBALL("์ˆซ์ž์•ผ๊ตฌ๊ฒŒ์ž„"), + BASKET("์žฅ๋ฐ”๊ตฌ๋‹ˆ"), + PAY("๊ฒฐ์ œ"), + SUBWAY("์ง€ํ•˜์ฒ ๋…ธ์„ ๋„"), + IMPROVEMENT_PERFORMANCE("์„ฑ๋Šฅ๊ฐœ์„ "), + DEPLOYMENT("๋ฐฐํฌ"); + + private String name; + + Mission(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Mission getEnumMission(String name) { + Optional result = Arrays.stream(Mission.values()) + .filter(mission -> mission.getName().equals(name)).findFirst(); + + if (result.isPresent()) { + return result.get(); + } + throw new IllegalArgumentException(ERROR_MISSION_NOT_EXIST); + } +} diff --git a/src/main/java/pairmatching/domain/Missions.java b/src/main/java/pairmatching/domain/Missions.java new file mode 100644 index 000000000..0d048bbea --- /dev/null +++ b/src/main/java/pairmatching/domain/Missions.java @@ -0,0 +1,47 @@ +package pairmatching.domain; + +import java.util.*; +import java.util.stream.Collectors; + +public class Missions { + private static Map> missionMap; + + public Missions() { + missionMap = new TreeMap<>(); + init(); + } + + private void init() { + Level.getList().stream() + .forEach(level -> missionMap.put(level, new ArrayList<>())); + + addInfo(); + } + + private void addInfo() { + missionMap.get(Level.LEVEL1).add(Mission.CAR_RACE); + missionMap.get(Level.LEVEL1).add(Mission.LOTTO); + missionMap.get(Level.LEVEL1).add(Mission.BASEBALL); + + missionMap.get(Level.LEVEL2).add(Mission.BASKET); + missionMap.get(Level.LEVEL2).add(Mission.PAY); + missionMap.get(Level.LEVEL2).add(Mission.SUBWAY); + + missionMap.get(Level.LEVEL4).add(Mission.IMPROVEMENT_PERFORMANCE); + missionMap.get(Level.LEVEL4).add(Mission.DEPLOYMENT); + } + + public List getValue(Level level) { + return Collections.unmodifiableList(missionMap.get(level).stream() + .map(mission -> mission.getName()) + .collect(Collectors.toList())); + } + + public boolean isExist(String level, String mission) { + if (missionMap.get(Level.getEnumLevel(level)) + .contains(Mission.getEnumMission(mission))) { + return true; + } + return false; + } +} diff --git a/src/main/java/pairmatching/repository/CrewRepository.java b/src/main/java/pairmatching/repository/CrewRepository.java new file mode 100644 index 000000000..3f76cca4f --- /dev/null +++ b/src/main/java/pairmatching/repository/CrewRepository.java @@ -0,0 +1,68 @@ +package pairmatching.repository; + +import pairmatching.domain.Course; +import pairmatching.domain.Crew; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static pairmatching.utils.ExceptionMessage.ERROR_FILE_READ; + +public class CrewRepository { + private static final CrewRepository instance = new CrewRepository(); + private static final Map> crews = new HashMap<>(); + + + private CrewRepository() { + + } + + public static CrewRepository getInstance() { + return instance; + } + + public static void initCrewInfo() { + try { + readBackendCrew(); + readFrontendCrew(); + } catch (IOException e) { + throw new IllegalArgumentException(ERROR_FILE_READ); + } + } + + private static void readBackendCrew() throws IOException { + List crewList = new ArrayList<>(); + BufferedReader reader = new BufferedReader( + new FileReader("src/main/resources/backend-crew.md") + ); + String str; + while ((str = reader.readLine()) != null) { + crewList.add(new Crew(Course.BACKEND, str)); + } + reader.close(); + crews.put(Course.BACKEND, crewList); + } + + private static void readFrontendCrew() throws IOException { + List crewList = new ArrayList<>(); + BufferedReader reader = new BufferedReader( + new FileReader("src/main/resources/frontend-crew.md") + ); + String str; + while ((str = reader.readLine()) != null) { + crewList.add(new Crew(Course.FRONTEND, str)); + } + reader.close(); + crews.put(Course.FRONTEND, crewList); + } + + public List getCrew(Course course) { + return crews.get(course).stream().collect(Collectors.toList()); + } +} diff --git a/src/main/java/pairmatching/repository/MatchInfoRepository.java b/src/main/java/pairmatching/repository/MatchInfoRepository.java new file mode 100644 index 000000000..5333b2254 --- /dev/null +++ b/src/main/java/pairmatching/repository/MatchInfoRepository.java @@ -0,0 +1,65 @@ +package pairmatching.repository; + +import pairmatching.domain.Course; +import pairmatching.domain.Level; +import pairmatching.domain.MatchInfo; +import pairmatching.domain.Mission; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class MatchInfoRepository { + private static final MatchInfoRepository instance = new MatchInfoRepository(); + private static List matchInfoList = new ArrayList<>(); + + private MatchInfoRepository() { + } + + public static MatchInfoRepository getInstance() { + return instance; + } + + public MatchInfo addMatchInfo(MatchInfo matchInfo) { + matchInfoList.add(matchInfo); + return matchInfo; + } + + public MatchInfo reviseMatchInfo(MatchInfo info) { + int index = 0; + int removeIndex = 0; + for (MatchInfo matchInfo : matchInfoList) { + if (info.getCourse() == matchInfo.getCourse() && info.getLevel() == matchInfo.getLevel() + && info.getMission() == matchInfo.getMission()) { + removeIndex = index; + } + index++; + } + matchInfoList.remove(removeIndex); + matchInfoList.add(info); + return info; + } + public boolean isExist(Course course, Level level, Mission mission) { + List result = matchInfoList.stream() + .filter(matchInfo -> course == matchInfo.getCourse()) + .filter(matchInfo -> level == matchInfo.getLevel()) + .filter(matchInfo -> mission == matchInfo.getMission()) + .collect(Collectors.toList()); + if (result.size() == 1) { + return true; + } + return false; + } + + public MatchInfo findMatchInfo(Course course, Level level, Mission mission) { + return matchInfoList.stream() + .filter(matchInfo -> course == matchInfo.getCourse()) + .filter(matchInfo -> level == matchInfo.getLevel()) + .filter(matchInfo -> mission == matchInfo.getMission()) + .collect(Collectors.toList()).get(0); + } + public void initMatchInfo() { + matchInfoList = new ArrayList<>(); + } + +} diff --git a/src/main/java/pairmatching/service/InitializeService.java b/src/main/java/pairmatching/service/InitializeService.java new file mode 100644 index 000000000..828e98fc9 --- /dev/null +++ b/src/main/java/pairmatching/service/InitializeService.java @@ -0,0 +1,11 @@ +package pairmatching.service; + +import pairmatching.repository.MatchInfoRepository; + +public class InitializeService { + public static final MatchInfoRepository matchInfoRepository = MatchInfoRepository.getInstance(); + + public void matchInfo() { + matchInfoRepository.initMatchInfo(); + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/service/InquiryService.java b/src/main/java/pairmatching/service/InquiryService.java new file mode 100644 index 000000000..2e2315caa --- /dev/null +++ b/src/main/java/pairmatching/service/InquiryService.java @@ -0,0 +1,30 @@ +package pairmatching.service; + +import pairmatching.domain.Course; +import pairmatching.domain.Level; +import pairmatching.domain.MatchInfo; +import pairmatching.domain.Mission; +import pairmatching.repository.MatchInfoRepository; + +import static pairmatching.controller.MatchingController.missions; +import static pairmatching.utils.ExceptionMessage.ERROR_NOT_EXIST_MATCH; +import static pairmatching.utils.Validate.checkInfoCount; +public class InquiryService { + private static final MatchInfoRepository matchingInfoRepository = MatchInfoRepository.getInstance(); + public static final MatchingService matchService = new MatchingService(); + + public MatchInfo getMatchInfo(String input) { + String[] infoArr = input.split(", "); + checkInfoCount(infoArr); + Course course = matchService.checkCourse(infoArr[0]); + Level level = matchService.checkLevel(infoArr[1]); + Mission mission = matchService.checkMission(infoArr[1], infoArr[2], missions); + try { + return matchingInfoRepository.findMatchInfo(course, level, mission); + } catch (IndexOutOfBoundsException e) { + throw new IllegalArgumentException(ERROR_NOT_EXIST_MATCH); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/pairmatching/service/MatchingService.java b/src/main/java/pairmatching/service/MatchingService.java new file mode 100644 index 000000000..aa99f954e --- /dev/null +++ b/src/main/java/pairmatching/service/MatchingService.java @@ -0,0 +1,73 @@ +package pairmatching.service; + +import camp.nextstep.edu.missionutils.Randoms; +import pairmatching.domain.*; +import pairmatching.repository.CrewRepository; +import pairmatching.repository.MatchInfoRepository; + +import java.util.ArrayList; +import java.util.List; + +import static pairmatching.utils.ExceptionMessage.*; +import static pairmatching.utils.Validate.checkEachInfo; + +public class MatchingService { + + private static final MatchInfoRepository matchInfoRepository = MatchInfoRepository.getInstance(); + private static final CrewRepository crewRepository = CrewRepository.getInstance(); + + public Course checkCourse(String course) { + checkEachInfo(course); + if (!Course.isExist(course)) { + throw new IllegalArgumentException(ERROR_COURSE_NOT_EXIST); + } + return Course.getEnumCourse(course); + } + + public Level checkLevel(String level) { + checkEachInfo(level); + if (!Level.isExist(level)) { + throw new IllegalArgumentException(ERROR_LEVEL_NOT_EXIST); + } + return Level.getEnumLevel(level); + } + + public Mission checkMission(String level, String mission, Missions missions) { + checkEachInfo(mission); + if (!missions.isExist(level, mission)) { + throw new IllegalArgumentException(ERROR_MISSION_NOT_EXIST); + } + return Mission.getEnumMission(mission); + } + + public boolean checkExistPair(Course course, Level level, Mission mission) { + if (matchInfoRepository.isExist(course, level, mission)) { + return true; + } + return false; + } + + public MatchInfo firstMatch(Course course, Level level, Mission mission) { + return matchInfoRepository.addMatchInfo(matchPair(course, level, mission)); + } + + public MatchInfo rematchAndSavePair(Course course, Level level, Mission mission) { + return matchInfoRepository.reviseMatchInfo(matchPair(course, level, mission)); + } + + public MatchInfo matchPair(Course course, Level level, Mission mission) { + List> pair = new ArrayList<>(); + List crews = Randoms.shuffle(crewRepository.getCrew(course)); + int index = 0; + while (crews.size() != index) { + List onePair = new ArrayList<>(); + onePair.add(crews.get(index++)); + onePair.add(crews.get(index++)); + if (index == crews.size() - 1) { + onePair.add(crews.get(index++)); + } + pair.add(onePair); + } + return new MatchInfo(course, level, mission, pair); + } +} \ No newline at end of file diff --git a/src/main/java/pairmatching/utils/ExceptionMessage.java b/src/main/java/pairmatching/utils/ExceptionMessage.java new file mode 100644 index 000000000..1c020e1b2 --- /dev/null +++ b/src/main/java/pairmatching/utils/ExceptionMessage.java @@ -0,0 +1,17 @@ +package pairmatching.utils; + +public class ExceptionMessage { + public static final String ERROR_INVALID_SELECT ="[ERROR] ๋ณด๊ธฐ์— ์—†๋Š” ์„ ํƒ์ž…๋‹ˆ๋‹ค."; + public static final String ERROR_EMPTY_INPUT = "[ERROR] ๋น„์–ด์žˆ๋Š” ๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."; + public static final String ERROR_LESS_INFO = "[ERROR] 3๊ฐœ์˜ ์ž…๋ ฅ ๊ฐ’์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."; + public static final String ERROR_FRONT_BLANK = "[ERROR] ์ž…๋ ฅ๊ฐ’ ์•ž์— ๊ณต๋ฐฑ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. " + + "๊ณต๋ฐฑ์€ ์ž…๋ ฅ๊ฐ’๋“ค ์‚ฌ์ด์— ๊ตฌ๋ถ„์„ ํ•  ๋•Œ ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”."; + public static final String ERROR_COURSE_NOT_EXIST = "[ERROR] ์ž…๋ ฅ๋œ ์ฝ”์Šค๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."; + public static final String ERROR_LEVEL_NOT_EXIST = "[ERROR] ์ž…๋ ฅ๋œ ๋ ˆ๋ฒจ์€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."; + public static final String ERROR_MISSION_NOT_EXIST = "[ERROR] ์ž…๋ ฅ๋œ ๋ฏธ์…˜์€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."; + + public static final String ERROR_FILE_READ = "[ERROR] ํŒŒ์ผ์„ ์ฝ๊ธฐ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "; + + public static final String ERROR_NOT_EXIST_MATCH = "[ERROR] ํ•ด๋‹น ๋งค์น˜๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."; +} + diff --git a/src/main/java/pairmatching/utils/Validate.java b/src/main/java/pairmatching/utils/Validate.java new file mode 100644 index 000000000..a31ebd508 --- /dev/null +++ b/src/main/java/pairmatching/utils/Validate.java @@ -0,0 +1,49 @@ +package pairmatching.utils; + +import java.util.Arrays; +import java.util.List; + +import static pairmatching.utils.ExceptionMessage.*; + +public class Validate { + private final static String ERROR_MESSAGE = "[ERROR]"; + + public static String checkMissionInfo(String input) { + List candidate = Arrays.asList(new String[]{"1", "2", "3", "Q"}); + if (!candidate.contains(input)) { + throw new IllegalArgumentException(ERROR_MESSAGE + "๋ณด๊ธฐ์— ์žˆ๋Š” ๊ธฐ๋Šฅ ์„ ํƒ๋งŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."); + } + return input; + } + + public static String checkRematchAnswer(String input) { + List candidate = Arrays.asList(new String[]{"๋„ค", "์•„๋‹ˆ์š”"}); + if (!candidate.contains(input)) { + throw new IllegalArgumentException(ERROR_INVALID_SELECT); + } + return input; + } + + public static void checkEachInfo(String input) { + checkEmptyValue(input); + checkFrontBlank(input); + } + + private static void checkEmptyValue(String input) { + if (input.isEmpty()) { + throw new IllegalArgumentException(ERROR_EMPTY_INPUT); + } + } + + private static void checkFrontBlank(String input) { + if (input.charAt(0) == ' ') { + throw new IllegalArgumentException(ERROR_FRONT_BLANK); + } + } + + public static void checkInfoCount(String[] input) { + if (input.length != 3) { + throw new IllegalArgumentException(ERROR_LESS_INFO); + } + } +} diff --git a/src/main/java/pairmatching/view/InputView.java b/src/main/java/pairmatching/view/InputView.java new file mode 100644 index 000000000..5d65fd594 --- /dev/null +++ b/src/main/java/pairmatching/view/InputView.java @@ -0,0 +1,32 @@ +package pairmatching.view; + +import camp.nextstep.edu.missionutils.Console; + +public class InputView { + public static String getMainSelect() { + System.out.println("\n๊ธฐ๋Šฅ์„ ์„ ํƒํ•˜์„ธ์š”.\n" + + "1. ํŽ˜์–ด ๋งค์นญ\n" + + "2. ํŽ˜์–ด ์กฐํšŒ\n" + + "3. ํŽ˜์–ด ์ดˆ๊ธฐํ™”\n" + + "Q. ์ข…๋ฃŒ"); + return Console.readLine(); + } + + public static String getMatchingInfo() { + System.out.println("๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์„ ์„ ํƒํ•˜์„ธ์š”.\n" + + "ex) ๋ฐฑ์—”๋“œ, ๋ ˆ๋ฒจ1, ์ž๋™์ฐจ๊ฒฝ์ฃผ"); + return Console.readLine(); + } + + public static String getConfirmRematch() { + System.out.println("\n๋งค์นญ ์ •๋ณด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋งค์นญํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n" + + "๋„ค | ์•„๋‹ˆ์˜ค"); + return Console.readLine(); + } + + public static String getInquiryInfo() { + System.out.println("๊ณผ์ •, ๋ ˆ๋ฒจ, ๋ฏธ์…˜์„ ์„ ํƒํ•˜์„ธ์š”.\n" + + "ex) ๋ฐฑ์—”๋“œ, ๋ ˆ๋ฒจ1, ์ž๋™์ฐจ๊ฒฝ์ฃผ"); + 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..27c9be5f2 --- /dev/null +++ b/src/main/java/pairmatching/view/OutputView.java @@ -0,0 +1,33 @@ +package pairmatching.view; + +import pairmatching.domain.*; + +import java.util.List; + +public class OutputView { + public static void printMissionInfo(Missions missions) { + System.out.println("\n#############################################"); + System.out.print("๊ณผ์ •: "); + System.out.println(String.join(" | ", Course.getList())); + System.out.println("๋ฏธ์…˜: "); + for (Level level : Level.getList()) { + System.out.print(" - " + level.getName() + ": "); + System.out.println(String.join(" | ", missions.getValue(level))); + } + System.out.println("#############################################"); + } + + public static void printMatchPair(MatchInfo matchInfo) { + System.out.println("\nํŽ˜์–ด ๋งค์นญ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค."); + for (List pair : matchInfo.getPairInfo()) { + for (int i = 0; i < pair.size() - 1; i++) { + System.out.print(pair.get(i) + " : "); + } + System.out.println(pair.get(pair.size() - 1)); + } + } + + public static void printInitialize() { + System.out.println("\n์ดˆ๊ธฐํ™” ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. "); + } +}