From 70e439a85b211cfbdd965116505bc2b467b3ce28 Mon Sep 17 00:00:00 2001 From: siyeonSon Date: Mon, 23 Sep 2024 11:59:11 +0900 Subject: [PATCH] :recycle: refactor(api): refactor if-else -> switch case --- .../applemusic/service/AppleMusicService.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/streetdrop-api/src/main/java/com/depromeet/external/applemusic/service/AppleMusicService.java b/backend/streetdrop-api/src/main/java/com/depromeet/external/applemusic/service/AppleMusicService.java index 332a354a..99c91788 100644 --- a/backend/streetdrop-api/src/main/java/com/depromeet/external/applemusic/service/AppleMusicService.java +++ b/backend/streetdrop-api/src/main/java/com/depromeet/external/applemusic/service/AppleMusicService.java @@ -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); + }; } }