Skip to content

Commit

Permalink
fix: 스포티파이 플리 이미지가 없는 경우 예외처리(#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Aug 26, 2024
1 parent ec28593 commit 065a7fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/main/java/play/pluv/oauth/spotify/dto/SpotifyMusic.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package play.pluv.oauth.spotify.dto;

import static play.pluv.oauth.spotify.dto.ThumbNailResponse.IMAGE_NULL_RESPONSE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.util.List;
import java.util.Optional;
import play.pluv.music.domain.DestinationMusic;
import play.pluv.music.domain.MusicId;

Expand All @@ -28,8 +30,9 @@ public DestinationMusic toDestinationMusic() {
}

public String getImageUrl() {
//TODO: 추후 로직 수정하기 images가 nullable함
return album.images().get(0).url();
return Optional.ofNullable(album.images())
.map(images -> images.get(0).url())
.orElse(IMAGE_NULL_RESPONSE);
}

public List<String> getArtistNames() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package play.pluv.oauth.spotify.dto;

import static play.pluv.oauth.spotify.dto.ThumbNailResponse.IMAGE_NULL_RESPONSE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;

import java.util.List;
import java.util.Optional;
import play.pluv.playlist.domain.PlayList;
import play.pluv.playlist.domain.PlayListId;

Expand All @@ -18,10 +20,13 @@ public record SpotifyPlayListResponse(
) {

public PlayList toPlayList() {
final String thumbNailUrl = Optional.ofNullable(images())
.map(images -> images.get(0).url())
.orElse(IMAGE_NULL_RESPONSE);

return PlayList.builder()
.playListId(new PlayListId(id, SPOTIFY))
//TODO: 추후 로직 수정하기 images가 nullable함
.thumbNailUrl(images.get(0).url())
.thumbNailUrl(thumbNailUrl)
.songCount(tracks.total())
.name(name)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public record ThumbNailResponse(
String url
) {

static final String IMAGE_NULL_RESPONSE = "";
}

0 comments on commit 065a7fa

Please sign in to comment.