-
Notifications
You must be signed in to change notification settings - Fork 503
[2주차 스터디 제출용] #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[2주차 스터디 제출용] #149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| package pairmatching; | ||
|
|
||
| import pairmatching.system.PairMatchingApplication; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO 구현 진행 | ||
| PairMatchingApplication pairMatchingApplication = new PairMatchingApplication(); | ||
| pairMatchingApplication.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.domain.Level; | ||
| import pairmatching.inputview.MatchingInputView; | ||
| import pairmatching.outputview.ExceptionHandlingOutputView; | ||
| import pairmatching.outputview.MatchingOutputView; | ||
| import pairmatching.repository.MissionRepository; | ||
| import pairmatching.vo.MatchingCommand; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public abstract class AbstractController implements Controller { | ||
| @Override | ||
| public void process(Map<String, Object> model) { | ||
| try { | ||
| doProcess(model); | ||
| } catch (IllegalArgumentException e) { | ||
| ExceptionHandlingOutputView.printExceptionMessage(e.getMessage()); | ||
| process(model); | ||
| } | ||
| } | ||
|
|
||
| protected static MatchingCommand getMatchingCommand() { | ||
| Map<Level, List<String>> allCrewNamesByLevel = MissionRepository.findAllNamesByAllLevel(); | ||
| MatchingOutputView.printInformation(allCrewNamesByLevel); | ||
| return MatchingInputView.getCommand(); | ||
| } | ||
|
|
||
| public abstract void doProcess(Map<String, Object> model); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public interface Controller { | ||
| void process(Map<String, Object> model); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.outputview.MatchingOutputView; | ||
| import pairmatching.service.MatchingService; | ||
| import pairmatching.vo.MatchingCommand; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class FindingController extends AbstractController { | ||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| MatchingCommand matchingCommand = getMatchingCommand(); | ||
|
|
||
| List<List<String>> pairs | ||
| = MatchingService.findAllPairs(matchingCommand.getCourse(), matchingCommand.getMission()); | ||
| MatchingOutputView.printPairInformation(pairs); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.inputview.MainInputView; | ||
| import pairmatching.outputview.MainOutputView; | ||
| import pairmatching.system.ControllerHolder; | ||
| import pairmatching.vo.ControllerName; | ||
| import pairmatching.vo.MainCommand; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class MainController extends AbstractController { | ||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| MainCommand command; | ||
| do { | ||
| MainOutputView.printCommands(); | ||
| command = MainInputView.getCommand(); | ||
|
|
||
| doMatchingProcess(model, command); | ||
| doFindingProcess(model, command); | ||
| if (command == MainCommand.RESET) { | ||
| ControllerHolder.get(ControllerName.RESET).process(model); | ||
| } | ||
|
|
||
| } while (command != MainCommand.QUIT); | ||
| } | ||
|
|
||
| private static void doFindingProcess(Map<String, Object> model, MainCommand command) { | ||
| if (command == MainCommand.FIND) { | ||
| ControllerHolder.get(ControllerName.FIND).process(model); | ||
| } | ||
| } | ||
|
|
||
| private static void doMatchingProcess(Map<String, Object> model, MainCommand command) { | ||
| if (command == MainCommand.MATCHING) { | ||
| ControllerHolder.get(ControllerName.MATCHING).process(model); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.inputview.MatchingInputView; | ||
| import pairmatching.outputview.ExceptionHandlingOutputView; | ||
| import pairmatching.outputview.MatchingOutputView; | ||
| import pairmatching.service.MatchingService; | ||
| import pairmatching.system.exception.PairMatchingAlreadyExistException; | ||
| import pairmatching.system.exception.SamePairMatchedAtSameLevelException; | ||
| import pairmatching.vo.MatchingCommand; | ||
| import pairmatching.vo.RematchingCommand; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class MatchingController extends AbstractController { | ||
|
|
||
| public static final int DUPLICATING_LIMIT_COUNT = 3; | ||
| public static final String MATCHING_FAILED_MESSAGE = "페어 매칭에 실패했습니다."; | ||
|
|
||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| MatchingCommand matchingCommand = getMatchingCommand(); | ||
| try { | ||
| MatchingService.checkPairMatchingAlreadyExists(matchingCommand.getCourse(), matchingCommand.getMission()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MatchingService. static 메소드들에 파라미터로 getCourse, getMission 으로 받아서 던져주는데 개인 취향인 것 같은데 저는 command 를 넘겨주고 Service 클래스에서 뽑아쓰는 방식을 선호해요!!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 저도 우가님 방식으로 하는 게 좋아보여요! 파라미터 개수도 줄어드니 더 좋겠네요 :) 감사합니다! |
||
| matchPairs(matchingCommand); | ||
| } catch (PairMatchingAlreadyExistException e) { | ||
| handlePairMatchingAlreadyExistingCondition(matchingCommand); | ||
| } | ||
| } | ||
|
|
||
| private static void matchPairs(MatchingCommand matchingCommand) { | ||
| doMatch(matchingCommand, 0); | ||
|
|
||
| List<List<String>> pairs | ||
| = MatchingService.findAllPairs(matchingCommand.getCourse(), matchingCommand.getMission()); | ||
| MatchingOutputView.printPairInformation(pairs); | ||
| } | ||
|
|
||
| private static void doMatch(MatchingCommand matchingCommand, int duplicatedCount) { | ||
| try { | ||
| MatchingService.doMatch(matchingCommand.getCourse(), matchingCommand.getMission()); | ||
| } catch (SamePairMatchedAtSameLevelException e) { | ||
| if (duplicatedCount == DUPLICATING_LIMIT_COUNT) { | ||
| ExceptionHandlingOutputView.printExceptionMessage(MATCHING_FAILED_MESSAGE); | ||
| throw e; | ||
| } | ||
| doMatch(matchingCommand, ++duplicatedCount); | ||
| } | ||
| } | ||
|
|
||
| private static void handlePairMatchingAlreadyExistingCondition(MatchingCommand matchingCommand) { | ||
| MatchingOutputView.printAskingReMatchingCommand(); | ||
| RematchingCommand rematchingCommand = MatchingInputView.getReMatchingCommand(); | ||
| if (rematchingCommand == RematchingCommand.YES) { | ||
| matchPairs(matchingCommand); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.outputview.MatchingOutputView; | ||
| import pairmatching.service.MatchingService; | ||
| import pairmatching.vo.MatchingCommand; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class ResetingController extends AbstractController { | ||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| MatchingCommand matchingCommand = getMatchingCommand(); | ||
| MatchingService.resetPairMatching(matchingCommand.getCourse(), matchingCommand.getMission()); | ||
|
|
||
| MatchingOutputView.printResetResult(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.domain.Level; | ||
| import pairmatching.repository.MissionRepository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class SetupController extends AbstractController { | ||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| saveMission(Level.LEVEL1, List.of("자동차경주", "로또", "숫자야구게임")); | ||
| saveMission(Level.LEVEL2, List.of("장바구니", "결제", "지하철노선도")); | ||
| saveMission(Level.LEVEL4, List.of("성능개선", "배포")); | ||
| } | ||
|
|
||
| private void saveMission(Level level, List<String> missionNames) { | ||
| for (String missionName : missionNames) { | ||
| MissionRepository.save(level, missionName); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import pairmatching.domain.Course; | ||
| import pairmatching.repository.CrewRepository; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.util.Map; | ||
| import java.util.Scanner; | ||
|
|
||
| public class SetupCrewController extends AbstractController { | ||
|
|
||
| public static final String FILE_NOT_FOUND_MESSAGE = "파일을 읽어오지 못했습니다."; | ||
| public static final String BACKEND_CREW_MD = "src/main/resources/backend-crew.md"; | ||
| public static final String FRONTEND_CREW_MD = "src/main/resources/frontend-crew.md"; | ||
|
|
||
| @Override | ||
| public void doProcess(Map<String, Object> model) { | ||
| saveCrewsFromFile(BACKEND_CREW_MD, Course.BACKEND); | ||
| saveCrewsFromFile(FRONTEND_CREW_MD, Course.FRONTEND); | ||
| } | ||
|
|
||
| private static void saveCrewsFromFile(String crewFilePath, Course course) { | ||
| try { | ||
| Scanner scanner = new Scanner(new File(crewFilePath)); | ||
| while (scanner.hasNext()) { | ||
| String crewName = scanner.nextLine(); | ||
| CrewRepository.save(course, crewName); | ||
| } | ||
| } catch (FileNotFoundException e) { | ||
| throw new IllegalStateException(FILE_NOT_FOUND_MESSAGE); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum Course { | ||
| BACKEND("백엔드"), | ||
| FRONTEND("프론트엔드"); | ||
|
|
||
| public static final String NOT_EXISTING_COURSE_NAME = "존재하지 않는 과정 이름"; | ||
| private final String name; | ||
|
|
||
| Course(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static Course findByName(String courseName) { | ||
| return Arrays.stream(Course.values()) | ||
| .filter(course -> course.name.equals(courseName)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException(NOT_EXISTING_COURSE_NAME)); | ||
| } | ||
|
|
||
| // 추가 기능 구현 | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Course{" + | ||
| "name='" + name + '\'' + | ||
| '}'; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum Level { | ||
| LEVEL1("레벨1"), | ||
| LEVEL2("레벨2"), | ||
| LEVEL3("레벨3"), | ||
| LEVEL4("레벨4"), | ||
| LEVEL5("레벨5"); | ||
|
|
||
| public static final String NOT_EXISTING_LEVEL_NAME = "존재하지 않는 레벨 이름"; | ||
| private String name; | ||
|
|
||
| Level(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static Level findByName(String levelName) { | ||
| return Arrays.stream(Level.values()) | ||
| .filter(level -> level.name.equals(levelName)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException(NOT_EXISTING_LEVEL_NAME)); | ||
| } | ||
|
|
||
| // 추가 기능 구현 | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Level{" + | ||
| "name='" + name + '\'' + | ||
| '}'; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Mission { | ||
| private final Level level; | ||
| private final String name; | ||
|
|
||
| public Mission(Level level, String name) { | ||
| this.level = level; | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static Mission of(Level level, String missionName) { | ||
| return new Mission(level, missionName); | ||
| } | ||
|
|
||
| public Level getLevel() { | ||
| return level; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Mission mission = (Mission) o; | ||
| return level == mission.level && name.equals(mission.name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(level, name); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Mission{" + | ||
| "level=" + level + | ||
| ", name='" + name + '\'' + | ||
| '}'; | ||
| } | ||
|
|
||
| public boolean isLevel(Level level) { | ||
| return this.level.equals(level); | ||
| } | ||
|
|
||
| public boolean isName(String missionName) { | ||
| return this.name.equals(missionName); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package pairmatching.inputview; | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console; | ||
|
|
||
| public class AbstractInputView { | ||
| protected static String readInput() { | ||
| return Console.readLine(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 여기서 빌드 그래들을 수정하는거였군요!
List.of 문법 사용이 안돼서 애먹었었는데,,ㅎ 감사합니당