Skip to content

Commit

Permalink
#141 #156 #158 feat: 분리되어 있던 음악 검색 로직 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantchoi committed Dec 6, 2022
1 parent 02aef9c commit c55eef5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Segno/Segno/Domain/UseCase/SearchMusicUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ final class SearchMusicUseCaseImpl: SearchMusicUseCase {

init(musicRepository: MusicRepository = MusicRepositoryImpl()) {
self.musicRepository = musicRepository

subscribeShazamResult()
}

func startSearching() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ final class DiaryEditViewController: UIViewController {
}
}

// 샤잠킷 로직 부분 - 추후 뜯어서 옮길 계획입니다.
// 샤잠킷 로직 부분
extension DiaryEditViewController {
private func bindLabel() {
shazamSession.isSearching
viewModel.isSearching
.observe(on: MainScheduler.instance)
.subscribe(onNext: { searchState in
switch searchState {
Expand All @@ -307,30 +307,26 @@ extension DiaryEditViewController {
}

private func bindSearchResult() {
shazamSession.result
viewModel.musicInfo
.observe(on: MainScheduler.instance)
.subscribe(onNext: { result in
switch result {
case .success(let song):
let title = song.title
let artist = song.artist

let musicInfo = MusicInfo(shazamSong: song) // 뷰모델에서 이 작업을 할 때, 향후 사용될 엔티티
debugPrint(musicInfo)
debugPrint(song)

DispatchQueue.main.async {
self.musicInfoLabel.text = "\(artist) - \(title)"
}
self.musicInfoLabel.text = "\(artist) - \(title)"
case .failure(_):
DispatchQueue.main.async {
self.musicInfoLabel.text = "음악을 찾지 못했어요."
}
self.musicInfoLabel.text = "음악을 찾지 못했어요."
}
})
.disposed(by: disposeBag)
}

private func searchTapped() {
shazamSession.toggleSearch() // 지워질 예정
viewModel.toggleSearchMusic()
}
}

Expand Down
2 changes: 2 additions & 0 deletions Segno/Segno/Presentation/ViewModel/DiaryEditViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class DiaryEditViewModel {
self.searchMusicUseCase = searchMusicUseCase

subscribeSearchingStatus()
subscribeSearchResult()
}

func addTags() {
Expand Down Expand Up @@ -58,6 +59,7 @@ final class DiaryEditViewModel {
func subscribeSearchResult() {
searchMusicUseCase.musicInfoResult
.subscribe(onNext: {
self.toggleSearchMusic()
self.musicInfo.onNext($0)
})
.disposed(by: disposeBag)
Expand Down

0 comments on commit c55eef5

Please sign in to comment.