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

[터틀] 지하철 경로 조회 - TDD 미션 제출합니다. #48

Merged
merged 30 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c7b39f2
feat : 실습
pci2676 May 12, 2020
49474f9
feat : 1단계 캐시
pci2676 May 13, 2020
580ae6b
checkpoint
pci2676 May 13, 2020
7c0a541
feat : 최단 거리 경로 찾기 기능 구현
pci2676 May 13, 2020
72c05df
feat : service에서 최단 경로 그래프 가져오기
pci2676 May 13, 2020
72340ec
refactor : 최단 경로 로직 변경
pci2676 May 14, 2020
80aae87
test : 테스트 실패 코드 수정
pci2676 May 14, 2020
4d6f48f
feat : 경로 찾기 인수테스트 성공
pci2676 May 15, 2020
3928a96
feat : Web View 연결
pci2676 May 15, 2020
e035eda
refactor : StationController에서 StationRepository 의존 제거
pci2676 May 15, 2020
8c0cd84
refactor : PathService의 데이터베이스 접근 횟수 개선
pci2676 May 15, 2020
adb141e
fix : 출발역과 도착역이 연결이 되어 있지 않은 경우 처리
pci2676 May 15, 2020
49e5757
refactor: 초기 데이터를 설정하는 방법을 ApplicationRunner에서 data.sql로 변경
begaonnuri May 18, 2020
ca23215
refactor: lineService 필드에 final 추가
begaonnuri May 18, 2020
f73ee8a
refactor: @ModelAttribute 제거
begaonnuri May 18, 2020
83adc39
refactor: 빈 생성자를 private으로 변경
begaonnuri May 18, 2020
5d9285b
refactor: Line 클래스에서 Set<Edge>를 사용하던 로직을 Edges로 이동
begaonnuri May 18, 2020
8da51d9
refactor: Edge들의 StationId를 받아오는 로직 depth 개선
begaonnuri May 18, 2020
a2c770e
refactor: 사용하지 않는 코드 제거
begaonnuri May 18, 2020
427de66
refactor: SubwayGraphKey의 symbol 필드 제거
begaonnuri May 18, 2020
bc9b429
test: 테스트코드의 변수명을 적절하게 변경
begaonnuri May 18, 2020
e607a4e
test: 하위 테스트 클래스에서만 사용되는 로직을 해당 클래스로 이동
begaonnuri May 18, 2020
00f7cac
test: SubwayGraphTest의 예외사항 테스트 추가
begaonnuri May 18, 2020
1f41d52
refactor: makeSubwayGraphs의 인자 제거
begaonnuri May 18, 2020
d365f48
refactor: 설정 파일의 profiles 제거
begaonnuri May 18, 2020
cb480c8
test: AcceptanceTest의 중복 코드 제거
begaonnuri May 24, 2020
1654f9e
refactor: LineService의 중복 제거
begaonnuri May 24, 2020
c380f6f
refactor: Lines의 로직이 PathService에 드러나지 않도록 변경
begaonnuri May 24, 2020
aaf87bd
refactor: 테스트 메소드 분리
begaonnuri May 25, 2020
a3b299e
refactor: AcceptanceTest의 픽스쳐를 각 클래스로 이동
begaonnuri May 25, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@SpringBootApplication
public class SubwayAdminApplication {

public static void main(String[] args) {
SpringApplication.run(SubwayAdminApplication.class, args);
}

}
15 changes: 14 additions & 1 deletion src/main/java/wooteco/subway/admin/config/ETagHeaderFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package wooteco.subway.admin.config;

// TODO: ETag 관련 설정하기
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.ShallowEtagHeaderFilter;

@Configuration
public class ETagHeaderFilter {
@Bean
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() {
FilterRegistrationBean<ShallowEtagHeaderFilter> filter
= new FilterRegistrationBean<>(new ShallowEtagHeaderFilter());
filter.addUrlPatterns("/lines/*");
filter.setName("etagFilter");
return filter;
}
}
47 changes: 32 additions & 15 deletions src/main/java/wooteco/subway/admin/controller/LineController.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
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.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.dto.LineDetailResponse;
import wooteco.subway.admin.dto.LineRequest;
import wooteco.subway.admin.dto.LineResponse;
import wooteco.subway.admin.dto.LineStationCreateRequest;
import wooteco.subway.admin.dto.WholeSubwayResponse;
import wooteco.subway.admin.service.LineService;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/lines")
public class LineController {
private LineService lineService;
private final LineService lineService;

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

@PostMapping(value = "/lines")
@PostMapping
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest view) {
Line persistLine = lineService.save(view.toLine());

Expand All @@ -29,37 +38,45 @@ public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest view) {
.body(LineResponse.of(persistLine));
}

@GetMapping("/lines")
@GetMapping
public ResponseEntity<List<LineResponse>> showLine() {
return ResponseEntity.ok().body(LineResponse.listOf(lineService.showLines()));
}

@GetMapping("/lines/{id}")
@GetMapping("/{id}")
public ResponseEntity<LineDetailResponse> retrieveLine(@PathVariable Long id) {
return ResponseEntity.ok().body(lineService.findLineWithStationsById(id));
}

@PutMapping("/lines/{id}")
public ResponseEntity updateLine(@PathVariable Long id, @RequestBody LineRequest view) {
@PutMapping("/{id}")
public ResponseEntity<Void> updateLine(@PathVariable Long id, @RequestBody LineRequest view) {
lineService.updateLine(id, view);
return ResponseEntity.ok().build();
}

@DeleteMapping("/lines/{id}")
public ResponseEntity deleteLine(@PathVariable Long id) {
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteLine(@PathVariable Long id) {
lineService.deleteLineById(id);
return ResponseEntity.noContent().build();
}

@PostMapping("/lines/{lineId}/stations")
public ResponseEntity addLineStation(@PathVariable Long lineId, @RequestBody LineStationCreateRequest view) {
lineService.addLineStation(lineId, view);
return ResponseEntity.ok().build();
@PostMapping("/{lineId}/stations")
public ResponseEntity<LineResponse> addEdge(@PathVariable Long lineId, @RequestBody LineStationCreateRequest view) {
Line line = lineService.addLineStation(lineId, view);
return ResponseEntity
.created(URI.create("/lines/" + lineId + "/stations"))
.body(LineResponse.of(line));
}

@DeleteMapping("/lines/{lineId}/stations/{stationId}")
public ResponseEntity removeLineStation(@PathVariable Long lineId, @PathVariable Long stationId) {
@DeleteMapping("/{lineId}/stations/{stationId}")
public ResponseEntity<Void> removeLineStation(@PathVariable Long lineId, @PathVariable Long stationId) {
lineService.removeLineStation(lineId, stationId);
return ResponseEntity.noContent().build();
}

@GetMapping("/map")
public ResponseEntity<WholeSubwayResponse> getAllSubway() {
return ResponseEntity.ok(lineService.wholeLines());
}

}
32 changes: 12 additions & 20 deletions src/main/java/wooteco/subway/admin/controller/PageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,32 @@

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import wooteco.subway.admin.repository.StationRepository;
import wooteco.subway.admin.service.LineService;

@Controller
public class PageController {
private LineService lineService;
private StationRepository stationRepository;

public PageController(LineService lineService, StationRepository stationRepository) {
this.lineService = lineService;
this.stationRepository = stationRepository;
}

@GetMapping(value = "/", produces = MediaType.TEXT_HTML_VALUE)
public String index() {
return "admin/index";
}

@GetMapping(value = "/stations", produces = MediaType.TEXT_HTML_VALUE)
public String stationPage(Model model) {
model.addAttribute("stations", stationRepository.findAll());
public String stationPage() {
return "admin/admin-station";
}

@GetMapping(value = "/lines", produces = MediaType.TEXT_HTML_VALUE)
public String linePage(Model model) {
model.addAttribute("lines", lineService.showLines());
return "admin/admin-line";
}

@GetMapping(value = "/edges", produces = MediaType.TEXT_HTML_VALUE)
public String edgePage(Model model) {
public String edgePage() {
return "admin/admin-edge";
}

@GetMapping(value = "/lines/map", produces = MediaType.TEXT_HTML_VALUE)
public String mapPage() {
return "service/map";
}

@GetMapping(value = "/search", produces = MediaType.TEXT_HTML_VALUE)
public String searchPage() {
return "service/search";
}
}
25 changes: 25 additions & 0 deletions src/main/java/wooteco/subway/admin/controller/PathController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package wooteco.subway.admin.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wooteco.subway.admin.dto.PathRequest;
import wooteco.subway.admin.dto.PathResponse;
import wooteco.subway.admin.service.PathService;

@RestController
@RequestMapping("/paths")
public class PathController {
private final PathService pathService;

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

@GetMapping
public ResponseEntity<PathResponse> findPath(PathRequest pathRequest) {
return ResponseEntity.ok(pathService.findPath(pathRequest));
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
package wooteco.subway.admin.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import wooteco.subway.admin.domain.Station;
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.dto.StationCreateRequest;
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;
}

@PostMapping("/stations")
public ResponseEntity<StationResponse> createStation(@RequestBody StationCreateRequest view) {
Station station = view.toStation();
Station persistStation = stationRepository.save(station);

return ResponseEntity
.created(URI.create("/stations/" + persistStation.getId()))
.body(StationResponse.of(persistStation));
public StationController(final StationService stationService) {
this.stationService = stationService;
}

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

@PostMapping("/stations")
public ResponseEntity<StationResponse> createStation(@RequestBody StationCreateRequest request) {
StationResponse stationResponse = stationService.save(request);
// TODO : body 없이 반환
return ResponseEntity
.created(URI.create("/stations/" + stationResponse.getId()))
.body(stationResponse);
}

@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();
}
}
58 changes: 58 additions & 0 deletions src/main/java/wooteco/subway/admin/domain/Edge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package wooteco.subway.admin.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;

public class Edge {
@Id
private Long id;
private Long preStationId;
private Long stationId;
private int distance;
private int duration;

@PersistenceConstructor
public Edge(final Long id, final Long preStationId, final Long stationId, final int distance, final int duration) {
this.id = id;
this.preStationId = preStationId;
this.stationId = stationId;
this.distance = distance;
this.duration = duration;
}

public Edge(Long preStationId, Long stationId, int distance, int duration) {
this.preStationId = preStationId;
this.stationId = stationId;
this.distance = distance;
this.duration = duration;
}

public boolean isNotFirst() {
return preStationId != null;
}

public boolean isSameStationId(Long stationId) {
return this.stationId.equals(stationId);
}

public void updatePreLineStation(Long preStationId) {
this.preStationId = preStationId;
}

public Long getPreStationId() {
return preStationId;
}

public Long getStationId() {
return stationId;
}

public int getDistance() {
return distance;
}

public int getDuration() {
return duration;
}

}
Loading