Skip to content

Commit

Permalink
Merge pull request #104 from yangsubinn/fix/#100
Browse files Browse the repository at this point in the history
[Fix] #100 - 스탬프 등록, 삭제, 수정 실패시 에러 처리
  • Loading branch information
yangsubinn authored Jan 11, 2023
2 parents b725437 + 9c89162 commit fc30863
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extension DefaultListDetailUseCase: ListDetailUseCase {
public func postStamp(missionId: Int, stampData: ListDetailRequestModel) {
let data = [stampData.imgURL as Any, stampData.content] as [Any]
repository.postStamp(missionId: missionId, stampData: data)
.replaceError(with: ListDetailModel(image: "", content: "", date: "", stampId: 0))
.sink { event in
print("completion: \(event)")
} receiveValue: { model in
Expand All @@ -63,13 +64,15 @@ extension DefaultListDetailUseCase: ListDetailUseCase {
public func putStamp(missionId: Int, stampData: ListDetailRequestModel) {
let data = [stampData.imgURL as Any, stampData.content] as [Any]
repository.putStamp(missionId: missionId, stampData: data)
.replaceError(with: -1)
.sink { result in
self.editSuccess.send(true)
self.editSuccess.send(result == -1 ? false: true)
}.store(in: self.cancelBag)
}

public func deleteStamp(stampId: Int) {
repository.deleteStamp(stampId: stampId)
.replaceError(with: false)
.sink { success in
self.deleteSuccess.send(success)
}.store(in: self.cancelBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,30 @@ extension ListDetailVC {
output.$listDetailModel
.compactMap { $0 }
.sink { model in
self.setData(model)
if self.sceneType == .none {
self.presentCompletedVC(level: self.starLevel)
if model.image.isEmpty {
let networkAlert = self.factory.makeNetworkAlertVC()
self.present(networkAlert, animated: true) {
self.backgroundDimmerView.removeFromSuperview()
}
} else {
self.setData(model)
if self.sceneType == .none {
self.presentCompletedVC(level: self.starLevel)
}
self.sceneType = .completed
self.reloadData(self.sceneType)
}
self.sceneType = .completed
self.reloadData(self.sceneType)
}.store(in: self.cancelBag)

output.editSuccessed
.sink { successed in
self.reloadData(.completed)
self.showToast(message: I18N.ListDetail.editCompletedToast)
if successed {
self.reloadData(.completed)
self.showToast(message: I18N.ListDetail.editCompletedToast)
} else {
let networkAlert = self.factory.makeNetworkAlertVC()
self.present(networkAlert, animated: true)
}
}.store(in: self.cancelBag)

output.showDeleteAlert
Expand All @@ -191,7 +203,8 @@ extension ListDetailVC {
if success {
self.navigationController?.popViewController(animated: true)
} else {
self.makeAlert(title: I18N.Default.error, message: I18N.Default.networkError)
let networkAlert = self.factory.makeNetworkAlertVC()
self.present(networkAlert, animated: true)
}
}.store(in: self.cancelBag)
}
Expand Down

0 comments on commit fc30863

Please sign in to comment.