-
Notifications
You must be signed in to change notification settings - Fork 23
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
Step2: 경로 조회 기능 #9
base: syeeuns
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 예은님, 2단계 구현 고생하셨습니다.
몇 가지 코멘트 남겼으니 확인해주세요.
궁금하신 점 코멘트, DM 남겨주세요. 🙇♂️
public RouteRequest() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jackson 라이브러리 2.13 버전부터 request dto 에 no args constructor 는 필요 없다고 하네요.
https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.13
private DijkstraShortestPath<Station, Section> getShortestPath() { | ||
List<Station> allStations = stationRepository.findAll(); | ||
List<Section> allSections = sectionRepository.findAll(); | ||
WeightedMultigraph<Station, Section> graph = new WeightedMultigraph<>(Section.class); | ||
|
||
for (Station station : allStations) { | ||
graph.addVertex(station); | ||
} | ||
for (Section section : allSections) { | ||
Station upStation = allStations.stream() | ||
.filter(station -> station.getId().equals(section.getUpStationId())) | ||
.findFirst().get(); | ||
Station downStation = allStations.stream() | ||
.filter(station -> station.getId().equals(section.getDownStationId())) | ||
.findFirst().get(); | ||
graph.setEdgeWeight(graph.addEdge(upStation, downStation), section.getDistance()); | ||
} | ||
return new DijkstraShortestPath<>(graph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별개 객체로 분리하면 테스트 코드 작성이 훨씬 편리해지겠는데요? 😄
@@ -0,0 +1,54 @@ | |||
package subway.domain.service; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain 과 service 의 차이는 무엇일까요?
@Override | ||
public Station findByName(String name) { | ||
String sql = "select * from STATION where name = ?"; | ||
try { | ||
return jdbcTemplate.queryForObject(sql, rowMapper, name); | ||
} catch (Exception e) { | ||
throw new NoSuchElementException("존재하지 않는 역입니다."); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저장소에 아이템이 없는게 꼭 예외 상황일까요? 각 상황마다 예외 여부가 달라지지 않을까요? 🤔
private static final int BASE_FARE = 1250; | ||
private static final int ADDITIONAL_FARE = 100; | ||
private static final int FIRST_SURCHARGE_BASE_DISTANCE = 10; | ||
private static final int SECOND_SURCHARGE_BASE_DISTANCE = 50; | ||
private static final int FIRST_ADDITIONAL_DISTANCE = 5; | ||
private static final int SECOND_ADDITIONAL_DISTANCE = 8; | ||
|
||
public static int calculateByDistance(int distance) { | ||
int fare = BASE_FARE; | ||
|
||
if (distance > SECOND_SURCHARGE_BASE_DISTANCE) { | ||
int distanceOver50 = distance - SECOND_SURCHARGE_BASE_DISTANCE; | ||
fare += ((distanceOver50 + SECOND_ADDITIONAL_DISTANCE - 1) / SECOND_ADDITIONAL_DISTANCE) * ADDITIONAL_FARE; | ||
distance = SECOND_SURCHARGE_BASE_DISTANCE; | ||
} | ||
if (distance > FIRST_SURCHARGE_BASE_DISTANCE) { | ||
int distanceOver10 = distance - FIRST_SURCHARGE_BASE_DISTANCE; | ||
fare += ((distanceOver10 + FIRST_ADDITIONAL_DISTANCE - 1) / FIRST_ADDITIONAL_DISTANCE) * ADDITIONAL_FARE; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상수의 나열과 단순한 연산... enum class 가 떠오르는데요? 😄
No description provided.