-
Notifications
You must be signed in to change notification settings - Fork 97
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
[2단계 - 경로 조회 기능] 채채(신채원) 미션 제출합니다. #203
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단계 열심히 구현해주셨군요
다음 요청엔 1단계 merge 하며 남긴 피드백도 함께 반영해주세요~
private int calculate(Distance distance) { | ||
if (distance.isShorterSame(10)) { | ||
return 1250; | ||
} | ||
|
||
if (distance.isShorterSame(50)) { | ||
return 1250 + over10under50(distance.minusDistance(10).getDistance()); | ||
} | ||
return 1250 + over10under50(40) + over50(distance.minusDistance(50).getDistance()); | ||
} | ||
|
||
private int over10under50(int distance) { | ||
return (int) ((Math.ceil((distance - 1) / 5) + 1) * 100); | ||
} | ||
|
||
private int over50(int distance) { | ||
return (int) ((Math.ceil((distance - 1) / 8) + 1) * 100); | ||
} |
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.
해당 부분은 도메인 요구사항으로 보이네요!
도메인 레이어에 구현해보면 어떨까요?
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.
도메인 레이어로 수정하였습니다!
WeightedMultigraph<String, DefaultWeightedEdge> graph | ||
= new WeightedMultigraph(DefaultWeightedEdge.class); |
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.
WeightedMultigraph 의 vertex 는 역 이름을 사용하신 이유가 있을까요?
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.
다시 고민해본 결과 아이디로 하는 것이 맞다고 판단하여 수정하였습니다!
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.
아이디로 하는것이 맞다고 판단한 배경도 궁금해요~ 😄
Station 객체를 vertex 로 사용해볼 수 있지 않을까요?
this.stationDao = stationDao; | ||
} | ||
|
||
public ShortestPathResponse getDijkstraShortestPath(final ShortestPathRequest shortestPathRequest) { |
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.
읽기 전용 트랜잭션을 적용해보는건 어떨까요?
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.
읽기전용 트렌젝셔널과, 일반트렌젝셔널 모두 적용 하였습니다. 감사합니다!
WeightedMultigraph<String, DefaultWeightedEdge> graph | ||
= new WeightedMultigraph(DefaultWeightedEdge.class); |
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.
라이브러리는 언제든 변경될 수 있다고 생각해요 :)
추상화해보는건 어떨까요?
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.
인터페이스로 분리하였습니다!
|
||
@RestController | ||
@RequestMapping("/shortestPath") | ||
public class ShortestPathController { |
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.
테스트 코드가 필요해보여요!
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.
테스트코드 추가하겠습니다!
|
||
|
||
@RestController | ||
@RequestMapping("/shortestPath") |
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.
path가 카멜케이스인 이유가 궁금해요!
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.
찾아보니 pathVariable은 카멜케이스로 쓰고 url 은 카멜케이스를 쓰지 않는군요..! 수정하겠습니다!
|
||
@GetMapping | ||
public ResponseEntity<ShortestPathResponse> createStation(@Valid @RequestBody ShortestPathRequest shortestPathRequest) { | ||
ShortestPathResponse path = shortestPathService.getDijkstraShortestPath(shortestPathRequest); |
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.
Controller 는 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.
같은 의견입니다! 인터페이스를 분리함과 동시에 getDijkstraShortestPath 라는 함수이름도 getPath로 수정하였습니다! 꼼꼼학 봐주셔서 감사합니다!
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.
안녕하세요 채채!
리뷰 요청기간이 지나서 이번 미션은 이만 Merge 하겠습니다~
추가로 남긴 코멘트가 있으니 확인 부탁드려요 🙏
2단계 남은 미션도 화이팅입니다 🔥
궁금하신 점 있으시면 언제든 편하게 DM 남겨주세요 😄
setGraph(allSections, graph); | ||
GraphPath<Long, DefaultWeightedEdge> path = getPath(startStationId, targetStationId, graph); | ||
|
||
return new AbstractMap.SimpleEntry<>(path.getVertexList(), new Distance((int) path.getWeight())); |
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.
Map 자료구조로 반환해야할 이유가 있었을까요?! 🤔
경로(List) 와 거리(Distance)를 가지는 객체를 반환해보면 어떨까요~
1단계 때 쭉 해오신것 처럼요~
return new AbstractMap.SimpleEntry<>(path.getVertexList(), new Distance((int) path.getWeight())); | ||
} | ||
|
||
private void setGraph(List<Section> allSections, WeightedMultigraph<Long, DefaultWeightedEdge> 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.
지하철 이라는 도메인에서는 Graph 를 세팅
하는 것일까요 노선도 경로를 세팅
하는 것일까요? 😄
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface PathStrategy { |
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.
PathStrategy 로 해주신것은 나중에 최단경로 조회 외에도 최소환승경로 조회
같은 전략을 갈아끼우기 위해서 였을까요~?
public Distance plusDistance(final int distance) { | ||
return new Distance(this.distance += distance); | ||
} |
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.
값 객체끼리 더해주기 위한 메서드 활용 👍
+)
아래 두 코드는 어떤 차이가 있을까요?
new Distance(this.distance += distance);
new Distance(this.distance + distance);
public boolean isShorterSame(final int distance) { | ||
return this.distance < distance; | ||
} |
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.
메서드 이름과 내부 로직이 일치하고 있을까요 🤔
@Test | ||
void 최소경로를_가져온다() { | ||
PathRequest pathRequest = new PathRequest(station1Id, station3Id); |
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.
테스트 잘 추가해주셨네요!!
@Test | ||
void 요금_계산_10_50() { | ||
NormalFeeStrategy feeStrategy = new NormalFeeStrategy(); | ||
Distance distance = new Distance(16); // 예시 거리: 30 |
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 Section findById(Long id) { | ||
final String sql = "SELECT se.id AS section_id, se.distance, se.line_id, " + |
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.
테스트를 위해 테스트에만 정의한 메서드로 보이네요 💯
쉽지 않은 구현이었을텐데 고생 많으셨습니다~!!
개인적으로는 findById(식별자로 조회해오는 메서드) 같이 기본적이고 사용될 가능성이 있는 메서드라면
꼭 테스트에 정의하지 않아도 된다고 생각해요~
하지만.. 개인적인 취향인 관계로
엄격하게 나눈다면 채채가 구현해준 방법도 좋습니다~!!
//package subway.dao.dto; | ||
// | ||
//public class SectionStationResultMap { | ||
// | ||
// private final Long sectionId; |
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.
안쓰는 파일이라면 삭제해주셔도 되겠어요~
import subway.domain.path.ShortestDistancePathStrategy; | ||
|
||
@Configuration | ||
public class Config { |
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.
Config 라는 이름의 클래스는 설정
이라는 단순한 정보만 제공할 수 있겠어요 😢
No description provided.