From a2f291b4c20bf2b0ce8aef1539112d5ae99eb2a6 Mon Sep 17 00:00:00 2001 From: giantim Date: Sun, 10 May 2020 10:59:22 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC,=20=EC=A0=9C=EB=84=A4=EB=A6=AD=EC=97=90=20?= =?UTF-8?q?=EC=9E=90=EB=A3=8C=ED=98=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LineController 제네릭에 자료형 추가 LineStationController 제네릭에 자료형 추가 StationController 제네릭에 자료형 추가 LineResponse 생성자에 bgColor 를 이용하도록 변경 LineStation 사용하지 않는 메서드 삭제 --- .../admin/controller/LineController.java | 15 +++++++------- .../controller/LineStationController.java | 6 +++--- .../admin/controller/StationController.java | 11 +++++----- .../subway/admin/domain/LineStation.java | 4 ---- .../subway/admin/dto/LineResponse.java | 20 +++++++++---------- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/main/java/wooteco/subway/admin/controller/LineController.java b/src/main/java/wooteco/subway/admin/controller/LineController.java index 387114afbf..eb8bd93b09 100644 --- a/src/main/java/wooteco/subway/admin/controller/LineController.java +++ b/src/main/java/wooteco/subway/admin/controller/LineController.java @@ -22,14 +22,14 @@ @RestController @RequestMapping("/lines") public class LineController { - private LineService lineService; + private final LineService lineService; public LineController(LineService lineService) { this.lineService = lineService; } @PostMapping - public ResponseEntity createLines(@RequestBody Request view) { + public ResponseEntity createLines(@RequestBody Request view) { Line line = view.getContent().toLine(); Line persistLine = lineService.save(line); @@ -39,25 +39,26 @@ public ResponseEntity createLines(@RequestBody Request view) { } @GetMapping - public ResponseEntity showLines() { + public ResponseEntity> showLines() { List lines = lineService.showLines(); - return ResponseEntity.ok().body(lines); + List lineResponses = LineResponse.listOf(lines); + return ResponseEntity.ok().body(lineResponses); } @GetMapping("/{id}") - public ResponseEntity getLine(@PathVariable Long id) { + public ResponseEntity getLine(@PathVariable Long id) { LineResponse lineResponse = lineService.findLineWithStationsById(id); return ResponseEntity.ok().body(lineResponse); } @PutMapping("/{id}") - public ResponseEntity updateLine(@PathVariable Long id, @RequestBody Request lineRequest) { + public ResponseEntity updateLine(@PathVariable Long id, @RequestBody Request lineRequest) { lineService.updateLine(id, lineRequest.getContent().toLine()); return ResponseEntity.ok().build(); } @DeleteMapping("/{id}") - public ResponseEntity deleteLine(@PathVariable Long id) { + public ResponseEntity deleteLine(@PathVariable Long id) { lineService.deleteLineById(id); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/wooteco/subway/admin/controller/LineStationController.java b/src/main/java/wooteco/subway/admin/controller/LineStationController.java index 0006611e6e..bf6d4a9f53 100644 --- a/src/main/java/wooteco/subway/admin/controller/LineStationController.java +++ b/src/main/java/wooteco/subway/admin/controller/LineStationController.java @@ -20,7 +20,7 @@ public LineStationController(LineService lineService) { } @PostMapping - public ResponseEntity createLineStation(@PathVariable Long lineId, + public ResponseEntity createLineStation(@PathVariable Long lineId, @RequestBody Request lineStationRequest) { LineStationCreateRequest lineStationCreateRequest = lineStationRequest.getContent(); lineService.addLineStation(lineId, lineStationCreateRequest); @@ -31,13 +31,13 @@ public ResponseEntity createLineStation(@PathVariable Long lineId, } @GetMapping - public ResponseEntity getLineStations(@PathVariable Long lineId) { + public ResponseEntity> getLineStations(@PathVariable Long lineId) { List lineStations = lineService.findLineStations(lineId); return ResponseEntity.ok().body(lineStations); } @DeleteMapping("/{stationId}") - public ResponseEntity deleteLine(@PathVariable Long lineId, @PathVariable Long stationId) { + public ResponseEntity deleteLine(@PathVariable Long lineId, @PathVariable Long stationId) { lineService.removeLineStation(lineId, stationId); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/wooteco/subway/admin/controller/StationController.java b/src/main/java/wooteco/subway/admin/controller/StationController.java index c8204970ab..42e2216e16 100644 --- a/src/main/java/wooteco/subway/admin/controller/StationController.java +++ b/src/main/java/wooteco/subway/admin/controller/StationController.java @@ -1,16 +1,15 @@ package wooteco.subway.admin.controller; -import java.net.URI; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; - import wooteco.subway.admin.domain.Station; import wooteco.subway.admin.dto.Request; import wooteco.subway.admin.dto.StationCreateRequest; import wooteco.subway.admin.dto.StationResponse; import wooteco.subway.admin.repository.StationRepository; +import java.net.URI; + @RestController @RequestMapping("/stations") public class StationController { @@ -21,7 +20,7 @@ public StationController(StationRepository stationRepository) { } @PostMapping - public ResponseEntity createStation(@RequestBody Request view) { + public ResponseEntity createStation(@RequestBody Request view) { Station station = view.getContent().toStation(); Station persistStation = stationRepository.save(station); @@ -31,12 +30,12 @@ public ResponseEntity createStation(@RequestBody Request v } @GetMapping - public ResponseEntity showStations() { + public ResponseEntity> showStations() { return ResponseEntity.ok().body(stationRepository.findAll()); } @DeleteMapping("/{id}") - public ResponseEntity deleteStation(@PathVariable Long id) { + public ResponseEntity deleteStation(@PathVariable Long id) { stationRepository.deleteById(id); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/wooteco/subway/admin/domain/LineStation.java b/src/main/java/wooteco/subway/admin/domain/LineStation.java index 2e7395dad4..136f0a1366 100644 --- a/src/main/java/wooteco/subway/admin/domain/LineStation.java +++ b/src/main/java/wooteco/subway/admin/domain/LineStation.java @@ -36,10 +36,6 @@ public int getDuration() { return duration; } - public void updatePreLineStation(Long preStationId) { - this.preStationId = preStationId; - } - public void modifyPreStationId(Long preStationId) { this.preStationId = preStationId; } diff --git a/src/main/java/wooteco/subway/admin/dto/LineResponse.java b/src/main/java/wooteco/subway/admin/dto/LineResponse.java index 34ff2329f8..cec051fff7 100644 --- a/src/main/java/wooteco/subway/admin/dto/LineResponse.java +++ b/src/main/java/wooteco/subway/admin/dto/LineResponse.java @@ -1,17 +1,16 @@ package wooteco.subway.admin.dto; +import wooteco.subway.admin.domain.Line; +import wooteco.subway.admin.domain.Station; + import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import wooteco.subway.admin.domain.Line; -import wooteco.subway.admin.domain.LineStation; -import wooteco.subway.admin.domain.Station; - public class LineResponse { private Long id; private String name; @@ -28,7 +27,7 @@ public LineResponse() { } public LineResponse(Long id, String name, LocalTime startTime, LocalTime endTime, int intervalTime, - LocalDateTime createdAt, LocalDateTime updatedAt, Set stations) { + LocalDateTime createdAt, LocalDateTime updatedAt, String bgColor, Set stations) { this.id = id; this.name = name; this.startTime = startTime; @@ -36,23 +35,24 @@ public LineResponse(Long id, String name, LocalTime startTime, LocalTime endTime this.intervalTime = intervalTime; this.createdAt = createdAt; this.updatedAt = updatedAt; + this.bgColor = bgColor; this.stations = stations; } public static LineResponse of(Line line) { return new LineResponse(line.getId(), line.getName(), line.getStartTime(), line.getEndTime(), - line.getIntervalTime(), line.getCreatedAt(), line.getUpdatedAt(), new HashSet<>()); + line.getIntervalTime(), line.getCreatedAt(), line.getUpdatedAt(), line.getBgColor(), new HashSet<>()); } public static LineResponse of(Line line, Set stations) { return new LineResponse(line.getId(), line.getName(), line.getStartTime(), line.getEndTime(), - line.getIntervalTime(), line.getCreatedAt(), line.getUpdatedAt(), stations); + line.getIntervalTime(), line.getCreatedAt(), line.getUpdatedAt(), line.getBgColor(), stations); } public static List listOf(List lines) { - return lines.stream() + return Collections.unmodifiableList(lines.stream() .map(it -> LineResponse.of(it)) - .collect(Collectors.toList()); + .collect(Collectors.toList())); } public Long getId() { From 6342be089c8e25c6fa3302c4b40e36db5625e532 Mon Sep 17 00:00:00 2001 From: giantim Date: Sun, 10 May 2020 14:13:58 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20LineResponse=20=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B5=AC=EA=B0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=EB=90=9C=20=EC=97=AD=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LineController 반환값을 LineResponse 로 변경 LineResponse 사용하지 않는 메서드 제거 LineService LineResponse 를 생성하여 역 정보를 담아서 모든 노선 정보를 보여주도록 변경 AdminEdge.js 구간 정보 불러오는 로직 수정 --- .../subway/admin/controller/LineController.java | 3 +-- .../wooteco/subway/admin/dto/LineResponse.java | 6 ------ .../subway/admin/service/LineService.java | 17 +++++++++++++---- src/main/resources/static/js/views/AdminEdge.js | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/wooteco/subway/admin/controller/LineController.java b/src/main/java/wooteco/subway/admin/controller/LineController.java index eb8bd93b09..c3e6b986f9 100644 --- a/src/main/java/wooteco/subway/admin/controller/LineController.java +++ b/src/main/java/wooteco/subway/admin/controller/LineController.java @@ -40,8 +40,7 @@ public ResponseEntity createLines(@RequestBody Request> showLines() { - List lines = lineService.showLines(); - List lineResponses = LineResponse.listOf(lines); + List lineResponses = lineService.showLines(); return ResponseEntity.ok().body(lineResponses); } diff --git a/src/main/java/wooteco/subway/admin/dto/LineResponse.java b/src/main/java/wooteco/subway/admin/dto/LineResponse.java index cec051fff7..5134da97db 100644 --- a/src/main/java/wooteco/subway/admin/dto/LineResponse.java +++ b/src/main/java/wooteco/subway/admin/dto/LineResponse.java @@ -49,12 +49,6 @@ public static LineResponse of(Line line, Set stations) { line.getIntervalTime(), line.getCreatedAt(), line.getUpdatedAt(), line.getBgColor(), stations); } - public static List listOf(List lines) { - return Collections.unmodifiableList(lines.stream() - .map(it -> LineResponse.of(it)) - .collect(Collectors.toList())); - } - public Long getId() { return id; } diff --git a/src/main/java/wooteco/subway/admin/service/LineService.java b/src/main/java/wooteco/subway/admin/service/LineService.java index 6307d6d13a..f3079f810a 100644 --- a/src/main/java/wooteco/subway/admin/service/LineService.java +++ b/src/main/java/wooteco/subway/admin/service/LineService.java @@ -10,6 +10,7 @@ import wooteco.subway.admin.repository.LineRepository; import wooteco.subway.admin.repository.StationRepository; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; @@ -17,8 +18,8 @@ @Service public class LineService { - private LineRepository lineRepository; - private StationRepository stationRepository; + private final LineRepository lineRepository; + private final StationRepository stationRepository; public LineService(LineRepository lineRepository, StationRepository stationRepository) { this.lineRepository = lineRepository; @@ -30,8 +31,16 @@ public Line save(Line line) { return lineRepository.save(line); } - public List showLines() { - return lineRepository.findAll(); + public List showLines() { + List lineResponses = new ArrayList<>(); + List lines = lineRepository.findAll(); + for (Line line : lines) { + List lineStationsId = line.findLineStationsId(); + Set stations = stationRepository.findAllById(lineStationsId); + lineResponses.add(LineResponse.of(line, stations)); + } + + return Collections.unmodifiableList(lineResponses); } public void updateLine(Long id, Line line) { diff --git a/src/main/resources/static/js/views/AdminEdge.js b/src/main/resources/static/js/views/AdminEdge.js index 2909784d04..7c64731bfe 100644 --- a/src/main/resources/static/js/views/AdminEdge.js +++ b/src/main/resources/static/js/views/AdminEdge.js @@ -22,14 +22,14 @@ function AdminEdge() { for (let i = 0; i < lines.length; i++) { const targetLine = lines[i]; const lineStations = targetLine["stations"]; - const lineStationsIds = lineStations.map(lineStation => lineStation["stationId"]); - const targetLineStations = lineStationsIds.map(id => stations.filter(station => station["id"] === id) - .map(station => station["name"])); + const lineStationsIds = lineStations.map(lineStation => lineStation["id"]); + const targetLineStationNames = lineStationsIds.map(id => stations.find(station => station["id"] === id)) + .map(station => station["name"]); const subwayLine = { lineId: targetLine["id"], title: targetLine["name"], bgColor: targetLine["bgColor"], - stations: targetLineStations + stations: targetLineStationNames } subwayLines = [...subwayLines, subwayLine]; } From 6b421d99ba2a603208ba2e83373a6d9a2dcc5785 Mon Sep 17 00:00:00 2001 From: giantim Date: Sun, 10 May 2020 16:43:01 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B0=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EB=AA=A8=EB=8B=AC=20=EC=B0=BD=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=9D=B4=EC=A0=84=EC=97=AD,=20=EB=93=9C=EB=A1=AD=EB=B0=95?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20fix:=20=EC=97=AD?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=A0=20=EB=95=8C=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EA=B2=80=EC=82=AC=EB=A5=BC=20=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit admin-edge.html input -> select 으로 변경 AdminEdge.js 노선에 포함된 이전역을 불러오는 함수 구현 AdminStation.js 중복 검사 로직 변경 constants.js 이벤트 상수 추가 schema.sql 테스트 데이터 추가 --- src/main/resources/schema.sql | 6 ++++ .../resources/static/js/views/AdminEdge.js | 30 ++++++++++++++----- .../resources/static/js/views/AdminStation.js | 2 +- src/main/resources/static/utils/constants.js | 3 +- src/main/resources/templates/admin-edge.html | 20 +++++-------- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index be9fa9f912..54a384fd9c 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -41,6 +41,12 @@ insert into STATION values(9, '종합운동장', CURRENT_TIMESTAMP()); insert into STATION values(10, '잠실새내', CURRENT_TIMESTAMP()); insert into STATION values(11, '잠실', CURRENT_TIMESTAMP()); +insert into STATION values(12, '당고개', CURRENT_TIMESTAMP()); +insert into STATION values(13, '상계', CURRENT_TIMESTAMP()); +insert into STATION values(14, '노원', CURRENT_TIMESTAMP()); +insert into STATION values(15, '창동', CURRENT_TIMESTAMP()); +insert into STATION values(16, '쌍문', CURRENT_TIMESTAMP()); + insert into LINE values(1, '1호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-blue-700'); insert into LINE values(2, '2호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); insert into LINE values(3, '3호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-orange-500'); diff --git a/src/main/resources/static/js/views/AdminEdge.js b/src/main/resources/static/js/views/AdminEdge.js index 7c64731bfe..619ec74f49 100644 --- a/src/main/resources/static/js/views/AdminEdge.js +++ b/src/main/resources/static/js/views/AdminEdge.js @@ -7,6 +7,7 @@ import api from "../../api/index.js"; function AdminEdge() { const $subwayLinesSlider = document.querySelector(".subway-lines-slider"); const $createLineStationButton = document.querySelector("#submit-button"); + const $stationSelectOptions = document.querySelector("#line-select-options"); const createSubwayEdgeModal = new Modal(); let subwayLines = []; @@ -35,7 +36,7 @@ function AdminEdge() { } } - const initSubwayLinesSlider = () => { + const initSubwayLinesSlider = async () => { $subwayLinesSlider.innerHTML = subwayLines .map(line => subwayLinesItemTemplate(line)) .join(""); @@ -53,19 +54,28 @@ function AdminEdge() { }); }; - const initSubwayLineOptions = () => { + const initSubwayLineOptions = async () => { const subwayLineOptionTemplate = subwayLines .map(line => optionTemplate(line.title)) .join(""); - const $stationSelectOptions = document.querySelector( - "#line-select-options" - ); $stationSelectOptions.insertAdjacentHTML( "afterbegin", subwayLineOptionTemplate ); }; + async function initDepartStations() { + const lineName = $stationSelectOptions.options[$stationSelectOptions.selectedIndex].value; + const line = subwayLines.find(subway => subway["title"] === lineName); + const lineStations = ["출발역", ...line["stations"]]; + const departOptionTemplate = lineStations + .map(lineStation => optionTemplate(lineStation)) + .join(""); + const $departStationOptions = document.querySelector("#depart-station-name"); + $departStationOptions.innerHTML = ""; + $departStationOptions.insertAdjacentHTML("afterbegin", departOptionTemplate); + } + const onRemoveStationHandler = async event => { const $target = event.target; const isDeleteButton = $target.classList.contains("mdi-delete"); @@ -111,19 +121,25 @@ function AdminEdge() { location.reload(); }; + async function initStation() { + await initDepartStations(); + } + const initEventListeners = async () => { $subwayLinesSlider.addEventListener( EVENT_TYPE.CLICK, onRemoveStationHandler ); $createLineStationButton.addEventListener(EVENT_TYPE.CLICK, await onCreateLineStation); + $stationSelectOptions.addEventListener(EVENT_TYPE.CHANGE, await initStation) }; this.init = async () => { await initSubwayLines(); - initSubwayLinesSlider(); - initSubwayLineOptions(); + await initSubwayLinesSlider(); + await initSubwayLineOptions(); await initEventListeners(); + await initDepartStations(); }; } diff --git a/src/main/resources/static/js/views/AdminStation.js b/src/main/resources/static/js/views/AdminStation.js index 13a6f2722d..52514ddefc 100644 --- a/src/main/resources/static/js/views/AdminStation.js +++ b/src/main/resources/static/js/views/AdminStation.js @@ -80,7 +80,7 @@ function AdminStation() { } function validateDuplicateStationName(stationNameInput, input) { - if (stations.includes(input)) { + if (stations.map(station => station["name"]).includes(input)) { alert(ERROR_MESSAGE.DUPLICATE); stationNameInput.value = CONSTANT.EMPTY; return false; diff --git a/src/main/resources/static/utils/constants.js b/src/main/resources/static/utils/constants.js index d29cee00d8..5b068e5ee5 100644 --- a/src/main/resources/static/utils/constants.js +++ b/src/main/resources/static/utils/constants.js @@ -1,6 +1,7 @@ export const EVENT_TYPE = { CLICK: "click", - KEY_PRESS: "keypress" + KEY_PRESS: "keypress", + CHANGE: "change" }; export const ERROR_MESSAGE = { diff --git a/src/main/resources/templates/admin-edge.html b/src/main/resources/templates/admin-edge.html index cf3d50e962..c8a3571d06 100644 --- a/src/main/resources/templates/admin-edge.html +++ b/src/main/resources/templates/admin-edge.html @@ -107,13 +107,10 @@ - +
대상역 - + id="arrival-station-name"> +
From 3cffaf4ffb00737ea03bda91a317efabb98e8248 Mon Sep 17 00:00:00 2001 From: giantim Date: Mon, 11 May 2020 14:06:19 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B0=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EB=B7=B0=EC=97=90=EC=84=9C=20=EB=8F=84=EC=B0=A9?= =?UTF-8?q?=EC=97=AD=EC=9D=84=20=EC=84=A0=ED=83=9D=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AdminEdge.js 도착역을 선택하는 옵션 추가 --- src/main/resources/schema.sql | 22 +++++++-------- .../resources/static/js/views/AdminEdge.js | 27 ++++++++++++++----- src/main/resources/templates/admin-edge.html | 2 +- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 54a384fd9c..1eb038cad6 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -56,15 +56,15 @@ insert into LINE values(6, '6호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), insert into LINE values(7, '7호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); insert into LINE values(8, '8호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-pink-500'); -insert into LINE_STATION values(1, null, 1, null, 0, 0); -insert into LINE_STATION values(1, null, 2, 1, 10, 2); -insert into LINE_STATION values(1, null, 3, 2, 10, 2); +insert into LINE_STATION values(1, 0, 1, null, 0, 0); +insert into LINE_STATION values(1, 1, 2, 1, 10, 2); +insert into LINE_STATION values(1, 2, 3, 2, 10, 2); -insert into LINE_STATION values(2, null, 4, null, 0, 0); -insert into LINE_STATION values(2, null, 5, 4, 10, 2); -insert into LINE_STATION values(2, null, 6, 5, 10, 2); -insert into LINE_STATION values(2, null, 7, 6, 10, 2); -insert into LINE_STATION values(2, null, 8, 7, 10, 2); -insert into LINE_STATION values(2, null, 9, 8, 10, 2); -insert into LINE_STATION values(2, null, 10, 9, 10, 2); -insert into LINE_STATION values(2, null, 11, 10, 10, 2); \ No newline at end of file +insert into LINE_STATION values(2, 0, 4, null, 0, 0); +insert into LINE_STATION values(2, 1, 5, 4, 10, 2); +insert into LINE_STATION values(2, 2, 6, 5, 10, 2); +insert into LINE_STATION values(2, 3, 7, 6, 10, 2); +insert into LINE_STATION values(2, 4, 8, 7, 10, 2); +insert into LINE_STATION values(2, 5, 9, 8, 10, 2); +insert into LINE_STATION values(2, 6, 10, 9, 10, 2); +insert into LINE_STATION values(2, 7, 11, 10, 10, 2); \ No newline at end of file diff --git a/src/main/resources/static/js/views/AdminEdge.js b/src/main/resources/static/js/views/AdminEdge.js index 619ec74f49..87769da123 100644 --- a/src/main/resources/static/js/views/AdminEdge.js +++ b/src/main/resources/static/js/views/AdminEdge.js @@ -76,6 +76,25 @@ function AdminEdge() { $departStationOptions.insertAdjacentHTML("afterbegin", departOptionTemplate); } + async function initArrivalStations() { + const lineName = $stationSelectOptions.options[$stationSelectOptions.selectedIndex].value; + const line = subwayLines.find(subway => subway["title"] === lineName); + const lineStations = ["출발역", ...line["stations"]]; + const arrivalStations = stations.filter(station => !lineStations.some(name => name === station["name"])) + .map(station => station["name"]) + const arrivalOptionTemplate = arrivalStations + .map(lineStation => optionTemplate(lineStation)) + .join(""); + const $arrivalStationOptions = document.querySelector("#arrival-station-name"); + $arrivalStationOptions.innerHTML = ""; + $arrivalStationOptions.insertAdjacentHTML("afterbegin", arrivalOptionTemplate); + } + + async function initStationOptions() { + await initDepartStations(); + await initArrivalStations(); + } + const onRemoveStationHandler = async event => { const $target = event.target; const isDeleteButton = $target.classList.contains("mdi-delete"); @@ -121,17 +140,13 @@ function AdminEdge() { location.reload(); }; - async function initStation() { - await initDepartStations(); - } - const initEventListeners = async () => { $subwayLinesSlider.addEventListener( EVENT_TYPE.CLICK, onRemoveStationHandler ); $createLineStationButton.addEventListener(EVENT_TYPE.CLICK, await onCreateLineStation); - $stationSelectOptions.addEventListener(EVENT_TYPE.CHANGE, await initStation) + $stationSelectOptions.addEventListener(EVENT_TYPE.CHANGE, await initStationOptions) }; this.init = async () => { @@ -139,7 +154,7 @@ function AdminEdge() { await initSubwayLinesSlider(); await initSubwayLineOptions(); await initEventListeners(); - await initDepartStations(); + await initStationOptions(); }; } diff --git a/src/main/resources/templates/admin-edge.html b/src/main/resources/templates/admin-edge.html index c8a3571d06..acf2643286 100644 --- a/src/main/resources/templates/admin-edge.html +++ b/src/main/resources/templates/admin-edge.html @@ -125,7 +125,7 @@ 대상역 From 50b89d3b28bbd9b734ce2c5ff2792b4a87bce44d Mon Sep 17 00:00:00 2001 From: giantim Date: Mon, 11 May 2020 14:15:01 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20schema=20=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data.sql | 44 +++++++++++++++++++++++++++++++++++ src/main/resources/schema.sql | 43 +--------------------------------- 2 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 src/main/resources/data.sql diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 0000000000..9aeafb1644 --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,44 @@ +TRUNCATE TABLE STATION; +TRUNCATE TABLE LINE; +TRUNCATE TABLE LINE_STATION; + +insert into station values(1, '수원', CURRENT_TIMESTAMP()); +insert into station values(2, '화서', CURRENT_TIMESTAMP()); +insert into station values(3, '성균관대', CURRENT_TIMESTAMP()); + +insert into STATION values(4, '교대', CURRENT_TIMESTAMP()); +insert into STATION values(5, '강남', CURRENT_TIMESTAMP()); +insert into STATION values(6, '역삼', CURRENT_TIMESTAMP()); +insert into STATION values(7, '선릉', CURRENT_TIMESTAMP()); +insert into STATION values(8, '삼성', CURRENT_TIMESTAMP()); +insert into STATION values(9, '종합운동장', CURRENT_TIMESTAMP()); +insert into STATION values(10, '잠실새내', CURRENT_TIMESTAMP()); +insert into STATION values(11, '잠실', CURRENT_TIMESTAMP()); + +insert into STATION values(12, '당고개', CURRENT_TIMESTAMP()); +insert into STATION values(13, '상계', CURRENT_TIMESTAMP()); +insert into STATION values(14, '노원', CURRENT_TIMESTAMP()); +insert into STATION values(15, '창동', CURRENT_TIMESTAMP()); +insert into STATION values(16, '쌍문', CURRENT_TIMESTAMP()); + +insert into LINE values(1, '1호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-blue-700'); +insert into LINE values(2, '2호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); +insert into LINE values(3, '3호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-orange-500'); +insert into LINE values(4, '4호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-blue-500'); +insert into LINE values(5, '5호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-purple-500'); +insert into LINE values(6, '6호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-yellow-500'); +insert into LINE values(7, '7호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); +insert into LINE values(8, '8호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-pink-500'); + +insert into LINE_STATION values(1, 0, 1, null, 0, 0); +insert into LINE_STATION values(1, 1, 2, 1, 10, 2); +insert into LINE_STATION values(1, 2, 3, 2, 10, 2); + +insert into LINE_STATION values(2, 0, 4, null, 0, 0); +insert into LINE_STATION values(2, 1, 5, 4, 10, 2); +insert into LINE_STATION values(2, 2, 6, 5, 10, 2); +insert into LINE_STATION values(2, 3, 7, 6, 10, 2); +insert into LINE_STATION values(2, 4, 8, 7, 10, 2); +insert into LINE_STATION values(2, 5, 9, 8, 10, 2); +insert into LINE_STATION values(2, 6, 10, 9, 10, 2); +insert into LINE_STATION values(2, 7, 11, 10, 10, 2); \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 1eb038cad6..bf25555382 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -26,45 +26,4 @@ create table if not exists LINE_STATION ( pre_station_id bigint, distance int, duration int -); - -insert into station values(1, '수원', CURRENT_TIMESTAMP()); -insert into station values(2, '화서', CURRENT_TIMESTAMP()); -insert into station values(3, '성균관대', CURRENT_TIMESTAMP()); - -insert into STATION values(4, '교대', CURRENT_TIMESTAMP()); -insert into STATION values(5, '강남', CURRENT_TIMESTAMP()); -insert into STATION values(6, '역삼', CURRENT_TIMESTAMP()); -insert into STATION values(7, '선릉', CURRENT_TIMESTAMP()); -insert into STATION values(8, '삼성', CURRENT_TIMESTAMP()); -insert into STATION values(9, '종합운동장', CURRENT_TIMESTAMP()); -insert into STATION values(10, '잠실새내', CURRENT_TIMESTAMP()); -insert into STATION values(11, '잠실', CURRENT_TIMESTAMP()); - -insert into STATION values(12, '당고개', CURRENT_TIMESTAMP()); -insert into STATION values(13, '상계', CURRENT_TIMESTAMP()); -insert into STATION values(14, '노원', CURRENT_TIMESTAMP()); -insert into STATION values(15, '창동', CURRENT_TIMESTAMP()); -insert into STATION values(16, '쌍문', CURRENT_TIMESTAMP()); - -insert into LINE values(1, '1호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-blue-700'); -insert into LINE values(2, '2호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); -insert into LINE values(3, '3호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-orange-500'); -insert into LINE values(4, '4호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-blue-500'); -insert into LINE values(5, '5호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-purple-500'); -insert into LINE values(6, '6호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-yellow-500'); -insert into LINE values(7, '7호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-green-500'); -insert into LINE values(8, '8호선', '05:30', '23:30', 10, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), 'bg-pink-500'); - -insert into LINE_STATION values(1, 0, 1, null, 0, 0); -insert into LINE_STATION values(1, 1, 2, 1, 10, 2); -insert into LINE_STATION values(1, 2, 3, 2, 10, 2); - -insert into LINE_STATION values(2, 0, 4, null, 0, 0); -insert into LINE_STATION values(2, 1, 5, 4, 10, 2); -insert into LINE_STATION values(2, 2, 6, 5, 10, 2); -insert into LINE_STATION values(2, 3, 7, 6, 10, 2); -insert into LINE_STATION values(2, 4, 8, 7, 10, 2); -insert into LINE_STATION values(2, 5, 9, 8, 10, 2); -insert into LINE_STATION values(2, 6, 10, 9, 10, 2); -insert into LINE_STATION values(2, 7, 11, 10, 10, 2); \ No newline at end of file +); \ No newline at end of file