Skip to content

Commit

Permalink
[2단계 - 최단 경로 및 요금 조회 api] 주드 미션 제출합니다. (#102)
Browse files Browse the repository at this point in the history
* feat: 노선 삭제 및 테스트케이스 추가

* feat: 노선 삭제 예외 처리

* feat: 중복 이름 추가 시 예외 처리

* refactor: 역 추가 분기 제거

* feat: 최단 거리 및 경로 계산

* feat: 최단 경로 및 요금 조회 기능

* chore: 테스트와 db 분리

* docs: 문서 추가

* chore : package 구분

* feat: 기타 예외 처리 추가

* feat: request 검증 추가

* refactor: 조회에 readonly 추가

* chore: h2로 설정 변경

* refactor: 상속으로 라이브러리 사용 분리

* chore

* refactor: polishing

* fix: 역을 삭제하면 모든 노선에서 삭제

* refactor: rename

* refactor: polishing 및 테스트

* test: test 포맷 수정

* test: test 추가

* refactor: polishing

* docs: 기능 정리

* feat: 없는 지하철역 예외 처리 및 테스트 추가

* refactor: 최단 경로 계산 구조 변경

* refactor: 요금 계산 로직 수정

* chore: 데이터베이스 세팅 수정

* refactor: 이름 수정

* test: 인수테스트 전면 수정

* docs: 요구사항 추가

* refactor: polishing

* test: 인수테스트 이름 수정

* refactor: depricated 제거

* refactor: slf4j 의존성 추가

* refactor: 에러 로그 추가

* refactor: polishing

* refactor: response, request 기본 생성자 추가

* refactor: shortestPathResponse로 변경
  • Loading branch information
kevstevie authored Jun 1, 2023
1 parent efb5450 commit 53eb520
Show file tree
Hide file tree
Showing 75 changed files with 2,200 additions and 630 deletions.
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,65 @@
## 도메인

- Path
- id, 상행역, 하행역, 거리를 가지는 경로 객체
- id, 하행역, 거리를 가지는 경로 객체

- Line
- id, 이름, 색, Map<Station, Path> 컬렉션을 가짐

- Station
- id, 이름을 가짐

- ShortestWayCalculator
- Line 객체를 파라미터로 받아 최단 경로와 거리를 계산하는 객체

- Direction
- 노선에 경로 추가 시 상행, 하행을 결정하는 ENUM

- AddPathStrategy
- 노선에 경로 추가시 분기와 중복 코드를 제거하기 위해 도입

## 기능 요구 사항

###

- 역을 등록할 수 있다.
- 역을 제거할 수 있다.

### 노선과 경로

- 노선은 하나의 직선이다.(순환하지 않는다.)
- 노선을 조회할 수 있다.
- 노선 조회 시 노선에 해당하는 역을 상행역부터 순서대로 조회한다.
- 모든 노선을 조회할 수 있다.
- 노선 조회 시 노선에 해당하는 역을 상행역부터 순서대로 조회한다.
- 노선을 등록할 수 있다.
- 노선을 제거할 수 있다.
- 노선 제거 시에 노선의 모든 경로가 제거 된다.
- 노선에 역(경로)를 등록할 수 있다.
- 기준역, 추가할 역, 거리, 추가할 역의 방향을 고려한다.
- 역들의 사이에 추가될 경우 등록할 경로의 거리가 기존 거리보다 짧아야 한다.
- 노선에 역이 없다면 최초 등록 시 두개의 역이 경로로 등록된다.
- 노선의 역(경로)를 제거할 수 있다.
- 중간에 등록된 역이 제거된다면 제거된 역의 양 쪽의 역의 경로 거리가 합산된다.
- 노선에 역이 두개 있다면 한개를 제거할 때 두 역이 모두 제거된다.
- 역이 제거될 때 노선에 등록된 역도 제거된다.

### 최단 경로 조회

- 두개 역 사이의 가장 짧은 거리를 계산한다.
- 경로와 거리, 비용도 같이 계산한다.
- 비용 정책 변경을 고려한다.
- 최단 거리에 따라 비용이 결정된다.
- 기본 정책
- 10km 까지 1250원
- 50km 까지 5km 당 100원의 추가 금액
- 50km 부터 8km 당 100원의 추가 금액
- [ ] 추가 정책
- 노선에 따른 추가 비용이 추가된다.
- 연령별 할인 정책이 추가된다.
- 13세 ~ 18세: 운임에서 350원을 공제한 금액의 20%할인
- 6세 ~ 12세: 운임에서 350원을 공제한 금액의 50%할인

## API

- GET /lines/{id}
Expand Down Expand Up @@ -94,3 +145,23 @@
- DELETE /lines/{line-id}/stations/{station-id}
- 노선의 역을 삭제한다.
- Response Status OK

- GET /fee?start={id}&end={id}
- Response OK

```json
{
"fee": 1250,
"stations": [
{
"id": 1,
"name": "수원"
},
{
"id": 2,
"name": "잠실나루"
}
]
}

```
31 changes: 19 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

sourceCompatibility = '11'

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.jgrapht:jgrapht-core:1.5.2'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'org.projectlombok:lombok'

implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1'
testAnnotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'io.rest-assured:rest-assured:4.4.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1'

runtimeOnly 'com.h2database:h2'
testImplementation 'io.rest-assured:rest-assured:4.4.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

runtimeOnly 'com.h2database:h2'
}

test {
useJUnitPlatform()
}
useJUnitPlatform()
}
Binary file added db/subway.mv.db
Binary file not shown.
Loading

0 comments on commit 53eb520

Please sign in to comment.