Skip to content

Commit

Permalink
♻️ refactor(api): refactor if-else -> switch case
Browse files Browse the repository at this point in the history
  • Loading branch information
siyeonSon committed Sep 23, 2024
1 parent 4836bd6 commit 70e439a
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class AppleMusicService {
private final AppleMusicFeignClient appleMusicFeignClient;

public RecommendCategoryDto getCategoryChart(RecommendType recommendType) {
if (recommendType == RecommendType.POPULAR_CHART_SONG) {
var response = appleMusicFeignClient.getSongCharts("songs", recommendType.getLimit());
return RecommendCategoryDto.ofAppleMusicResponseDto(recommendType, response);
}
else if (recommendType == RecommendType.CHART_ARTIST) {
var response = appleMusicFeignClient.getAlbumCharts("albums", recommendType.getLimit());
return RecommendCategoryDto.ofAppleMusicResponseDto(recommendType, response);
}
else {
throw new BusinessException(CommonErrorCode.UNSUPPORTED_TYPE);
}
return switch (recommendType) {
case POPULAR_CHART_SONG -> {
var response = appleMusicFeignClient.getSongCharts("songs", recommendType.getLimit());
yield RecommendCategoryDto.ofAppleMusicResponseDto(recommendType, response);
}
case CHART_ARTIST -> {
var response = appleMusicFeignClient.getAlbumCharts("albums", recommendType.getLimit());
yield RecommendCategoryDto.ofAppleMusicResponseDto(recommendType, response);
}
default -> throw new BusinessException(CommonErrorCode.UNSUPPORTED_TYPE);
};
}

}

0 comments on commit 70e439a

Please sign in to comment.