Skip to content

Commit

Permalink
#170 feat: locationSubject, musicInfo를 BehaviorSubject로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEYOONJONG committed Dec 8, 2022
1 parent e9b475b commit b8ffcc1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Segno/Segno/Domain/UseCase/DiaryEditUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class DiaryEditUseCaseImpl: DiaryEditUseCase {
}

func postDiary(_ diary: DiaryDetail, image: Data) -> Single<DiaryDetail> {
repository.postDiary(diary, image: image).map { dto in
return repository.postDiary(diary, image: image).map { dto in
DiaryDetail(
identifier: dto.id,
title: dto.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ extension DiaryEditViewController {
self.musicInfoLabel.text = "\(artist) - \(title)"
case .failure(_):
self.musicInfoLabel.text = Metric.musicNotFound
default:
break
}
})
.disposed(by: disposeBag)
Expand Down
18 changes: 15 additions & 3 deletions Segno/Segno/Presentation/ViewModel/DiaryEditViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import RxSwift

final class DiaryEditViewModel {
var locationSubject = PublishSubject<Location>()
var locationSubject = BehaviorSubject<Location?>(value: nil)
var addressSubject = PublishSubject<String>()

private let disposeBag = DisposeBag()
Expand All @@ -24,7 +24,7 @@ final class DiaryEditViewModel {

var isSearching = BehaviorSubject(value: false)
var isReceivingLocation = BehaviorSubject(value: false)
var musicInfo = PublishSubject<MusicInfoResult>()
var musicInfo = BehaviorSubject<MusicInfoResult?>(value: nil)

init(diaryDetailUseCase: DiaryDetailUseCase = DiaryDetailUseCaseImpl(),
searchMusicUseCase: SearchMusicUseCase = SearchMusicUseCaseImpl(),
Expand Down Expand Up @@ -100,8 +100,20 @@ final class DiaryEditViewModel {
.subscribe(onSuccess: { [weak self] imageInfo in
guard let imageName = imageInfo.filename else { return }
debugPrint(imageName)

guard let location = try? self?.locationSubject.value() else { return }
guard let musicInfoResult = try? self?.musicInfo.value() else { return }
switch musicInfoResult {
case .success(let musicInfo):
debugPrint(musicInfo)
self?.saveDiary(title: title, body: body, tags: tags, imageName: imageName, musicInfo: musicInfo, location: location)
case .failure(let error):
debugPrint(error)
}
})
.disposed(by: disposeBag)
}

func saveDiary(title: String, body: String, tags: [String], imageName: String, musicInfo: MusicInfo, location: Location) {
debugPrint("저장할 프로퍼티 : \(title), \(body), \(tags), \(imageName), \(musicInfo), \(location)")
}
}

0 comments on commit b8ffcc1

Please sign in to comment.