Skip to content
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

[Spring 경로 조회 - 1단계] 레넌(조형래) 미션 제출합니다. #183

Merged
merged 28 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
af360ee
feat: 프로젝트 이동
jinyoungchoi95 May 17, 2022
36ae4b4
docs: 요구사항 추가
jinyoungchoi95 May 17, 2022
eb2e504
feat: Section 내 station 포함 체크 기능 추가 및 테스트
jinyoungchoi95 May 17, 2022
3e6bac9
feat: 길찾기 전략 조회 및 예외 테스트 추가
jinyoungchoi95 May 17, 2022
585b4b1
feat: 최단 경로 계산 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
345aca0
refactor: 메소드 분리
jinyoungchoi95 May 17, 2022
986dfca
feat: findAll Sections 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
ef571d0
feat: PathService 경로 조회 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
587601f
feat: GET "/paths" 경로 조회 api 추가 및 테스트
jinyoungchoi95 May 17, 2022
57f7d6c
feat: GET "/paths" 경로 조회 api 추가 및 테스트
jinyoungchoi95 May 17, 2022
b2529ab
feat: 기본 운임 계산 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
5b3de4b
feat: 50km 운임 계산 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
d1fabc8
refactor: Path 매직넘버 상수화
jinyoungchoi95 May 17, 2022
b02911a
feat: 50km 초과구간 운임 계산 기능 구현 및 테스트
jinyoungchoi95 May 17, 2022
7f931b2
fix: id 값 테스트 오류 수정
jinyoungchoi95 May 17, 2022
6a0fa96
feat: path 운임 계산 기능 수정
jinyoungchoi95 May 17, 2022
77c07b4
feat: path 조회 api 요금 정보 추가
jinyoungchoi95 May 17, 2022
c03af53
refactor: Path 계산 기능 메소드 분리
jinyoungchoi95 May 17, 2022
2273bf5
fix: Vertex 오타 수정
jinyoungchoi95 May 17, 2022
e1461bc
fix: 경로를 찾지 못했을 때 예외 처리 및 테스트
jinyoungchoi95 May 17, 2022
fdff67a
refactor: 미사용 구문 제거
jinyoungchoi95 May 17, 2022
f3085e7
refactor: getPath null 처리 방법 수정
jinyoungchoi95 May 17, 2022
bf08e34
refactor: 로타입 지정 및 오타 수정
brorae May 17, 2022
99121c2
refactor: path 검증 추가 및 ParameterizedTest 추가
brorae May 17, 2022
ddfbe4b
refactor: 상수 이름 변경
brorae May 17, 2022
c139f08
refactor: test 코드 추가
brorae May 17, 2022
d8b6a36
refactor: request validation 추가
brorae May 17, 2022
034d09b
refactor: 노선 삭제 시 구간도 삭제하도록 수정
brorae May 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 18 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
<p align="center">
<img width="200px;" src="https://raw.githubusercontent.com/woowacourse/atdd-subway-admin-frontend/master/images/main_logo.png"/>
</p>
<p align="center">
<a href="https://techcourse.woowahan.com/c/Dr6fhku7" alt="woowacuorse subway">
<img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Fedu.nextstep.camp%2Fc%2FR89PYi5H">
</a>
<img alt="GitHub" src="https://img.shields.io/github/license/woowacourse/atdd-subway-path">
</p>

<br>

# 지하철 노선도 미션
스프링 과정 실습을 위한 지하철 노선도 애플리케이션

<br>

## 🚀 Getting Started
### Usage
#### application 구동
```
./gradlew bootRun
```
<br>

## ✏️ Code Review Process
[텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview)

<br>

## 🐞 Bug Report

버그를 발견한다면, [Issues](https://github.com/woowacourse/atdd-subway-path/issues) 에 등록해주세요 :)

<br>

## 📝 License

This project is [MIT](https://github.com/woowacourse/atdd-subway-path/blob/master/LICENSE) licensed.
### step1 요구사항
- [ERROR] 출발역과 도착역이 Sections에 포함되지 않으면 예외가 발생한다.
- [ERROR] 출발역에서 도착역으로 가는 경로가 포함되어 있지 않으면 예외가 발생한다.

- 출발역과 도착역 그리고 전체 Section정보를 받아 경로를 만드는 전략이 존재한다.
- 전략의 경우 다익스트라 라이브러리를 사용한 전략이 존재한다.
- 정점(vertex) : 지하철 역 (Station)
- 간선(edge) : 지하철역 연결정보(Section)
- 가중치(edgeWeight) : 거리
- 최단 거리 기준 조회 시 가중치를 거리로 설정한다.
- 들어온 Station List 정보를 반환한다.
- Path
- path는 거리와 station정보를 가지고 있다.
- path에서는 가지고 있는 stations의 모든 거리를 계산할 수 있다.
- path에서는 거리에 따른 돈 계산을 반환할 수 있다.
- 기본 운임 (10km 이내)는 1,250원이다.
- 10~50km까지는 5km마다 100원을 추가한다.
- 50km 초과 시 8km까지 마다 100원을 추가한다.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// log
implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1'
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/wooteco/subway/configuration/PathConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package wooteco.subway.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import wooteco.subway.domain.strategy.FindDijkstraShortestPathStrategy;
import wooteco.subway.domain.strategy.FindPathStrategy;

@Configuration
public class PathConfiguration {
brorae marked this conversation as resolved.
Show resolved Hide resolved

@Bean
public FindPathStrategy findPathStrategy() {
return new FindDijkstraShortestPathStrategy();
}
}
61 changes: 61 additions & 0 deletions src/main/java/wooteco/subway/controller/LineController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package wooteco.subway.controller;

import java.net.URI;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.Positive;
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.dto.line.LineResponse;
import wooteco.subway.dto.line.LineSaveRequest;
import wooteco.subway.dto.line.LineUpdateRequest;
import wooteco.subway.service.LineService;

@RestController
@RequestMapping("/lines")
public class LineController {

private final LineService lineService;

public LineController(final LineService lineService) {
this.lineService = lineService;
}

@PostMapping
public ResponseEntity<LineResponse> createLine(@RequestBody @Valid LineSaveRequest lineSaveRequest) {
LineResponse response = lineService.save(lineSaveRequest);
return ResponseEntity.created(URI.create("/lines/" + response.getId())).body(response);
}

@GetMapping
public ResponseEntity<List<LineResponse>> showLines() {
return ResponseEntity.ok().body(lineService.findAll());
}

@GetMapping("/{lineId}")
public ResponseEntity<LineResponse> showLine(
@PathVariable @Positive(message = "노선의 id는 양수 값만 들어올 수 있습니다.") Long lineId) {
LineResponse response = lineService.findById(lineId);
return ResponseEntity.ok().body(response);
}

@PutMapping("/{lineId}")
public ResponseEntity<Void> updateLine(@PathVariable Long lineId,
@RequestBody @Valid LineUpdateRequest lineUpdateRequest) {
lineService.update(lineId, lineUpdateRequest);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{lineId}")
public ResponseEntity<Void> deleteLine(@PathVariable Long lineId) {
lineService.delete(lineId);
return ResponseEntity.noContent().build();
}
}
25 changes: 25 additions & 0 deletions src/main/java/wooteco/subway/controller/PathFindController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package wooteco.subway.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;
import wooteco.subway.dto.path.PathFindRequest;
import wooteco.subway.dto.path.PathFindResponse;
import wooteco.subway.service.PathService;

@RestController
public class PathFindController {

private final PathService pathService;

public PathFindController(final PathService pathService) {
this.pathService = pathService;
}

@GetMapping("/paths")
public ResponseEntity<PathFindResponse> findPath(@ModelAttribute PathFindRequest pathFindRequest) {
PathFindResponse response = pathService.findPath(pathFindRequest);
return ResponseEntity.ok(response);
}
}
37 changes: 37 additions & 0 deletions src/main/java/wooteco/subway/controller/SectionController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package wooteco.subway.controller;

import javax.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import wooteco.subway.dto.section.SectionSaveRequest;
import wooteco.subway.service.SectionService;

@RestController
@RequestMapping("/lines/{lineId}/sections")
public class SectionController {

private final SectionService sectionService;

public SectionController(final SectionService sectionService) {
this.sectionService = sectionService;
}

@PostMapping
public ResponseEntity<Void> saveSection(@PathVariable long lineId,
@RequestBody @Valid SectionSaveRequest sectionSaveRequest) {
sectionService.save(lineId, sectionSaveRequest);
return ResponseEntity.ok().build();
}

@DeleteMapping
public ResponseEntity<Void> deleteSection(@PathVariable long lineId, @RequestParam long stationId) {
sectionService.delete(lineId, stationId);
return ResponseEntity.ok().build();
}
}
44 changes: 44 additions & 0 deletions src/main/java/wooteco/subway/controller/StationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package wooteco.subway.controller;

import java.net.URI;
import java.util.List;
import javax.validation.Valid;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wooteco.subway.dto.station.StationResponse;
import wooteco.subway.dto.station.StationSaveRequest;
import wooteco.subway.service.StationService;

@RestController
@RequestMapping("/stations")
public class StationController {

private final StationService stationService;

public StationController(final StationService stationService) {
this.stationService = stationService;
}

@PostMapping
public ResponseEntity<StationResponse> createStation(@RequestBody @Valid StationSaveRequest stationSaveRequest) {
StationResponse response = stationService.save(stationSaveRequest.toStation());
return ResponseEntity.created(URI.create("/stations/" + response.getId())).body(response);
}

@GetMapping
public ResponseEntity<List<StationResponse>> showStations() {
return ResponseEntity.ok().body(stationService.findAll());
}

@DeleteMapping("/{stationId}")
public ResponseEntity<Void> deleteStation(@PathVariable Long stationId) {
stationService.delete(stationId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package wooteco.subway.controller;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;
import wooteco.subway.dto.SubwayErrorResponse;
import wooteco.subway.exception.NotFoundException;

@RestControllerAdvice
public class SubwayControllerAdvice {

@ExceptionHandler(IllegalStateException.class)
public ResponseEntity<SubwayErrorResponse> handleBusinessException(IllegalStateException exception) {
return ResponseEntity.badRequest().body(SubwayErrorResponse.from(exception));
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<SubwayErrorResponse> handleMethodValidException(MethodArgumentNotValidException exception) {
return ResponseEntity.badRequest().body(SubwayErrorResponse.from(exception));
}

@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<Void> handleNoHandlerFoundException() {
return ResponseEntity.notFound().build();
}

@ExceptionHandler(NotFoundException.class)
public ResponseEntity<SubwayErrorResponse> handleNotFoundException(NotFoundException exception) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(SubwayErrorResponse.from(exception));
}

@ExceptionHandler(EmptyResultDataAccessException.class)
public ResponseEntity<Void> handleNotFoundException() {
return ResponseEntity.notFound().build();
}

@ExceptionHandler(DataAccessException.class)
public ResponseEntity<Void> handleDataAccessException() {
return ResponseEntity.internalServerError().build();
}

@ExceptionHandler(Exception.class)
public ResponseEntity<Void> handleException() {
return ResponseEntity.internalServerError().build();
}
}
30 changes: 0 additions & 30 deletions src/main/java/wooteco/subway/dao/StationDao.java

This file was deleted.

Loading