-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ordinCode/ordincode
[학성] 지하철 정보 관리 - 인수 테스트 미션 제출합니다.
- Loading branch information
Showing
58 changed files
with
6,218 additions
and
224 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
.DS_Store |
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 |
---|---|---|
@@ -1,28 +1,29 @@ | ||
plugins { | ||
id 'org.springframework.boot' version '2.2.5.RELEASE' | ||
id 'io.spring.dependency-management' version '1.0.9.RELEASE' | ||
id 'java' | ||
id 'org.springframework.boot' version '2.2.5.RELEASE' | ||
id 'io.spring.dependency-management' version '1.0.9.RELEASE' | ||
id 'java' | ||
} | ||
|
||
group = 'com.example' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '1.8' | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' | ||
implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1' | ||
testImplementation 'io.rest-assured:rest-assured:3.3.0' | ||
testImplementation('org.springframework.boot:spring-boot-starter-test') { | ||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' | ||
} | ||
runtimeOnly 'com.h2database:h2' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' | ||
implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1' | ||
implementation 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.3.1' | ||
testImplementation 'io.rest-assured:rest-assured:3.3.0' | ||
testImplementation('org.springframework.boot:spring-boot-starter-test') { | ||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' | ||
} | ||
runtimeOnly 'com.h2database:h2' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/wooteco/subway/admin/controller/ExceptionController.java
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,17 @@ | ||
package wooteco.subway.admin.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wooteco.subway.admin.domain.exception.DuplicationNameException; | ||
import wooteco.subway.admin.domain.exception.NotFoundLineException; | ||
|
||
@ControllerAdvice | ||
@RestController | ||
public class ExceptionController { | ||
@ExceptionHandler(value = {NotFoundLineException.class, DuplicationNameException.class}) | ||
public ResponseEntity<String> exceptionHandler(IllegalArgumentException e) { | ||
return ResponseEntity.badRequest().body(e.getMessage()); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/main/java/wooteco/subway/admin/controller/LineController.java
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,86 @@ | ||
package wooteco.subway.admin.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wooteco.subway.admin.domain.Line; | ||
import wooteco.subway.admin.domain.LineStation; | ||
import wooteco.subway.admin.dto.LineRequest; | ||
import wooteco.subway.admin.dto.LineResponse; | ||
import wooteco.subway.admin.dto.LineStationCreateRequest; | ||
import wooteco.subway.admin.service.LineService; | ||
import wooteco.subway.admin.service.StationService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequestMapping("/lines") | ||
public class LineController { | ||
private final LineService lineService; | ||
private final StationService stationService; | ||
|
||
public LineController(final LineService lineService, final StationService stationService) { | ||
this.lineService = lineService; | ||
this.stationService = stationService; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<Line> createLine(@RequestBody LineRequest lineRequest) { | ||
Line line = LineRequest.toLine(lineRequest); | ||
Line savedLine = lineService.save(line); | ||
return ResponseEntity.created(URI.create("/lines/" + savedLine.getId())).body(savedLine); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<LineResponse>> findAllLine() { | ||
List<LineResponse> lineResponses = lineService.findAll().stream() | ||
.map(line -> lineService.findLineWithStationsById(line.getId())) | ||
.collect(Collectors.toList()); | ||
return ResponseEntity.ok(lineResponses); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<LineResponse> findLine(@PathVariable Long id) { | ||
return ResponseEntity.ok(lineService.findLineWithStationsById(id)); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Void> updateLine(@PathVariable Long id, @RequestBody LineRequest lineRequest) { | ||
Line line = LineRequest.toLine(lineRequest); | ||
lineService.updateLine(id, line); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteLine(@PathVariable Long id) { | ||
lineService.deleteLineById(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PostMapping("/{lineId}/stations") | ||
public ResponseEntity<Void> addStation(@PathVariable Long lineId, | ||
@RequestBody LineStationCreateRequest req) { | ||
Long preStationId = stationService.findStationId(req.getPreStationName()); | ||
Long stationId = stationService.findStationId(req.getStationName()); | ||
|
||
LineStation lineStation = new LineStation( | ||
preStationId, stationId, req.getDistance(), req.getDuration()); | ||
|
||
lineService.addLineStation(lineId, lineStation); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping("/{lineId}/stations/{stationId}") | ||
public ResponseEntity<Void> deleteStation(@PathVariable Long lineId, @PathVariable Long stationId) { | ||
lineService.removeLineStation(lineId, stationId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/wooteco/subway/admin/controller/LineStationController.java
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,24 @@ | ||
package wooteco.subway.admin.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wooteco.subway.admin.domain.LineStation; | ||
import wooteco.subway.admin.service.LineService; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
public class LineStationController { | ||
private final LineService lineService; | ||
|
||
public LineStationController(final LineService lineService) { | ||
this.lineService = lineService; | ||
} | ||
|
||
@GetMapping("/lineStations/{lineId}") | ||
public ResponseEntity<List<LineStation>> findAllLineStations(@PathVariable Long lineId) { | ||
return ResponseEntity.ok(lineService.findLineStationByLineId(lineId)); | ||
} | ||
} |
33 changes: 19 additions & 14 deletions
33
src/main/java/wooteco/subway/admin/controller/StationController.java
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 |
---|---|---|
@@ -1,40 +1,45 @@ | ||
package wooteco.subway.admin.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import wooteco.subway.admin.domain.Station; | ||
import wooteco.subway.admin.dto.StationCreateRequest; | ||
import wooteco.subway.admin.dto.StationRequest; | ||
import wooteco.subway.admin.dto.StationResponse; | ||
import wooteco.subway.admin.repository.StationRepository; | ||
import wooteco.subway.admin.service.StationService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
public class StationController { | ||
private final StationRepository stationRepository; | ||
private final StationService stationService; | ||
|
||
public StationController(StationRepository stationRepository) { | ||
this.stationRepository = stationRepository; | ||
public StationController(final StationService stationService) { | ||
this.stationService = stationService; | ||
} | ||
|
||
@PostMapping("/stations") | ||
public ResponseEntity createStation(@RequestBody StationCreateRequest view) { | ||
Station station = view.toStation(); | ||
Station persistStation = stationRepository.save(station); | ||
|
||
public ResponseEntity<StationResponse> createStation(@RequestBody StationRequest stationRequest) { | ||
Station persistStation = stationService.save(stationRequest.getName()); | ||
return ResponseEntity | ||
.created(URI.create("/stations/" + persistStation.getId())) | ||
.body(StationResponse.of(persistStation)); | ||
} | ||
|
||
@GetMapping("/stations") | ||
public ResponseEntity showStations() { | ||
return ResponseEntity.ok().body(stationRepository.findAll()); | ||
public ResponseEntity<List<StationResponse>> showStations() { | ||
List<Station> stations = stationService.findAll(); | ||
return ResponseEntity.ok().body(StationResponse.listOf(stations)); | ||
} | ||
|
||
@DeleteMapping("/stations/{id}") | ||
public ResponseEntity deleteStation(@PathVariable Long id) { | ||
stationRepository.deleteById(id); | ||
public ResponseEntity<Void> deleteStation(@PathVariable Long id) { | ||
stationService.deleteById(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/wooteco/subway/admin/controller/WebController.java
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,27 @@ | ||
package wooteco.subway.admin.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@Controller | ||
public class WebController { | ||
@GetMapping("/") | ||
public String index() { | ||
return "index"; | ||
} | ||
|
||
@GetMapping("/admin-line") | ||
public String adminLine() { | ||
return "admin-line"; | ||
} | ||
|
||
@GetMapping("/admin-edge") | ||
public String adminEdge() { | ||
return "admin-edge"; | ||
} | ||
|
||
@GetMapping("/admin-station") | ||
public String adminStation() { | ||
return "admin-station"; | ||
} | ||
} |
Oops, something went wrong.