Skip to content

Commit

Permalink
feat [#216] 하나의 아티스트 아이디 값이 여러 개의 객체에 매핑될 수 있도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1hyun committed Jan 24, 2025
1 parent 88b6937 commit 2dccd05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.sopt.confeti.annotation.Resolver;
import org.sopt.confeti.domain.artistfavorite.ArtistFavorite;
import org.sopt.confeti.domain.concert.Concert;
import org.sopt.confeti.domain.festival.Festival;
import org.sopt.confeti.domain.festivaldate.FestivalDate;
import org.sopt.confeti.global.exception.ConfetiException;
import org.sopt.confeti.global.message.ErrorMessage;
import org.sopt.confeti.global.util.IntegrateFunction;

@Resolver
Expand Down Expand Up @@ -39,7 +44,7 @@ public class ArtistResolver {
}};

private List<String> artistIds;
private HashMap<String, ConfetiArtist> artistMapper;
private HashMap<String, Queue<ConfetiArtist>> artistMapper;

private final SpotifyAPIHandler spotifyAPIHandler;

Expand Down Expand Up @@ -97,17 +102,14 @@ private void collectArtistFavorite(final Object target) {
ArtistFavorite artistFavorite = (ArtistFavorite) target;
ConfetiArtist confetiArtist = artistFavorite.getArtist();
artistIds.add(confetiArtist.getArtistId());
artistMapper.put(confetiArtist.getArtistId(), artistFavorite.getArtist());
addArtistToMapper(confetiArtist.getArtistId(), artistFavorite.getArtist());
}

private void collectConcert(final Object target) {
Concert concert = (Concert) target;
concert.getArtists().forEach(artist -> {
artistIds.add(artist.getArtist().getArtistId());
artistMapper.put(
artist.getArtist().getArtistId(),
artist.getArtist()
);
addArtistToMapper(artist.getArtist().getArtistId(), artist.getArtist());
});
}

Expand All @@ -119,7 +121,7 @@ private void collectFestival(final Object target) {
.flatMap(time -> time.getArtists().stream())
.forEach(artist -> {
artistIds.add(artist.getArtist().getArtistId());
artistMapper.put(artist.getArtist().getArtistId(), artist.getArtist());
addArtistToMapper(artist.getArtist().getArtistId(), artist.getArtist());
});
}

Expand All @@ -130,13 +132,18 @@ private void collectFestivalDate(final Object target) {
.flatMap(time -> time.getArtists().stream())
.forEach(artist -> {
artistIds.add(artist.getArtist().getArtistId());
artistMapper.put(artist.getArtist().getArtistId(), artist.getArtist());
addArtistToMapper(artist.getArtist().getArtistId(), artist.getArtist());
});
}

private void injection(final List<ConfetiArtist> confetiArtists) {
confetiArtists.forEach((confetiArtist -> {
ConfetiArtist mappedConfetiArtist = artistMapper.get(confetiArtist.getArtistId());
ConfetiArtist mappedConfetiArtist = artistMapper.get(confetiArtist.getArtistId()).poll();

if (mappedConfetiArtist == null) {
throw new ConfetiException(ErrorMessage.INTERNAL_SERVER_ERROR);
}

mappedConfetiArtist.setName(confetiArtist.getName());
mappedConfetiArtist.setProfileUrl(confetiArtist.getProfileUrl());
}));
Expand All @@ -145,4 +152,16 @@ private void injection(final List<ConfetiArtist> confetiArtists) {
private List<ConfetiArtist> searchByArtistIds(final List<String> artistIds) {
return spotifyAPIHandler.findArtistsByArtistIdsEntry(artistIds);
}

private void addArtistToMapper(final String artistId, final ConfetiArtist artist) {
if (!artistMapper.containsKey(artistId)) {
createQueueToMapper(artistId);
}

artistMapper.get(artistId).add(artist);
}

private void createQueueToMapper(final String artistId) {
artistMapper.put(artistId, new LinkedList<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public List<ConfetiArtist> findArtistsByArtistIdsEntry(final List<String> artist
}

public List<ConfetiArtist> findArtistsByArtistIds(final List<String> artistIds) {
artistIds.forEach(artistId -> System.out.print(artistId + ","));
System.out.println();
if (artistIds.isEmpty()) {
return Collections.emptyList();
}
Expand Down

0 comments on commit 2dccd05

Please sign in to comment.