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

Step2: 경로 조회 기능 #9

Open
wants to merge 3 commits into
base: syeeuns
Choose a base branch
from
Open

Conversation

syeeuns
Copy link

@syeeuns syeeuns commented Jun 11, 2023

No description provided.

Copy link
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 예은님, 2단계 구현 고생하셨습니다.
몇 가지 코멘트 남겼으니 확인해주세요.
궁금하신 점 코멘트, DM 남겨주세요. 🙇‍♂️

Comment on lines +11 to +12
public RouteRequest() {
}
Copy link
Member

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

Comment on lines +35 to +52
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);
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domain 과 service 의 차이는 무엇일까요?

Comment on lines +58 to +67
@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("존재하지 않는 역입니다.");
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저장소에 아이템이 없는게 꼭 예외 상황일까요? 각 상황마다 예외 여부가 달라지지 않을까요? 🤔

Comment on lines +5 to +24
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;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수의 나열과 단순한 연산... enum class 가 떠오르는데요? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants