From 81f9369ca70df2e246355255c7b39323cd4900a7 Mon Sep 17 00:00:00 2001 From: mmaybei Date: Fri, 19 Jul 2024 08:12:59 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat/#241=20=EC=A4=80=EB=B9=84/=EC=9D=B4?= =?UTF-8?q?=EB=8F=99/=EB=8F=84=EC=B0=A9=20=EC=8B=9C=EA=B0=84=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/ServiceType/HomeServiceType.swift | 34 +++++++++ .../ViewController/HomeViewController.swift | 73 +++++++++++-------- .../Source/Home/ViewModel/HomeViewModel.swift | 57 ++++++++++++++- .../ViewModel/SetReadyInfoViewModel.swift | 1 - 4 files changed, 130 insertions(+), 35 deletions(-) diff --git a/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift b/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift index d7a4f77a..17a63586 100644 --- a/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift +++ b/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift @@ -13,9 +13,31 @@ protocol HomeServiceType { func fetchLoginUser() async throws -> ResponseBodyDTO? func fetchNearestPromise() async throws -> ResponseBodyDTO? func fetchUpcomingPromise() async throws -> ResponseBodyDTO? + + func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? + func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO? + func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO? } extension HomeService: HomeServiceType { + func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return try await request( + with: .updatePreparationStatus(promiseID: promiseID) + ) + } + + func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return try await request( + with: .updateDepartureStatus(promiseID: promiseID) + ) + } + + func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return try await request( + with: .updateArrivalStatus(promiseID: promiseID) + ) + } + func fetchLoginUser() async throws -> ResponseBodyDTO? { return try await request(with: .fetchLoginUser) } @@ -30,6 +52,18 @@ extension HomeService: HomeServiceType { } final class MockHomeService: HomeServiceType { + func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return nil + } + + func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return nil + } + + func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return nil + } + func fetchLoginUser() async throws -> ResponseBodyDTO? { let mockData = ResponseBodyDTO( success: true, diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index 97231eb7..1fce438e 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -48,8 +48,6 @@ class HomeViewController: BaseViewController { view.backgroundColor = .maincolor register() - updateUI() - updateUserInfo() updateNearestPromise() updateUpcomingPromise() @@ -57,6 +55,8 @@ class HomeViewController: BaseViewController { viewModel.requestLoginUser() viewModel.requestNearestPromise() viewModel.requestUpcomingPromise() + + bindViewModel() } override func viewWillAppear(_ animated: Bool) { @@ -188,17 +188,43 @@ private extension HomeViewController { ) } - func updateUI() { - viewModel.currentState.bind { [weak self] state in - switch state { - case .prepare: - self?.setPrepareUI() - case .move: - self?.setMoveUI() - case .arrive: - self?.setArriveUI() - case .none: - break + func bindViewModel() { + viewModel.isPreapreSucceedToSave.bind { [weak self] _ in + if self?.viewModel.isPreapreSucceedToSave.value == true { + DispatchQueue.main.async { + self?.setPrepareUI() + self?.rootView.todayPromiseView.prepareTimeLabel.setText( + self?.viewModel.homePrepareTime ?? "", + style: .caption02, + color: .gray8 + ) + } + } + } + + viewModel.isMoveSucceedToSave.bind { [weak self] _ in + if self?.viewModel.isMoveSucceedToSave.value == true { + DispatchQueue.main.async { + self?.setMoveUI() + self?.rootView.todayPromiseView.moveTimeLabel.setText( + self?.viewModel.homeMoveTime ?? "", + style: .caption02, + color: .gray8 + ) + } + } + } + + viewModel.isArriveSucceedToSave.bind { [weak self] _ in + if self?.viewModel.isArriveSucceedToSave.value == true { + DispatchQueue.main.async { + self?.setArriveUI() + self?.rootView.todayPromiseView.arriveTimeLabel.setText( + self?.viewModel.homeArriveTime ?? "", + style: .caption02, + color: .gray8 + ) + } } } } @@ -402,31 +428,16 @@ private extension HomeViewController { @objc func prepareButtonDidTap(_ sender: UIButton) { - viewModel.updateState(newState: .prepare) - rootView.todayPromiseView.prepareTimeLabel.setText( - viewModel.homePrepareTime, - style: .caption02, - color: .gray8 - ) + viewModel.updatePrepareStatus() } @objc func moveButtonDidTap(_ sender: UIButton) { - viewModel.updateState(newState: .move) - rootView.todayPromiseView.moveTimeLabel.setText( - viewModel.homeMoveTime, - style: .caption02, - color: .gray8 - ) + viewModel.updateMoveStatus() } @objc func arriveButtonDidTap(_ sender: UIButton) { - viewModel.updateState(newState: .arrive) - rootView.todayPromiseView.arriveTimeLabel.setText( - viewModel.homeArriveTime, - style: .caption02, - color: .gray8 - ) + viewModel.updateArriveStatus() } } diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index aa791aba..5ddde271 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -17,7 +17,7 @@ enum ReadyState { } final class HomeViewModel { - var currentState = ObservablePattern(.none) + var promiseID = ObservablePattern?(nil) var loginUser = ObservablePattern?>(nil) var nearestPromise = ObservablePattern?>(nil) @@ -26,6 +26,10 @@ final class HomeViewModel { var levelName = ObservablePattern("") var levelCaption = ObservablePattern("") + var isPreapreSucceedToSave = ObservablePattern(false) + var isMoveSucceedToSave = ObservablePattern(false) + var isArriveSucceedToSave = ObservablePattern(false) + private let service: HomeServiceType init(service: HomeServiceType) { @@ -42,8 +46,7 @@ final class HomeViewModel { $0.pmSymbol = "PM" } - func updateState(newState: ReadyState) { - currentState.value = newState + private func updateState(newState: ReadyState) { let currentTimeString = dateFormatter.string(from: Date()) switch newState { case .prepare: @@ -84,6 +87,54 @@ final class HomeViewModel { } } + func updatePrepareStatus() { + Task { + do { + guard let responseBody = try await service.updatePreparationStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + else { + isPreapreSucceedToSave.value = false + return + } + isPreapreSucceedToSave.value = responseBody.success + updateState(newState: .prepare) + } catch { + print(">>> \(error.localizedDescription) : \(#function)") + } + } + } + + func updateMoveStatus() { + Task { + do { + guard let responseBody = try await service.updateDepartureStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + else { + isMoveSucceedToSave.value = false + return + } + isMoveSucceedToSave.value = responseBody.success + updateState(newState: .move) + } catch { + print(">>> \(error.localizedDescription) : \(#function)") + } + } + } + + func updateArriveStatus() { + Task { + do { + guard let responseBody = try await service.updateArrivalStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + else { + isArriveSucceedToSave.value = false + return + } + isArriveSucceedToSave.value = responseBody.success + updateState(newState: .arrive) + } catch { + print(">>> \(error.localizedDescription) : \(#function)") + } + } + } + func requestLoginUser() { Task { do { diff --git a/KkuMulKum/Source/Promise/ReadyStatus/ViewModel/SetReadyInfoViewModel.swift b/KkuMulKum/Source/Promise/ReadyStatus/ViewModel/SetReadyInfoViewModel.swift index d1fb8bcd..a18fae31 100644 --- a/KkuMulKum/Source/Promise/ReadyStatus/ViewModel/SetReadyInfoViewModel.swift +++ b/KkuMulKum/Source/Promise/ReadyStatus/ViewModel/SetReadyInfoViewModel.swift @@ -20,7 +20,6 @@ final class SetReadyInfoViewModel { let moveMinute = ObservablePattern("") let isSucceedToSave = ObservablePattern(false) - // TODO: 준비 및 이동 시간 분 단위로 계산 var readyTime: Int = 0 var moveTime: Int = 0 From 10202065aa2347b19c8828d3797f412f26d1f644 Mon Sep 17 00:00:00 2001 From: mmaybei Date: Fri, 19 Jul 2024 11:18:36 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat/#241=20=EB=82=B4=20=EC=A4=80=EB=B9=84?= =?UTF-8?q?=ED=98=84=ED=99=A9=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum/Application/SceneDelegate.swift | 2 +- .../Promises/MyReadyStatusResponseModel.swift | 10 +- .../Network/TargetType/HomeTargetType.swift | 5 +- .../Home/ServiceType/HomeServiceType.swift | 9 ++ .../ViewController/HomeViewController.swift | 124 ++++++++++++------ .../Source/Home/ViewModel/HomeViewModel.swift | 100 +++++++++----- 6 files changed, 172 insertions(+), 78 deletions(-) diff --git a/KkuMulKum/Application/SceneDelegate.swift b/KkuMulKum/Application/SceneDelegate.swift index 2af0dffc..bd9b87d7 100644 --- a/KkuMulKum/Application/SceneDelegate.swift +++ b/KkuMulKum/Application/SceneDelegate.swift @@ -36,7 +36,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { DispatchQueue.main.async { if success { print("Auto login successful, showing main screen") - self?.showLoginScreen() + self?.showMainScreen() } else { print("Auto login failed, showing login screen") self?.showLoginScreen() diff --git a/KkuMulKum/Network/DTO/Model/Promises/MyReadyStatusResponseModel.swift b/KkuMulKum/Network/DTO/Model/Promises/MyReadyStatusResponseModel.swift index da4a069e..bdeb6393 100644 --- a/KkuMulKum/Network/DTO/Model/Promises/MyReadyStatusResponseModel.swift +++ b/KkuMulKum/Network/DTO/Model/Promises/MyReadyStatusResponseModel.swift @@ -12,9 +12,9 @@ import Foundation struct MyReadyStatusModel: ResponseModelType { let promiseTime: String - let preparationTime: Int - let travelTime: Int - let preparationStartAt: String - let departureAt: String - let arrivalAt: String + let preparationTime: Int? + let travelTime: Int? + let preparationStartAt: String? + let departureAt: String? + let arrivalAt: String? } diff --git a/KkuMulKum/Network/TargetType/HomeTargetType.swift b/KkuMulKum/Network/TargetType/HomeTargetType.swift index 509f8dfc..0a6a4fc5 100644 --- a/KkuMulKum/Network/TargetType/HomeTargetType.swift +++ b/KkuMulKum/Network/TargetType/HomeTargetType.swift @@ -16,6 +16,7 @@ enum HomeTargetType { case updatePreparationStatus(promiseID: Int) case updateDepartureStatus(promiseID: Int) case updateArrivalStatus(promiseID: Int) + case fetchMyReadyStatus(promiseID: Int) } extension HomeTargetType: TargetType { @@ -42,12 +43,14 @@ extension HomeTargetType: TargetType { return "/api/v1/promises/\(promiseID)/departure" case .updateArrivalStatus(let promiseID): return "/api/v1/promises/\(promiseID)/arrival" + case .fetchMyReadyStatus(let promiseID): + return "/api/v1/promises/\(promiseID)/status" } } var method: Moya.Method { switch self { - case .fetchLoginUser, .fetchNearestPromise, .fetchUpcomingPromise: + case .fetchLoginUser, .fetchNearestPromise, .fetchUpcomingPromise, .fetchMyReadyStatus: return .get case .updatePreparationStatus, .updateDepartureStatus, .updateArrivalStatus: return .patch diff --git a/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift b/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift index 17a63586..1b4360eb 100644 --- a/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift +++ b/KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift @@ -13,6 +13,7 @@ protocol HomeServiceType { func fetchLoginUser() async throws -> ResponseBodyDTO? func fetchNearestPromise() async throws -> ResponseBodyDTO? func fetchUpcomingPromise() async throws -> ResponseBodyDTO? + func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO? func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO? @@ -20,6 +21,10 @@ protocol HomeServiceType { } extension HomeService: HomeServiceType { + func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return try await request(with: .fetchMyReadyStatus(promiseID: promiseID)) + } + func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { return try await request( with: .updatePreparationStatus(promiseID: promiseID) @@ -52,6 +57,10 @@ extension HomeService: HomeServiceType { } final class MockHomeService: HomeServiceType { + func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { + return nil + } + func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO? { return nil } diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index 1fce438e..9c99d4fa 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -51,17 +51,19 @@ class HomeViewController: BaseViewController { updateUserInfo() updateNearestPromise() updateUpcomingPromise() - - viewModel.requestLoginUser() - viewModel.requestNearestPromise() - viewModel.requestUpcomingPromise() - - bindViewModel() + updateUI() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.isNavigationBarHidden = true + + viewModel.requestLoginUser() + viewModel.requestNearestPromise() + viewModel.requestUpcomingPromise() + viewModel.requestMyReadyStatus() + +// bindViewModel() } override func setupAction() { @@ -188,42 +190,59 @@ private extension HomeViewController { ) } - func bindViewModel() { - viewModel.isPreapreSucceedToSave.bind { [weak self] _ in - if self?.viewModel.isPreapreSucceedToSave.value == true { - DispatchQueue.main.async { +// func bindViewModel() { +// viewModel.isPreapreSucceedToSave.bind { [weak self] _ in +// if self?.viewModel.isPreapreSucceedToSave.value == true { +// DispatchQueue.main.async { +// //self?.setPrepareUI() +// self?.rootView.todayPromiseView.prepareTimeLabel.setText( +// self?.viewModel.homePrepareTime ?? "", +// style: .caption02, +// color: .gray8 +// ) +// } +// } +// } +// +// viewModel.isMoveSucceedToSave.bind { [weak self] _ in +// if self?.viewModel.isMoveSucceedToSave.value == true { +// DispatchQueue.main.async { +// //self?.setMoveUI() +// self?.rootView.todayPromiseView.moveTimeLabel.setText( +// self?.viewModel.homeMoveTime ?? "", +// style: .caption02, +// color: .gray8 +// ) +// } +// } +// } +// +// viewModel.isArriveSucceedToSave.bind { [weak self] _ in +// if self?.viewModel.isArriveSucceedToSave.value == true { +// DispatchQueue.main.async { +// //self?.setArriveUI() +// self?.rootView.todayPromiseView.arriveTimeLabel.setText( +// self?.viewModel.homeArriveTime ?? "", +// style: .caption02, +// color: .gray8 +// ) +// } +// } +// } +// } + + func updateUI() { + viewModel.currentState.bind { [weak self] state in + DispatchQueue.main.async { + switch state { + case .prepare: self?.setPrepareUI() - self?.rootView.todayPromiseView.prepareTimeLabel.setText( - self?.viewModel.homePrepareTime ?? "", - style: .caption02, - color: .gray8 - ) - } - } - } - - viewModel.isMoveSucceedToSave.bind { [weak self] _ in - if self?.viewModel.isMoveSucceedToSave.value == true { - DispatchQueue.main.async { + case .move: self?.setMoveUI() - self?.rootView.todayPromiseView.moveTimeLabel.setText( - self?.viewModel.homeMoveTime ?? "", - style: .caption02, - color: .gray8 - ) - } - } - } - - viewModel.isArriveSucceedToSave.bind { [weak self] _ in - if self?.viewModel.isArriveSucceedToSave.value == true { - DispatchQueue.main.async { + case .arrive: self?.setArriveUI() - self?.rootView.todayPromiseView.arriveTimeLabel.setText( - self?.viewModel.homeArriveTime ?? "", - style: .caption02, - color: .gray8 - ) + case .none: + break } } } @@ -366,6 +385,10 @@ private extension HomeViewController { rootView.todayPromiseView.moveLabel.isHidden = false rootView.todayPromiseView.prepareLineView.isHidden = false + + rootView.todayPromiseView.prepareTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.preparationStartAt ?? "", style: .caption02, color: .gray8 + ) } func setMoveUI() { @@ -385,7 +408,16 @@ private extension HomeViewController { rootView.todayPromiseView.arriveLabel.isHidden = false rootView.todayPromiseView.prepareCheckView.isHidden = false + + rootView.todayPromiseView.prepareLineView.isHidden = false rootView.todayPromiseView.moveLineView.isHidden = false + + rootView.todayPromiseView.prepareTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.preparationStartAt ?? "", style: .caption02, color: .gray8 + ) + rootView.todayPromiseView.moveTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.departureAt ?? "", style: .caption02, color: .gray8 + ) } func setArriveUI() { @@ -404,9 +436,23 @@ private extension HomeViewController { rootView.todayPromiseView.moveLabel.isHidden = true rootView.todayPromiseView.arriveLabel.isHidden = true + rootView.todayPromiseView.prepareCheckView.isHidden = false rootView.todayPromiseView.moveCheckView.isHidden = false rootView.todayPromiseView.arriveCheckView.isHidden = false + + rootView.todayPromiseView.prepareLineView.isHidden = false + rootView.todayPromiseView.moveLineView.isHidden = false rootView.todayPromiseView.arriveLineView.isHidden = false + + rootView.todayPromiseView.prepareTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.preparationStartAt ?? "", style: .caption02, color: .gray8 + ) + rootView.todayPromiseView.moveTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.departureAt ?? "", style: .caption02, color: .gray8 + ) + rootView.todayPromiseView.arriveTimeLabel.setText( + self.viewModel.myReadyStatus.value?.data?.arrivalAt ?? "", style: .caption02, color: .gray8 + ) } diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index 5ddde271..e0cf6e91 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -17,11 +17,12 @@ enum ReadyState { } final class HomeViewModel { - var promiseID = ObservablePattern?(nil) + var currentState = ObservablePattern(.none) var loginUser = ObservablePattern?>(nil) var nearestPromise = ObservablePattern?>(nil) var upcomingPromiseList = ObservablePattern?>(nil) + var myReadyStatus = ObservablePattern?>(nil) var levelName = ObservablePattern("") var levelCaption = ObservablePattern("") @@ -36,32 +37,33 @@ final class HomeViewModel { self.service = service } - var homePrepareTime: String = "" - var homeMoveTime: String = "" - var homeArriveTime: String = "" - - private let dateFormatter = DateFormatter().then { - $0.dateFormat = "a hh:mm" - $0.amSymbol = "AM" - $0.pmSymbol = "PM" - } - - private func updateState(newState: ReadyState) { - let currentTimeString = dateFormatter.string(from: Date()) - switch newState { - case .prepare: - homePrepareTime = currentTimeString - case .move: - homeMoveTime = currentTimeString - case .arrive: - homeArriveTime = currentTimeString - case .none: - break - } - } +// var homePrepareTime: String = "" +// var homeMoveTime: String = "" +// var homeArriveTime: String = "" + +// private let dateFormatter = DateFormatter().then { +// $0.dateFormat = "a hh:mm" +// $0.amSymbol = "AM" +// $0.pmSymbol = "PM" +// } + +// private func updateState(newState: ReadyState) { +// currentState.value = newState +// let currentTimeString = dateFormatter.string(from: Date()) +// switch newState { +// case .prepare: +// homePrepareTime = currentTimeString +// case .move: +// homeMoveTime = currentTimeString +// case .arrive: +// homeArriveTime = currentTimeString +// case .none: +// break +// } +// } ///서버에서 보내주는 level Int 값에 따른 levelName - func getLevelName(level: Int) -> String { + private func getLevelName(level: Int) -> String { switch level { case 1: return "빼꼼 꾸물이" case 2: return "밍기적 꾸물이" @@ -72,7 +74,7 @@ final class HomeViewModel { } ///서버에서 보내주는 level Int 값에 따른 levelCaption - func getLevelCaption(level: Int) -> String { + private func getLevelCaption(level: Int) -> String { switch level { case 1: return "꾸물꿈에 오신 것을 환영해요!\n정시 도착으로 캐릭터를 성장시켜 보세요." @@ -87,16 +89,46 @@ final class HomeViewModel { } } + private func judgeReadyStatus() { + let data = myReadyStatus.value?.data + if data?.preparationStartAt == nil && data?.departureAt == nil && data?.arrivalAt == nil { + currentState.value = .none + } else if data?.preparationStartAt != nil && data?.departureAt == nil && data?.arrivalAt == nil { + currentState.value = .prepare + } else if data?.departureAt != nil && data?.arrivalAt == nil { + currentState.value = .move + } else if data?.arrivalAt != nil { + currentState.value = .arrive + } + } + + func requestMyReadyStatus() { + Task { + do { + print(currentState.value) + myReadyStatus.value = try await service.fetchMyReadyStatus( + with: nearestPromise.value?.data?.promiseID ?? 1 + ) + judgeReadyStatus() + print(currentState.value) + } catch { + print(">>> \(error.localizedDescription) : \(#function)") + } + } + } + func updatePrepareStatus() { Task { do { - guard let responseBody = try await service.updatePreparationStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + guard let responseBody = try await service.updatePreparationStatus( + with: nearestPromise.value?.data?.promiseID ?? 1 + ) else { isPreapreSucceedToSave.value = false return } isPreapreSucceedToSave.value = responseBody.success - updateState(newState: .prepare) +// updateState(newState: .prepare) } catch { print(">>> \(error.localizedDescription) : \(#function)") } @@ -106,13 +138,15 @@ final class HomeViewModel { func updateMoveStatus() { Task { do { - guard let responseBody = try await service.updateDepartureStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + guard let responseBody = try await service.updateDepartureStatus( + with: nearestPromise.value?.data?.promiseID ?? 1 + ) else { isMoveSucceedToSave.value = false return } isMoveSucceedToSave.value = responseBody.success - updateState(newState: .move) +// updateState(newState: .move) } catch { print(">>> \(error.localizedDescription) : \(#function)") } @@ -122,13 +156,15 @@ final class HomeViewModel { func updateArriveStatus() { Task { do { - guard let responseBody = try await service.updateArrivalStatus(with: nearestPromise.value?.data?.promiseID ?? 1) + guard let responseBody = try await service.updateArrivalStatus( + with: nearestPromise.value?.data?.promiseID ?? 1 + ) else { isArriveSucceedToSave.value = false return } isArriveSucceedToSave.value = responseBody.success - updateState(newState: .arrive) +// updateState(newState: .arrive) } catch { print(">>> \(error.localizedDescription) : \(#function)") } From 9266a38f8d21e33c215900390206e04a3b1d7ea0 Mon Sep 17 00:00:00 2001 From: mmaybei Date: Fri, 19 Jul 2024 15:35:22 +0900 Subject: [PATCH 3/5] =?UTF-8?q?chore/#241=20=EC=A4=91=EA=B0=84=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/ViewController/HomeViewController.swift | 10 +++++++++- KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index 9c99d4fa..980ffafd 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -48,16 +48,22 @@ class HomeViewController: BaseViewController { view.backgroundColor = .maincolor register() + updateUI() + updateUserInfo() updateNearestPromise() updateUpcomingPromise() - updateUI() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.isNavigationBarHidden = true +// updateUserInfo() +// updateNearestPromise() +// updateUpcomingPromise() +// updateUI() + viewModel.requestLoginUser() viewModel.requestNearestPromise() viewModel.requestUpcomingPromise() @@ -397,6 +403,7 @@ private extension HomeViewController { setProgressButton(rootView.todayPromiseView.moveButton) setEnableButton(rootView.todayPromiseView.arriveButton) + rootView.todayPromiseView.prepareButton.isEnabled = false rootView.todayPromiseView.moveButton.isEnabled = false rootView.todayPromiseView.arriveButton.isEnabled = true @@ -425,6 +432,7 @@ private extension HomeViewController { setCompleteButton(rootView.todayPromiseView.moveButton) setCompleteButton(rootView.todayPromiseView.arriveButton) + rootView.todayPromiseView.prepareButton.isEnabled = false rootView.todayPromiseView.moveButton.isEnabled = false rootView.todayPromiseView.arriveButton.isEnabled = false diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index e0cf6e91..03b007be 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -128,7 +128,7 @@ final class HomeViewModel { return } isPreapreSucceedToSave.value = responseBody.success -// updateState(newState: .prepare) + currentState.value = .prepare } catch { print(">>> \(error.localizedDescription) : \(#function)") } @@ -146,7 +146,7 @@ final class HomeViewModel { return } isMoveSucceedToSave.value = responseBody.success -// updateState(newState: .move) + currentState.value = .move } catch { print(">>> \(error.localizedDescription) : \(#function)") } @@ -164,7 +164,7 @@ final class HomeViewModel { return } isArriveSucceedToSave.value = responseBody.success -// updateState(newState: .arrive) + currentState.value = .arrive } catch { print(">>> \(error.localizedDescription) : \(#function)") } From f3cb9933b1ccf10b6c1d66fee6b348bb53e7b1af Mon Sep 17 00:00:00 2001 From: mmaybei Date: Fri, 19 Jul 2024 16:06:56 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix/#241=20nearestPromise=EA=B0=80=20?= =?UTF-8?q?=EB=A8=BC=EC=A0=80=20=ED=98=B8=EC=B6=9C=EB=90=98=EA=B3=A0=20myR?= =?UTF-8?q?eadyStatus=EA=B0=80=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum/Source/Home/ViewController/HomeViewController.swift | 2 +- KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index 980ffafd..da132004 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -67,7 +67,7 @@ class HomeViewController: BaseViewController { viewModel.requestLoginUser() viewModel.requestNearestPromise() viewModel.requestUpcomingPromise() - viewModel.requestMyReadyStatus() +// viewModel.requestMyReadyStatus() // bindViewModel() } diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index 03b007be..699ae154 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -187,6 +187,7 @@ final class HomeViewModel { Task { do { nearestPromise.value = try await service.fetchNearestPromise() + requestMyReadyStatus() } catch { print(">>> \(error.localizedDescription) : \(#function)") } From 94f70fd307d4c106a785b1be54696dbea109c278 Mon Sep 17 00:00:00 2001 From: mmaybei Date: Fri, 19 Jul 2024 16:09:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?chore/#241=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewController/HomeViewController.swift | 51 +------------------ .../Source/Home/ViewModel/HomeViewModel.swift | 35 ------------- 2 files changed, 1 insertion(+), 85 deletions(-) diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index da132004..d71b87e0 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -58,18 +58,10 @@ class HomeViewController: BaseViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.isNavigationBarHidden = true - -// updateUserInfo() -// updateNearestPromise() -// updateUpcomingPromise() -// updateUI() - + viewModel.requestLoginUser() viewModel.requestNearestPromise() viewModel.requestUpcomingPromise() -// viewModel.requestMyReadyStatus() - -// bindViewModel() } override func setupAction() { @@ -196,47 +188,6 @@ private extension HomeViewController { ) } -// func bindViewModel() { -// viewModel.isPreapreSucceedToSave.bind { [weak self] _ in -// if self?.viewModel.isPreapreSucceedToSave.value == true { -// DispatchQueue.main.async { -// //self?.setPrepareUI() -// self?.rootView.todayPromiseView.prepareTimeLabel.setText( -// self?.viewModel.homePrepareTime ?? "", -// style: .caption02, -// color: .gray8 -// ) -// } -// } -// } -// -// viewModel.isMoveSucceedToSave.bind { [weak self] _ in -// if self?.viewModel.isMoveSucceedToSave.value == true { -// DispatchQueue.main.async { -// //self?.setMoveUI() -// self?.rootView.todayPromiseView.moveTimeLabel.setText( -// self?.viewModel.homeMoveTime ?? "", -// style: .caption02, -// color: .gray8 -// ) -// } -// } -// } -// -// viewModel.isArriveSucceedToSave.bind { [weak self] _ in -// if self?.viewModel.isArriveSucceedToSave.value == true { -// DispatchQueue.main.async { -// //self?.setArriveUI() -// self?.rootView.todayPromiseView.arriveTimeLabel.setText( -// self?.viewModel.homeArriveTime ?? "", -// style: .caption02, -// color: .gray8 -// ) -// } -// } -// } -// } - func updateUI() { viewModel.currentState.bind { [weak self] state in DispatchQueue.main.async { diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index 699ae154..23cad8e1 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -27,41 +27,12 @@ final class HomeViewModel { var levelName = ObservablePattern("") var levelCaption = ObservablePattern("") - var isPreapreSucceedToSave = ObservablePattern(false) - var isMoveSucceedToSave = ObservablePattern(false) - var isArriveSucceedToSave = ObservablePattern(false) - private let service: HomeServiceType init(service: HomeServiceType) { self.service = service } -// var homePrepareTime: String = "" -// var homeMoveTime: String = "" -// var homeArriveTime: String = "" - -// private let dateFormatter = DateFormatter().then { -// $0.dateFormat = "a hh:mm" -// $0.amSymbol = "AM" -// $0.pmSymbol = "PM" -// } - -// private func updateState(newState: ReadyState) { -// currentState.value = newState -// let currentTimeString = dateFormatter.string(from: Date()) -// switch newState { -// case .prepare: -// homePrepareTime = currentTimeString -// case .move: -// homeMoveTime = currentTimeString -// case .arrive: -// homeArriveTime = currentTimeString -// case .none: -// break -// } -// } - ///서버에서 보내주는 level Int 값에 따른 levelName private func getLevelName(level: Int) -> String { switch level { @@ -124,10 +95,8 @@ final class HomeViewModel { with: nearestPromise.value?.data?.promiseID ?? 1 ) else { - isPreapreSucceedToSave.value = false return } - isPreapreSucceedToSave.value = responseBody.success currentState.value = .prepare } catch { print(">>> \(error.localizedDescription) : \(#function)") @@ -142,10 +111,8 @@ final class HomeViewModel { with: nearestPromise.value?.data?.promiseID ?? 1 ) else { - isMoveSucceedToSave.value = false return } - isMoveSucceedToSave.value = responseBody.success currentState.value = .move } catch { print(">>> \(error.localizedDescription) : \(#function)") @@ -160,10 +127,8 @@ final class HomeViewModel { with: nearestPromise.value?.data?.promiseID ?? 1 ) else { - isArriveSucceedToSave.value = false return } - isArriveSucceedToSave.value = responseBody.success currentState.value = .arrive } catch { print(">>> \(error.localizedDescription) : \(#function)")