Skip to content

Commit fecdfdc

Browse files
committed
feat: 아티스트 상세 - isLiked 추가
1 parent 6199a34 commit fecdfdc

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/artists/controller/ArtistsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public RsData<Slice<ArtistListResponse>> list(
8282
public RsData<ArtistDetailResponse> artist(
8383
@PathVariable Long id
8484
) {
85-
return RsData.success("아티스트 상세 조회를 성공했습니다.", artistService.getArtistDetail(id));
85+
User user = rq.getUserOrNull(); // 로그인하지 않은 경우 null
86+
return RsData.success("아티스트 상세 조회를 성공했습니다.", artistService.getArtistDetail(id, user));
8687
}
8788

8889
@Operation(summary = "아티스트 정보 수정", description = "아티스트 정보를 수정합니다.")

src/main/java/com/back/web7_9_codecrete_be/domain/artists/dto/response/ArtistDetailResponse.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public record ArtistDetailResponse(
3737
List<TopTrackResponse> topTracks,
3838

3939
@Schema(description = "아티스트와 관련 있는 다른 아티스트 목록입니다.")
40-
List<RelatedArtistResponse> relatedArtists
40+
List<RelatedArtistResponse> relatedArtists,
41+
42+
@Schema(description = "로그인한 유저의 좋아요 여부입니다. 비회원인 경우 false입니다.")
43+
Boolean isLiked
4144
) {
4245
}

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/ArtistEnrichService.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected void enrichSingleArtist(Artist artist) {
189189
// 기존 artistType이 있으면 유지, 없으면 가져온 값 사용
190190
String artistTypeStr = result.artistType != null ? result.artistType :
191191
(artist.getArtistType() != null ? artist.getArtistType().name() : null);
192-
192+
193193
// String을 ArtistType enum으로 변환
194194
ArtistType artistType;
195195
if (artistTypeStr != null) {
@@ -329,8 +329,8 @@ private EnrichResult enrichArtist(Artist artist) {
329329
artist.getMusicBrainzId(), artistGroup);
330330
}
331331
}
332-
}
333-
332+
}
333+
334334
if (artistType != null || artistGroup != null) {
335335
log.info("✅ -1단계 성공 (MBID 직접 검색): artistId={}, mbid={}, qid={}, type={}, group={}",
336336
artist.getId(), artist.getMusicBrainzId(), mbidWikidataQid, artistType, artistGroup);
@@ -459,13 +459,13 @@ private EnrichResult enrichArtist(Artist artist) {
459459
artist.getSpotifyArtistId(), artistGroup, groups);
460460
} else {
461461
// SPARQL로 못 찾으면 기존 방식 시도
462-
artistGroup = resolveGroupNameFromWikidata(entity);
463-
if (artistGroup != null) {
464-
source += "Wikidata ";
462+
artistGroup = resolveGroupNameFromWikidata(entity);
463+
if (artistGroup != null) {
464+
source += "Wikidata ";
465465
log.debug("소속 그룹 추출 성공 (Wikidata): spotifyId={}, group={}",
466466
artist.getSpotifyArtistId(), artistGroup);
467-
}
468-
}
467+
}
468+
}
469469
}
470470
// Wikidata에서 못 찾으면 MusicBrainz에서 시도
471471
if (artistGroup == null && mbInfo.getArtistGroup() != null &&
@@ -499,9 +499,9 @@ private EnrichResult enrichArtist(Artist artist) {
499499

500500
// MBID 상세 조회
501501
Optional<MusicBrainzClient.ArtistInfo> mbInfoOpt = musicBrainzClient.getArtistByMbid(mbid);
502-
if (mbInfoOpt.isPresent()) {
503-
MusicBrainzClient.ArtistInfo mbInfo = mbInfoOpt.get();
504-
502+
if (mbInfoOpt.isPresent()) {
503+
MusicBrainzClient.ArtistInfo mbInfo = mbInfoOpt.get();
504+
505505
// Type 덮어쓰기 정책: 합의(consensus) 방식
506506
if (mbInfo.getArtistType() != null && !mbInfo.getArtistType().isBlank() &&
507507
"spotify-url".equals(mbidSource)) {
@@ -517,7 +517,7 @@ private EnrichResult enrichArtist(Artist artist) {
517517
} else if (wdType == null) {
518518
// Wikidata에서 type을 못 찾았으면 MusicBrainz 사용
519519
artistType = mbType;
520-
source += "MusicBrainz ";
520+
source += "MusicBrainz ";
521521
log.debug("artistType 추출 성공 (MusicBrainz, Wikidata type 없음): spotifyId={}, mbid={}, type={}",
522522
artist.getSpotifyArtistId(), mbid, mbType);
523523
} else {
@@ -530,8 +530,8 @@ private EnrichResult enrichArtist(Artist artist) {
530530
// SOLO일 때만 group 추출 (MusicBrainz만 사용, Wikidata는 이미 시도했거나 없음)
531531
if ("SOLO".equals(artistType) && artistGroup == null) {
532532
if (mbInfo.getArtistGroup() != null && !mbInfo.getArtistGroup().isBlank()) {
533-
artistGroup = mbInfo.getArtistGroup();
534-
source += "MusicBrainz ";
533+
artistGroup = mbInfo.getArtistGroup();
534+
source += "MusicBrainz ";
535535
log.debug("소속 그룹 추출 성공 (MusicBrainz): spotifyId={}, mbid={}, group={}",
536536
artist.getSpotifyArtistId(), mbid, artistGroup);
537537
}
@@ -619,7 +619,7 @@ private EnrichResult enrichArtist(Artist artist) {
619619
}
620620

621621
return new EnrichResult(nameKo, artistGroup, artistType, source.trim());
622-
}
622+
}
623623

624624
// Wikidata 엔티티에서 정보 추출 (한국이름-활동명, 소속그룹, 솔로/그룹)
625625
private EnrichResult extractInfoFromWikidata(JsonNode entity) {

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/ArtistService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Slice<ArtistListResponse> listArtist(Pageable pageable, User user, Artist
9898
}
9999

100100
@Transactional(readOnly = true)
101-
public ArtistDetailResponse getArtistDetail(Long artistId) {
101+
public ArtistDetailResponse getArtistDetail(Long artistId, User user) {
102102
Artist artist = artistRepository.findById(artistId)
103103
.orElseThrow(() -> new BusinessException(ArtistErrorCode.ARTIST_NOT_FOUND));
104104

@@ -108,13 +108,20 @@ public ArtistDetailResponse getArtistDetail(Long artistId) {
108108

109109
long likeCount = artistLikeRepository.countByArtistId(artistId);
110110

111+
// 로그인한 유저의 좋아요 여부 확인
112+
boolean isLiked = false;
113+
if (user != null) {
114+
isLiked = artistLikeRepository.existsByArtistAndUser(artist, user);
115+
}
116+
111117
return spotifyService.getArtistDetail(
112118
artist.getSpotifyArtistId(),
113119
artist.getArtistGroup(),
114120
artist.getArtistType(),
115121
likeCount,
116122
artist.getId(),
117-
artist.getGenre() != null ? artist.getGenre().getId() : null
123+
artist.getGenre() != null ? artist.getGenre().getId() : null,
124+
isLiked
118125
);
119126
}
120127

src/main/java/com/back/web7_9_codecrete_be/domain/artists/service/SpotifyService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public ArtistDetailResponse getArtistDetail(
190190
ArtistType artistType,
191191
long likeCount,
192192
long artistId,
193-
Long genreId
193+
Long genreId,
194+
boolean isLiked
194195
) {
195196
try {
196197
SpotifyApi api = spotifyClient.getAuthorizedApi();
@@ -219,7 +220,8 @@ public ArtistDetailResponse getArtistDetail(
219220
"", // 설명
220221
toAlbumResponses(albums != null ? albums.getItems() : null, spotifyArtistId),
221222
toTopTrackResponses(topTracks),
222-
relatedResponses
223+
relatedResponses,
224+
isLiked
223225
);
224226
} catch (Exception e) {
225227
log.error("Spotify 상세 조회 실패: artistId={}", spotifyArtistId, e);

0 commit comments

Comments
 (0)