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

[BE] 가까운 지하철 역을 2개 보여준다. #575

Open
wants to merge 8 commits into
base: dev-be
Choose a base branch
from

Conversation

tsulocalize
Copy link
Contributor

❗ Issue

✨ 구현한 기능

  • 지하철 역을 2개 보여주는 기능
  • 환승역을 하나로 보여주는 기능

📢 논의하고 싶은 내용

🎸 기타

Copy link
Contributor

@tkdgur0906 tkdgur0906 left a comment

Choose a reason for hiding this comment

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

고생많으셨습니다!
리뷰 한번 확인해주세요~

private static final double AVERAGE_WALKING_SPEED = 1.3 * 60; // meter per minute
// meter per second * minute unit * decreasing speed on open street
private static final double AVERAGE_WALKING_SPEED = 1.3 * 60 * 0.4;
private static final int MAX_NESTING_STATION_NUMBER = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

중첩된 지하철역 수가 4인 이유가 있나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

대한민국 내 환승역 최대 중첩수가 4 입니다!

@@ -25,7 +28,17 @@ public SubwayStationResponse readNearestStation(double latitude, double longitud
double distance = Math.sqrt(dx * dx + dy * dy);
return SubwayStationResponse.of(station, (int) Math.round(distance / AVERAGE_WALKING_SPEED));
Copy link
Contributor

Choose a reason for hiding this comment

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

거리 계산 로직을 메서드 분리하면 좋을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!

private static final List<SubwayStation> SUBWAY_STATIONS = SubwayReader.readSubwayStationData();

public SubwayStationResponse readNearestStation(double latitude, double longitude) {
public List<SubwayStationResponse> readNearestStation(double latitude, double longitude) {
Copy link
Contributor

Choose a reason for hiding this comment

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

스트림이 길어서 가독성이 좀 떨어진다고 생각하는데, 인지 단위로 한번씩 끊는 것은 어떤가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!

@ParameterizedTest
@MethodSource("provideStationData")
void readNearestStation(double latitude, double longitude, String nearestStationName) {
void readNearestStation(double latitude, double longitude, Station nearestStation, Station nextNearestStation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

테스트 코드를 맨 위로 올리는 것은 어떤가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!


public SubwayStationResponse merge(SubwayStationResponse response) {
if (!stationName.equals(response.stationName)) {
throw new BangggoodException(ExceptionCode.STATION_NOT_SAME);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new BangggoodException(ExceptionCode.STATION_NOT_SAME);
throw new BangggoodException(ExceptionCode.STATION_NAME_NOT_SAME);

예외 메시지도 변경되면 좋겠어요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!

Comment on lines 21 to 22
public ResponseEntity<List<SubwayStationResponse>> readNearestStation(@RequestParam("latitude") double latitude,
@RequestParam("longitude") double longitude) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Double로 바꿔야 될 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!


public static SubwayStationResponse of(SubwayStation station, Integer walkingTime) {
return new SubwayStationResponse(station.getName(), station.getLine(), walkingTime);
List<String> stationLine = new ArrayList<>();
stationLine.add(station.getLine());
Copy link
Contributor

Choose a reason for hiding this comment

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

어차피 1개만 받는 것 같은데 왜 List를 선택하셨나요??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

merge() 메서드를 통해 다른 Response와 합치기 위함입니다.

잠실역 2호선.merge(잠실역 8호선) = 잠실역 2호선,8호선

Copy link
Contributor

@shin-jisong shin-jisong left a comment

Choose a reason for hiding this comment

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

간단한 리뷰만 남겼습니다! 수고하셨습니다~

@@ -16,6 +18,13 @@ public SubwayStation(Integer id, String name, String line, double latitude, doub
this.longitude = longitude;
}

public double getDistance(double latitude, double longitude) {
Copy link
Contributor

Choose a reason for hiding this comment

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

getXX의 명명은 getter와 혼동되는 것 같은데 함수의 명명을 바꿔보는 것 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

calculateDistance로 바꿨습니다!

Copy link
Contributor

@tkdgur0906 tkdgur0906 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~

.min(Comparator.comparing(SubwayStationResponse::walkingTime))
.orElseThrow(() -> new BangggoodException(ExceptionCode.STATION_NOT_FOUND));
.sorted(Comparator.comparing(SubwayStationResponse::getWalkingTime))
.limit(MAX_NESTING_STATION_NUMBER * REQUESTED_STATION_NUMBER)
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분은 어떤 의미의 코드인가요??

Comment on lines +27 to 28
double distance = station.calculateDistance(latitude, longitude);
return SubwayStationResponse.of(station, (int) Math.round(distance / AVERAGE_WALKING_SPEED));
Copy link
Contributor

Choose a reason for hiding this comment

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

SubwayStation 클래스에 walkingTime 계산을 요청할 수도 있지 않을까요?
뒤에 (int) Math.round(distance / AVERAGE_WALKING_SPEED)); 로직과 따로 있지 않아도 될 것 같아요

Comment on lines +32 to +35
.collect(Collectors.groupingBy(
SubwayStationResponse::getStationName,
Collectors.reducing(SubwayStationResponse::merge)
));
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분만 조금 더 개선하면 이해하기 쉬울 것 같아요!

Copy link
Contributor

@shin-jisong shin-jisong left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

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

Successfully merging this pull request may close these issues.

4 participants