Skip to content

Commit

Permalink
merge: 피드 아티스트 중복 제거
Browse files Browse the repository at this point in the history
Feature/#122 피드 아티스트 중복 제거
  • Loading branch information
hong-sile authored Aug 26, 2024
2 parents 4902724 + 6db987c commit 02610a7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/main/java/play/pluv/progress/domain/MusicTransferContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package play.pluv.progress.domain;

import static java.util.stream.Collectors.joining;
import static java.util.Comparator.comparing;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Getter;
import play.pluv.feed.domain.Feed;
Expand Down Expand Up @@ -67,12 +73,19 @@ public Feed createFeed(final String creatorName) {
.creatorName(creatorName)
.artistNames(artistNames)
.thumbNailUrl(thumbNailUrl)
.songCount(transferredMusics.size())
.build();
}

private String extractArtistNames(final List<TransferredMusicInContext> transferredMusics) {
return transferredMusics.stream()
final Map<String, Long> artistCountMap = transferredMusics.stream()
.map(TransferredMusicInContext::getArtistNames)
.collect(joining(","));
.filter(artistNames -> !artistNames.isBlank())
.map(artistNames -> artistNames.split(","))
.flatMap(Arrays::stream)
.collect(groupingBy(identity(), counting()));
return artistCountMap.keySet().stream()
.sorted(comparing(artistCountMap::get).reversed())
.collect(Collectors.joining(","));
}
}
6 changes: 3 additions & 3 deletions src/test/java/play/pluv/fixture/TransferContextFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static MusicTransferContext musicTransferContext(
return List.of(
new TransferredMusicInContext(new HistoryMusicId(APPLE, "a"), "사랑하게 될거야", "한로로", "imageUrl",
"isrc"),
new TransferredMusicInContext(new HistoryMusicId(APPLE, "b"), "자처", "한로로", "imageUrl",
new TransferredMusicInContext(new HistoryMusicId(APPLE, "b"), "자처", "한로로,창모", "imageUrl",
"abcd"),
new TransferredMusicInContext(new HistoryMusicId(APPLE, "c"), "ㅈㅣㅂ", "한로로", "imageUrl",
new TransferredMusicInContext(new HistoryMusicId(APPLE, "c"), "ㅈㅣㅂ", "아이유", "imageUrl",
null),
new TransferredMusicInContext(new HistoryMusicId(APPLE, "d"), "금붕어", "한로로", "imageUrl",
new TransferredMusicInContext(new HistoryMusicId(APPLE, "d"), "금붕어", "한로로,아이유", "imageUrl",
null)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package play.pluv.progress.domain;

import static org.assertj.core.api.Assertions.assertThat;
import static play.pluv.fixture.TransferContextFixture.이전한_음악_목록;
import static play.pluv.playlist.domain.MusicStreaming.APPLE;
import static play.pluv.playlist.domain.MusicStreaming.SPOTIFY;
import static play.pluv.playlist.domain.MusicStreaming.YOUTUBE;

import java.util.List;
import org.junit.jupiter.api.Test;
import play.pluv.history.domain.HistoryMusicId;

class MusicTransferContextTest {

@Test
void 피드를_생성할수_있다() {
final List<TransferredMusicInContext> 이전한_음악_목록 = 이전한_음악_목록();
final MusicTransferContext context = new MusicTransferContext(
10L, List.of(), 10, "imageUrl", "이전 중", APPLE, SPOTIFY
);
context.addTransferredMusics(이전한_음악_목록);

final String actual = context.createFeed("creator").getArtistNames();
final String expected = "한로로,아이유,창모";

assertThat(actual)
.isEqualTo(expected);
}

@Test
void 피드를_생성할떄_가수이름이없는경우() {
final List<TransferredMusicInContext> 이전한_음악_목록 = List.of(
new TransferredMusicInContext(new HistoryMusicId(YOUTUBE, "c"), "ㅈㅣㅂ", "", "imageUrl",
null),
new TransferredMusicInContext(new HistoryMusicId(YOUTUBE, "d"), "금붕어", "", "imageUrl",
null)
);

final MusicTransferContext context = new MusicTransferContext(
10L, List.of(), 10, "imageUrl", "이전 중", APPLE, SPOTIFY
);
context.addTransferredMusics(이전한_음악_목록);

final String actual = context.createFeed("creator").getArtistNames();

assertThat(actual)
.isBlank();
}
}

0 comments on commit 02610a7

Please sign in to comment.