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

✨ [Feature/vote] implement getting candidates API #78

Merged
merged 23 commits into from
Mar 29, 2025
Merged

Conversation

linirini
Copy link
Member

@linirini linirini commented Mar 24, 2025

#️⃣ 연관된 이슈

📝 작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

  • 투표 후보지 목록을 조회하여 필요한 모든 정보를 응답으로 담아 전달합니다.
  • 투표 후보지가 아직 등록되어 있지 않다면, 지하철역 추천 캐시로부터 목록을 조회해와 후보지 정보를 저장 후 반환합니다.

📸 스크린샷 (선택)

💬 리뷰 요구사항(선택)

  • pr 사이즈가 너무 커질 것이 우려되어 우선 후보지 등록 API 관련한 pr을 열었습니다.
  • 이후 개발할 API에 필요하므로, 빠른 리뷰와 머지가 필요합니다..
  • 고민 지점은 코멘트로 공유했습니다.
  • 리팩터링 브랜치 머지하면서 충돌이 발생해서 파일 이동이 많이 섞여 있습니다. 작업 커밋만 모아보시려명 링크를 눌러주세요!

@linirini linirini added ✨ Feature new feature 🥇 Urgency 1 긴급도 높음 labels Mar 24, 2025
@linirini linirini added this to the 2차 MVP milestone Mar 24, 2025
@linirini linirini self-assigned this Mar 24, 2025
@linirini linirini linked an issue Mar 24, 2025 that may be closed by this pull request
4 tasks
@@ -19,6 +18,7 @@
@RequiredArgsConstructor
public class RoutePersistenceAdapter implements SaveRoutePort, RetrieveRoutePort {

public static final List<String> ROUTE_ONE_LIST = List.of("경부선", "경인선", "경원선", "장항선");
Copy link
Member Author

Choose a reason for hiding this comment

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

1호선 네이밍 통일 관련 작업을 코드 레벨에 반영했습니다!

@@ -153,4 +164,17 @@ private double calculateDistance(Point p1, Station station) {
// 유클리드 거리 공식 적용
return Math.sqrt(Math.pow(lat2 - lat1, 2) + Math.pow(lon2 - lon1, 2));
}

@Override
@Cacheable(value = "recommendStations", cacheManager = "stationCacheManager", key = "#roomId")
Copy link
Member Author

Choose a reason for hiding this comment

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

캐시에서 지하철 추천 목록을 조회해옵니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

이부분 저랑 좀 맞춰보죠!

Station station,
List<Route> routes,
TmapPublicTransportationParsedResponse transportationParsedResponse,
List<CommentResponse> comments //comment 도메인 구현 시 List<Comment>로 교체
Copy link
Member Author

Choose a reason for hiding this comment

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

응답 정의를 위해 우선 CommentResponse를 생성하였습니다.
추후에 댓글 추가/조회 API가 구현된다면 해당 usecase를 사용하여 관련 응답을 반영 예정입니다.


public record RouteResponse(
String name
//TODO: String color
Copy link
Member Author

Choose a reason for hiding this comment

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

이 부분이 고민됩니다.
호선 색깔 정보를 함께 반환해야하는데, 색깔 정보를 따로 DB에서 저장하지 않고 있다보니 Tmap API를 통해서만 색깔 정보를 조회할 수 있어요.
어떻게 처리하면 좋을지 두분의 의견이 필요합니다..ㅜㅜ

Copy link
Collaborator

Choose a reason for hiding this comment

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

Git에서 리뷰할 때는 코드 스니펫만 보이고 전체 로직을 보기가 좀 힘들어서 그런데 공공데이터 API를 호출해서 저장한 DB에는 호선에 대한 색상 정보가 없고 Tmap API를 호출해서 호선 색상 정보를 받아와야해서 고민이신걸까요?
음,, 몇가지 방법이 떠오르는건

  1. Tmap API를 호출하는 시점에서 호선 색깔 정보를 같이 캐싱하는 방법. 이렇게 하면 DB에도 별도 컬럼 추가할 필요도 없고 API 호출을 최소화할 수 있고 구현도 간단함. Spring 캐시 또는 Redis Cache 어떤 것이든 괜찮을 것 같아요.
  2. DB에 컬럼을 추가하고 받아온 색상 정보를 DB에 업데이트하는 방법
  3. 지하철 색상 정보가 그렇게 변경되는 정보가 아니기 때문에 정적 파일 등으로 추가하고 반환하는 방법

등이 있을 것 같아요! 전체 로직은 봐야하겠지만 전 캐싱이 제일 좋을 것 같습니다 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

호선색깔 필요없다고 하셨습니다 (디자이너 피셜)


@Repository
@RequiredArgsConstructor
public class VoteCommandRedisAdapter implements SaveVotePort {
Copy link
Member Author

Choose a reason for hiding this comment

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

투표 결과를 저장하는 Adapter입니다! 해당 어댑터는 추후 투표 생성 API를 개발하면서 변경될 가능성이 높기 때문에 이번 pr에선 리뷰하지 않는 것을 권장합니다 ㅎㅎ

@@ -39,4 +49,37 @@ void doesNotSaveStationsIfAlreadyExists() {
// then
assertThat(stationRepository.findAll()).hasSize(1);
}

//TODO: 적절한 테스트 방법이 떠오르지 않아요.
Copy link
Member Author

Choose a reason for hiding this comment

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

그렇습니다...

Copy link
Collaborator

@yunyoung1819 yunyoung1819 left a comment

Choose a reason for hiding this comment

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

리뷰 남겨놓았습니다 👍
PR 보니까 작업하신 부분이 많네요! 투표 API 구현하느라 고생하셨습니다. 😄


public record RouteResponse(
String name
//TODO: String color
Copy link
Collaborator

Choose a reason for hiding this comment

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

Git에서 리뷰할 때는 코드 스니펫만 보이고 전체 로직을 보기가 좀 힘들어서 그런데 공공데이터 API를 호출해서 저장한 DB에는 호선에 대한 색상 정보가 없고 Tmap API를 호출해서 호선 색상 정보를 받아와야해서 고민이신걸까요?
음,, 몇가지 방법이 떠오르는건

  1. Tmap API를 호출하는 시점에서 호선 색깔 정보를 같이 캐싱하는 방법. 이렇게 하면 DB에도 별도 컬럼 추가할 필요도 없고 API 호출을 최소화할 수 있고 구현도 간단함. Spring 캐시 또는 Redis Cache 어떤 것이든 괜찮을 것 같아요.
  2. DB에 컬럼을 추가하고 받아온 색상 정보를 DB에 업데이트하는 방법
  3. 지하철 색상 정보가 그렇게 변경되는 정보가 아니기 때문에 정적 파일 등으로 추가하고 반환하는 방법

등이 있을 것 같아요! 전체 로직은 봐야하겠지만 전 캐싱이 제일 좋을 것 같습니다 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

이 Candidate는 Redis에서 보관중인 내용을 투표 시작 시점에 가져가서 저장하는 용도인가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

맞아요! 투표 시작 시점을 명확하게 알 수 없기 때문에, 후보지 조회 서비스에서 존재하지 않는다면 캐시에서 값을 가져와서 저장하고, 캐시를 지우도록 구현했어요!

@@ -153,4 +164,17 @@ private double calculateDistance(Point p1, Station station) {
// 유클리드 거리 공식 적용
return Math.sqrt(Math.pow(lat2 - lat1, 2) + Math.pow(lon2 - lon1, 2));
}

@Override
@Cacheable(value = "recommendStations", cacheManager = "stationCacheManager", key = "#roomId")
Copy link
Collaborator

Choose a reason for hiding this comment

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

이부분 저랑 좀 맞춰보죠!


public record RouteResponse(
String name
//TODO: String color
Copy link
Collaborator

Choose a reason for hiding this comment

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

호선색깔 필요없다고 하셨습니다 (디자이너 피셜)

@minseokey
Copy link
Collaborator

LGTM~~!

@@ -193,22 +187,10 @@ private double calculateDistance(Point p1, Station station) {
return Math.sqrt(Math.pow(lat2 - lat1, 2) + Math.pow(lon2 - lon1, 2));
}

@Override
Copy link
Collaborator

Choose a reason for hiding this comment

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

좋습니다. 삭제로직은 급한거 아니니까 런칭 이후로 보시죠!

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅎㅎㅎ

@minseokey
Copy link
Collaborator

확인 했습니다!

Copy link
Collaborator

@yunyoung1819 yunyoung1819 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 👍

@linirini linirini merged commit bb3a9d8 into develop Mar 29, 2025
2 checks passed
@linirini linirini deleted the feature/vote branch March 29, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature new feature 🥇 Urgency 1 긴급도 높음
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] 투표 후보 목록 조회 API
3 participants