forked from techeer-sv/Infinite_Challenge_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 지하철 역 등록 및 삭제 - 노선에 등록된 역은 삭제 불가 - 중복된 지하철 역 이름이 등록 불가 - 지하철 역 이름은 2글자 이상 - 지하철 역의 목록을 조회 가능 Closes techeer-sv#4, techeer-sv#5, techeer-sv#6, techeer-sv#7, techeer-sv#8
- Loading branch information
1 parent
3e47622
commit b426627
Showing
9 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package subway.controller; | ||
|
||
import java.util.Scanner; | ||
|
||
import subway.service.SubwayService; | ||
import subway.view.LineView; | ||
import subway.view.MainView; | ||
import subway.view.SectionView; | ||
import subway.view.StationView; | ||
|
||
public class MainController { | ||
private final StationController stationController; | ||
private final LineController lineController; | ||
private final SectionController sectionController; | ||
private final MainView mainView; | ||
private final Scanner scanner; | ||
private final SubwayService subwayService; | ||
|
||
public MainController(Scanner scanner) { | ||
this.scanner = scanner; | ||
this.stationController = new StationController(scanner); | ||
this.lineController = new LineController(scanner); | ||
this.sectionController = new SectionController(scanner); | ||
this.subwayService = new SubwayService(); | ||
this.mainView = new MainView(); | ||
} | ||
|
||
public void run() { | ||
subwayService.settingData(); | ||
selectSubway(); | ||
} | ||
|
||
public void selectSubway() { | ||
boolean quit = true; | ||
while (quit){ | ||
mainView.printMainView(); | ||
mainView.printSelectView(); | ||
String command = scanner.nextLine().trim(); | ||
if (command.equals("1")) { | ||
stationController.manageStation(); | ||
} | ||
if (command.equals("2")) { | ||
lineController.manageLine(); | ||
} | ||
if (command.equals("3")) { | ||
sectionController.manageSection(); | ||
} | ||
if (command.equals("4")) { | ||
sectionController.printLine(); | ||
} | ||
if (command.equals("Q")) { | ||
quit = false; | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package subway.controller; | ||
|
||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
import subway.service.StationService; | ||
import subway.view.MainView; | ||
import subway.view.StationView; | ||
|
||
public class StationController { | ||
private final StationView stationView; | ||
private final MainView mainView; | ||
private final StationService stationService; | ||
private final Scanner scanner; | ||
|
||
public StationController(Scanner scanner) { | ||
this.scanner = scanner; | ||
this.stationView = new StationView(); | ||
this.mainView = new MainView(); | ||
this.stationService = new StationService(); | ||
} | ||
|
||
public void manageStation() { | ||
boolean back = true; | ||
while (back) { | ||
stationView.printStationView(); | ||
mainView.printSelectView(); | ||
String command = scanner.nextLine().trim(); | ||
if (command.equals("1")) { | ||
stationView.printAddStation(); | ||
String stationName = scanner.nextLine().trim(); | ||
stationService.addStation(stationName); | ||
stationView.printSuccessAddStation(); | ||
} | ||
if (command.equals("2")) { | ||
stationView.printDeleteStation(); | ||
String stationName = scanner.nextLine().trim(); | ||
stationService.deleteStation(stationName); | ||
stationView.printSuccessDeleteStation(); | ||
} | ||
if (command.equals("3")) { | ||
stationView.printSelectStation(); | ||
List<String> stations = stationService.getStations(); | ||
stationView.printStationList(stations); | ||
} | ||
if (command.equals("B")) { | ||
back = false; | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package subway.service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import subway.domain.SectionRepository; | ||
import subway.domain.Station; | ||
import subway.domain.StationRepository; | ||
import subway.view.error.StationErrorMessage; | ||
|
||
public class StationService { | ||
public void addStation(String stationName) { | ||
if (stationName.length() < 2) { | ||
throw new IllegalArgumentException(StationErrorMessage.WRONG_NAME.getMessage()); | ||
} | ||
|
||
if (StationRepository.stations().stream() | ||
.anyMatch(station -> station.getName().equals(stationName))) { | ||
throw new IllegalArgumentException(StationErrorMessage.ALREADY_EXISTS.getMessage()); | ||
} | ||
|
||
Station newStation = new Station(stationName); | ||
StationRepository.addStation(newStation); | ||
} | ||
|
||
public void deleteStation(String stationName) { | ||
if (SectionRepository.isStationInSection(stationName)) { | ||
throw new IllegalArgumentException(StationErrorMessage.UN_REMOVABLE.getMessage()); | ||
} | ||
|
||
if (!StationRepository.deleteStation(stationName)) { | ||
throw new IllegalArgumentException(StationErrorMessage.NOT_EXISTS.getMessage()); | ||
} | ||
} | ||
|
||
public List<String> getStations() { | ||
return StationRepository.stations().stream() | ||
.map(Station::getName) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package subway.view; | ||
|
||
import java.util.List; | ||
|
||
public class StationView { | ||
private static final String STATION = "## 역 관리 화면"; | ||
private static final String ADD_STATION = "1. 역 등록"; | ||
private static final String REMOVE_STATION = "2. 역 삭제"; | ||
private static final String VIEW_STATIONS = "3. 역 조회"; | ||
private static final String BACK = "B. 돌아가기"; | ||
private static final String ADD_STATION_NAME = "## 등록할 역 이름을 입력하세요."; | ||
private static final String DELETE_STATION_NAME = "## 삭제할 역 이름을 입력하세요."; | ||
private static final String SUCCESS_ADD_STATION = "[INFO] 지하철 역이 등록되었습니다."; | ||
private static final String SUCCESS_DELETE_STATION = "[INFO] 지하철 역이 삭제되었습니다."; | ||
private static final String SELECT_STATION = "## 역 목록"; | ||
|
||
|
||
|
||
public void printStationView() { | ||
System.out.println(STATION + "\n" + | ||
ADD_STATION + "\n" + | ||
REMOVE_STATION + "\n" + | ||
VIEW_STATIONS + "\n" + | ||
BACK); | ||
} | ||
|
||
public void printAddStation() { | ||
System.out.println(ADD_STATION_NAME); | ||
} | ||
|
||
public void printSuccessAddStation() { | ||
System.out.println(SUCCESS_ADD_STATION); | ||
} | ||
|
||
public void printDeleteStation() { | ||
System.out.println(DELETE_STATION_NAME); | ||
} | ||
|
||
public void printSuccessDeleteStation() {System.out.println(SUCCESS_DELETE_STATION);} | ||
|
||
public void printSelectStation() {System.out.println(SELECT_STATION);} | ||
|
||
public void printStationList(List<String> stations) { | ||
stations.forEach(station -> System.out.println("[INFO] " + station)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package subway.view.error; | ||
|
||
public enum StationErrorMessage { | ||
ALREADY_EXISTS("[ERROR] 중복된 이름입니다."), | ||
NOT_EXISTS("[ERROR] 존재하지 않는 역입니다."), | ||
UN_REMOVABLE("[ERROR] 노선이 등록되어 있는 역입니다."), | ||
WRONG_NAME("[ERROR] 지하철 역 이름은 2글자 이상이어야 합니다."); | ||
|
||
private String message; | ||
|
||
StationErrorMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getMessage(){ | ||
return message; | ||
} | ||
} |