-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: post recommendation API #508
Conversation
siyeonSon
commented
Sep 11, 2024
- Resolve : [Api] add post recommendation API #507
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.
고생 많으셨습니다.
기존에 코드 많이 더러웠는데 깔끔하게 정리해주셨네요
감사합니다 😄 👍🏻 💯
...rop-api/src/main/java/com/depromeet/domains/recommend/dto/response/MusicInfoResponseDto.java
Outdated
Show resolved
Hide resolved
...etdrop-api/src/main/java/com/depromeet/domains/recommend/service/SearchRecommendService.java
Show resolved
Hide resolved
backend/streetdrop-api/src/main/java/com/depromeet/common/error/dto/CommonErrorCode.java
Show resolved
Hide resolved
...end/streetdrop-api/src/main/java/com/depromeet/domains/recommend/constant/RecommendType.java
Outdated
Show resolved
Hide resolved
...-api/src/main/java/com/depromeet/domains/recommend/controller/SearchRecommendController.java
Show resolved
Hide resolved
...etdrop-api/src/main/java/com/depromeet/domains/recommend/service/SearchRecommendService.java
Outdated
Show resolved
Hide resolved
...treetdrop-api/src/main/java/com/depromeet/external/applemusic/service/AppleMusicService.java
Show resolved
Hide resolved
바로 머지해주시면 오늘 테섭 배포해두겠습니다 |
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.
개발하면서 고민했던 점들이에요 💭
@GetMapping(value = "${apple.music.api.get-catalog-charts-url}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
AppleMusicSongChartResponseDto getSongCharts( | ||
@RequestParam("types") String types, | ||
@RequestParam("limit") int limit | ||
); | ||
|
||
@GetMapping(value = "${apple.music.api.get-catalog-charts-url}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
AppleMusicAlbumChartResponseDto getAlbumCharts( | ||
@RequestParam("types") String types, | ||
@RequestParam("limit") int limit | ||
); |
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.
[추상화에 대한 고민]
두 로직은 동일한 AppleMusicAPI를 활용하지만 파라미터 값만 다르게 적용했습니다.
- AppleMusicAPI: https://developer.apple.com/documentation/applemusicapi/get_catalog_charts
- 인기 음악: https://api.music.apple.com/v1/catalog/kr/charts?types=songs&limit=30
- 인기 앨범: https://api.music.apple.com/v1/catalog/kr/charts?types=albums&limit=10
그런데 서로 API 응답 값이 달라서 서로 다른 DTO를 사용합니다.
같은 API를 활용한 코드라서 하나로 묶고, DTO를 최대한 재활용 하고 싶은데 적당한 방법이 떠오르지 않아서 고민이에요 🤔
|
||
import java.util.List; | ||
|
||
public class AppleMusicSongChartResponseDto { |
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.
[DTO 객체 생성 비용 최적화 고민]
Apple Music API 주소는 다음과 같습니다.
https://api.music.apple.com/v1/catalog/kr/charts?types=songs&limit=30
호출할 때마다 객체를 최소 30+N개 만들어야 해요. M번 호출되면 M*(30+N)개라서 메모리 효율적이지 않다고 생각합니다.
이미 만든 객체를 재활용 할 수 없을까요? DTO 객체 생성 비용 최적화에 대해서 고민이에요 🤔
@Configuration | ||
public class AppleMusicAuthConfig implements RequestInterceptor { | ||
|
||
private static final String HEADER_NAME ="Authorization"; | ||
private static final String AUTH_TYPE = "Bearer"; | ||
|
||
@Value("${apple.music.api.key}") | ||
private String value; | ||
|
||
@Override | ||
public void apply(RequestTemplate requestTemplate) { | ||
requestTemplate.header(HEADER_NAME, AUTH_TYPE + " " + value); | ||
} | ||
|
||
} |
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.
Apple Music API와 통신하는 코드가 서로 통일되어 있지 않아요.
음악 검색 Apple Music API 통신은 Web Client로 작성되어 있고, 검색어 추천 Apple Music API 통신은 Feign Client로 작성했습니다.
이로 인해 설정 부분에도 차이가 존재해요. 현재 코드에 작성된 AppleMusicAuthConfig와 기존 코드의 AppleMusicConfig를 비교해보시면 좋을 것 같아요.
이전에 작성된 코드와 싱크를 맞추는 작업이 필요해요. 다만 AppleMusic API 호출 부분, 설정 부분, DTO 등 작업량이 많아질 것이라 생각해요. 별도의 브랜치에 작업하여 반영하겠습니다.
참고
Feign Client를 사용한 이유: #472 (comment)