Skip to content

Commit

Permalink
feat: 랜덤 뮤직 덱을 프레젠테이션 영역에서 사용할 수 있도록 수정하기 (boostcampwm-2024#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
windowcow committed Nov 14, 2024
1 parent 3c26852 commit ca34f9b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Molio/Source/Domain/Entity/MusicDeck/RandomMusicDeck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import Combine
// MARK: 프로토콜 요구사항

extension RandomMusicDeck: MusicDeck {
var currentMusicTrackModelPublisher: AnyPublisher<RandomMusic?, Never> {
return musicPublisher(at: 0)
}

func musicPublisher(at index: Int) -> AnyPublisher<RandomMusic?, Never> {
randomMusics
.compactMap { randomMusics in
// 인덱스 범위를 벗어나지 않는지 체크하는 로직이다.
guard randomMusics.count > index else { return nil }

return randomMusics[index]
}
.removeDuplicates { $0?.isrc == $1?.isrc }
.eraseToAnyPublisher()
var nextMusicTrackModelPublisher: AnyPublisher<RandomMusic?, Never> {
return musicPublisher(at: 1)
}

func likeCurrentMusic() {
Expand Down Expand Up @@ -97,7 +92,6 @@ final class RandomMusicDeck {
}
}


private func loadRandomMusic() {
let genres = self.musicFilter.value?.genres ?? []

Expand All @@ -110,11 +104,23 @@ final class RandomMusicDeck {
}
}


private func removeCurrentMusic() {
guard !randomMusics.value.isEmpty else { return }

randomMusics.value.remove(at: 0)
}


private func musicPublisher(at index: Int) -> AnyPublisher<RandomMusic?, Never> {
randomMusics
.compactMap { randomMusics in
// 인덱스 범위를 벗어나지 않는지 체크하는 로직이다.
guard randomMusics.count > index else { return nil }

return randomMusics[index]
}
.removeDuplicates { $0?.isrc == $1?.isrc }
.eraseToAnyPublisher()
}
}

0 comments on commit ca34f9b

Please sign in to comment.