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 지하철 노선도 관리 - 3단계] 다니(이다은) 미션 제출합니다. #141

Merged
merged 68 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e80a453
fix(dao): 노선 이름으로 데이터를 찾는 쿼리 버그 수정
da-nyee May 8, 2021
2c64ceb
test(dao): 노선 이름으로 데이터를 찾는 쿼리 테스트 작성
da-nyee May 8, 2021
e449cd8
docs: README.md 3단계 기능 요구사항 추가
yjksw May 6, 2021
a782255
docs: 객체 구조 설계 작성
da-nyee May 6, 2021
523c8c4
feat: 구간을 추가하는 기능 구현
yjksw May 6, 2021
be7971f
feat: 노선을 추가하는 기능 구현
yjksw May 7, 2021
493bffc
feat: 노선을 추가하는 기능 수정 및 구간 초기화
da-nyee May 7, 2021
65051f5
feat: 구간 추가 해당 노선 연결 여부 검증 로직 구현
da-nyee May 7, 2021
c07eacb
feat: 해당 노선에 이미 등록된 구간인지 검증하는 로직 구현
yjksw May 7, 2021
ec6e37b
feat: 등록 가능한 구간 거리인지 검증하는 로직 구현
yjksw May 7, 2021
5af65b7
chore: docs 디렉토리 생성
da-nyee May 7, 2021
37850f1
docs: TODO 작성
da-nyee May 7, 2021
4f85d7f
docs: README.md 기능 요구사항 수정
da-nyee May 7, 2021
329bf0e
fix: 구간 존재 검증 로직 수정
da-nyee May 7, 2021
62cd38a
feat: 구간 추가 기능 구현
da-nyee May 7, 2021
ee1d0e5
feat: 구간 제거 기능 구현
yjksw May 8, 2021
133cda1
refactor: Optional 반환으로 변경
da-nyee May 10, 2021
c9a2618
feat: 구간 삭제 검증 로직 구현
da-nyee May 10, 2021
dd68134
feat: 노선을 조회하는 기능 구현 - 추가 기능
yjksw May 10, 2021
d7b588b
refactor: 불필요한 import 삭제
da-nyee May 10, 2021
3ac4d01
fix: 노선 조회 추가 기능 버그 수정
da-nyee May 10, 2021
2c09441
feat: 구간 Controller 작성
da-nyee May 10, 2021
8e8588d
refactor: getter 대신 DTO 사용
yjksw May 10, 2021
d658475
refactor: Dao 인터페이스 분리
yjksw May 10, 2021
2322642
refactor: 불필요한 생성자 제거
yjksw May 10, 2021
5c1c250
refactor: 노선 유효성 검증 로직 수정
yjksw May 10, 2021
2434d8a
refactor: DAO 참조를 서비스 참조로 변경
da-nyee May 10, 2021
fc75427
test: 인수 테스트 버그 수정
yjksw May 10, 2021
4a7a1b7
refactor: 불필요한 import 삭제
yjksw May 10, 2021
dba2a8d
refactor: 메소드 참조로 변경
da-nyee May 10, 2021
e2d40e1
refactor: 커스텀 예외 상태코드 최상위에서 지정
yjksw May 11, 2021
586126d
fix: 유효성 검사 코드 버그 수정
yjksw May 11, 2021
22df399
test: 역 인수 테스트 변수 추출
da-nyee May 11, 2021
f51b610
refactor: 구간 검증 로직 수정 및 사용
da-nyee May 11, 2021
b8fc7cf
test: 노선 조회 인수 테스트 수정
yjksw May 11, 2021
14eead8
test: 구간 인수 테스트 작성
da-nyee May 11, 2021
c7aa20f
test: truncate.sql 추가
yjksw May 11, 2021
e678cd8
test: 인수 테스트 예외 케이스 추가
yjksw May 11, 2021
d72d851
docs: TODO 체크
da-nyee May 11, 2021
f7a8549
fix(dao): rebase conflicts 해결
da-nyee May 11, 2021
4b6ffc3
feat(station): 역 이름 길이 유효성 검증 추가
da-nyee May 11, 2021
9a4960d
feat(line): 노선 이름 길이 유효성 검증 추가
da-nyee May 11, 2021
e2b7b7f
feat(section): 구간 단위 테스트 작성 및 구간 유효성 검증 추가
da-nyee May 11, 2021
b56238d
refactor(exception): 디렉토리 구조 정리 및 클래스명 변경
da-nyee May 11, 2021
3499deb
test(subway): @DisplayName 수정 및 메소드명 변경
da-nyee May 11, 2021
aa49654
style(dao): 메소드 나열 순서 변경
da-nyee May 11, 2021
965c4c7
refactor(subway): 생성자 체이닝 적용
da-nyee May 11, 2021
bd54bdd
refactor(subway): 불필요한 import 삭제
da-nyee May 11, 2021
daf00ad
test(sections): 단위 테스트 작성
da-nyee May 17, 2021
c4f721f
refactor(service): @Transactional 추가
da-nyee May 17, 2021
120e1ec
refactor(service): private -> public 생성자로 변경
da-nyee May 17, 2021
0a2ac89
test(acceptance): 중복 로직 메소드 추출
da-nyee May 17, 2021
bcd7943
refactor(dto): Bean Validation으로 유효성 검증
da-nyee May 17, 2021
98e83b8
fix(dto): Bean Validation으로 유효성 검증 버그 해결
da-nyee May 17, 2021
280c69a
refactor(service): 공백 라인 추가 및 메소드 분리
da-nyee May 18, 2021
8e8d018
refactor(domain): Bean Validation으로 유효성 검증
da-nyee May 18, 2021
1bdad48
refactor(section): 파라미터명 수정
da-nyee May 18, 2021
7aa5a39
refactor(controller): lineId 유효성 검증을 Service에서 하도록 변경
da-nyee May 18, 2021
41a5aca
refactor(service): Service에서 여러 DAO를 의존하는 구조로 변경
da-nyee May 18, 2021
47f1123
refactor(dao): EXISTS, LIMIT 쿼리로 데이터 존재성 체크
da-nyee May 18, 2021
9bf7477
refactor(dao): rowMapper() 분리
da-nyee May 18, 2021
4e0caf0
test(section): data.sql 대신 @BeforeEach로 test fixtures 생성
da-nyee May 18, 2021
0d90e79
refactor(section): 클래스명 변경
da-nyee May 18, 2021
ce8c234
test(section): 구간 생성 및 삭제를 더 상세한 케이스로 나눠 테스트 작성
da-nyee May 18, 2021
d538621
refactor(subway): DTO가 도메인 객체 생성 책임을 가지도록 변경
da-nyee May 19, 2021
71407d7
refactor(domain): Bean Validation으로 유효성 검증 삭제
da-nyee May 21, 2021
eae6cdb
test(section): 별도 클래스 대신 @BeforeEach로 test fixture 생성
da-nyee May 21, 2021
7db3e4b
test(subway): test fixtures 수정
da-nyee May 21, 2021
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
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'

// handlebars
implementation 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.3.0'
Expand Down
44 changes: 43 additions & 1 deletion README.md → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,49 @@ npm run dev
- [x] H2 log/console 확인

### 스프링 JDBC H2 DB 테스트
- [x] DAO 테스트 작성
- [x] DAO 테스트 작성
<br>

> 3 단계

### 노선 추가 기능 수정
- [x] 3가지 정보 추가
- [x] 상행 종점 (upStationId)
- [x] 하행 종점 (downStationId)
- [x] 두 종점간의 거리 (distance)
- [x] 노선 추가 시 상행-하행 구간 등록

### 구간 추가
- [x] 3가지 정보 추가
- [x] 상행 종점 (upStationId)
- [x] 하행 종점 (downStationId)
- [x] 두 종점간의 거리 (distance)
- [x] 하나의 노선에서 종점역 추가될 경우
- 새 구간 하행 - 기존 구간 상행 비교 --> 상행 종점 변경
- 새 구간 상행 - 기존 구간 하행 비교 --> 하행 종점 변경
- [x] 하나의 노선에서 중간역 추가될 경우 재배치
- [x] Distance 변경
- 새 구간 상행 - 기존 구간 상행 비교 --> 중간 추가
- 새 구간 하행 - 기존 구간 하행 비교 --> 중간 추가
- [x] 중간역 등록 시 기존 구간 길이보다 크거나 같으면 등록 불가
- [x] 해당 노선에 이미 등록된 구간 추가 불가
- [x] 상행역과 하행역 둘 중 하나는 무조건 해당 노선에 포함

### 구간 제거
- [x] URI 정보 `/lines/{line_id}/sections?stationId={station_id}`
- [x] 종점이 제거될 경우 다음으로 오던 역이 종점
- [x] 중간역이 제거될 경우 재배치
- [x] Distance 변경
- [x] 구간이 하나인 노선에서 마지막 구간 제거 불가

### 노선 조회 기능 수정
- [x] 상행 -> 하행 역 목록 차례로 출력

### 지하철 역 / 지하철 노선 / 지하철 구간 구조 설계
|Station |Line |Section |
|:------:|:---:|:------:|
| | |lineId |
| | |조회 시 구간 정렬|

<br>

Expand Down
2 changes: 2 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- 테스트 코드 메소드 분리
- AssertJ 메소드 활용

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/wooteco/subway/exception/NoLineException.java

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/wooteco/subway/exception/SubwayException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class SubwayException extends RuntimeException {
private final HttpStatus httpStatus;
private final String message;

public SubwayException(HttpStatus httpStatus, String message) {
this.httpStatus = httpStatus;
public SubwayException(String message) {
this.httpStatus = HttpStatus.BAD_REQUEST;
this.message = message;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.line;

import wooteco.subway.exception.SubwayException;

public class LineDuplicationException extends SubwayException {
public LineDuplicationException() {
super("이미 존재하는 노선색깔입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.line;

import wooteco.subway.exception.SubwayException;

public class LineLengthException extends SubwayException {
public LineLengthException() {
super("2자 이상의 이름을 입력해주세요.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package wooteco.subway.exception.line;

import wooteco.subway.exception.SubwayException;

public class LineNonexistenceException extends SubwayException {

public LineNonexistenceException() {
super("존재하지 않는 노선입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.line;

import wooteco.subway.exception.SubwayException;

public class LineSuffixException extends SubwayException {
public LineSuffixException() {
super("-선으로 끝나는 이름을 입력해주세요.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.section;

import wooteco.subway.exception.SubwayException;

public class SectionAdditionException extends SubwayException {
public SectionAdditionException() {
super("추가할 수 없는 구간입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.section;

import wooteco.subway.exception.SubwayException;

public class SectionDeletionException extends SubwayException {
public SectionDeletionException() {
super("삭제할 수 없는 구간입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.section;

import wooteco.subway.exception.SubwayException;

public class SectionDuplicationException extends SubwayException {
public SectionDuplicationException() {
super("상행역과 하행역은 중복되지 않게 입력해주세요.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.station;

import wooteco.subway.exception.SubwayException;

public class StationDuplicationException extends SubwayException {
public StationDuplicationException() {
super("이미 존재하는 역입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.station;

import wooteco.subway.exception.SubwayException;

public class StationLengthException extends SubwayException {
public StationLengthException() {
super("2자 이상의 역 이름을 입력해주세요.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package wooteco.subway.exception.station;

import wooteco.subway.exception.SubwayException;

public class StationNonexistenceException extends SubwayException {

public StationNonexistenceException() {
super("존재하지 않는 역입니다.");
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wooteco.subway.exception.station;

import wooteco.subway.exception.SubwayException;

public class StationSuffixException extends SubwayException {
public StationSuffixException() {
super("-역으로 끝나는 이름을 입력해주세요.");
}
}
19 changes: 13 additions & 6 deletions src/main/java/wooteco/subway/line/Line.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wooteco.subway.line;

import wooteco.subway.exception.LineSuffixException;
import wooteco.subway.exception.line.LineLengthException;
import wooteco.subway.exception.line.LineSuffixException;

import java.util.Objects;

Expand All @@ -14,14 +15,14 @@ public class Line {
public Line() {
}

public Line(Long id, String name, String color) {
this.id = id;
this.name = name;
this.color = color;
public Line(String name, String color) {
this(null, name, color);
}

public Line(String name, String color) {
public Line(Long id, String name, String color) {
validateSuffix(name);
validateLength(name);
this.id = id;
this.name = name;
this.color = color;
}
Expand All @@ -36,6 +37,12 @@ private boolean isNotEndsWithLine(String name) {
return !name.endsWith(SUFFIX);
}

private void validateLength(String name) {
if (name.length() < 2) {
throw new LineLengthException();
}
}

public Long getId() {
return id;
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/wooteco/subway/line/LineController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import wooteco.subway.station.StationResponse;

import javax.validation.Valid;
import java.net.URI;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -18,15 +20,15 @@ public LineController(LineService lineService) {
}

@PostMapping
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest lineRequest) {
public ResponseEntity<LineResponse> createLine(@Valid @RequestBody LineRequest lineRequest) {
Line newLine = lineService.add(lineRequest);
LineResponse lineResponse = new LineResponse(newLine);
return ResponseEntity.created(URI.create("/lines/" + newLine.getId())).body(lineResponse);
}

@GetMapping
public ResponseEntity<List<LineResponse>> showLines() {
List<Line> lines = lineService.lines();
List<Line> lines = lineService.findAll();
List<LineResponse> lineResponses = lines.stream()
.map(LineResponse::new)
.collect(Collectors.toList());
Expand All @@ -35,13 +37,15 @@ public ResponseEntity<List<LineResponse>> showLines() {

@GetMapping(value = "/{id}")
public ResponseEntity<LineResponse> showLine(@PathVariable Long id) {
Line line = lineService.line(id);
LineResponse lineResponse = new LineResponse(line);
Line line = lineService.findById(id);
List<StationResponse> sortedStations = lineService.sortedStationsByLineId(id);
LineResponse lineResponse = new LineResponse(line, sortedStations);
return ResponseEntity.ok().body(lineResponse);
}

@PutMapping(value = "/{id}")
public ResponseEntity<Object> updateLine(@PathVariable Long id, @RequestBody LineRequest lineRequest) {
public ResponseEntity<Void> updateLine(@PathVariable Long id,
@Valid @RequestBody LineRequest lineRequest) {
lineService.update(id, lineRequest);
return ResponseEntity.ok().build();
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/wooteco/subway/line/LineDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public interface LineDao {

List<Line> findAll();

void update(Long id, String name, String color);

Line findById(Long id);
Optional<Line> findById(Long id);

Optional<Line> findByName(String name);

Optional<Line> findByColor(String color);

void update(Long id, String name, String color);

void delete(Long id);
}
Loading