Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 준비/이동/도착 시간 업데이트 API 및 준비 현황 API 연결 #248

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KkuMulKum/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
5 changes: 4 additions & 1 deletion KkuMulKum/Network/TargetType/HomeTargetType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
43 changes: 43 additions & 0 deletions KkuMulKum/Source/Home/ServiceType/HomeServiceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,36 @@ protocol HomeServiceType {
func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>?
func fetchNearestPromise() async throws -> ResponseBodyDTO<NearestPromiseModel>?
func fetchUpcomingPromise() async throws -> ResponseBodyDTO<UpcomingPromiseListModel>?
func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO<MyReadyStatusModel>?

func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>?
func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>?
func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>?
}

extension HomeService: HomeServiceType {
func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO<MyReadyStatusModel>? {
return try await request(with: .fetchMyReadyStatus(promiseID: promiseID))
}

func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return try await request(
with: .updatePreparationStatus(promiseID: promiseID)
)
}

func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return try await request(
with: .updateDepartureStatus(promiseID: promiseID)
)
}

func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return try await request(
with: .updateArrivalStatus(promiseID: promiseID)
)
}

func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? {
return try await request(with: .fetchLoginUser)
}
Expand All @@ -30,6 +57,22 @@ extension HomeService: HomeServiceType {
}

final class MockHomeService: HomeServiceType {
func fetchMyReadyStatus(with promiseID: Int) async throws -> ResponseBodyDTO<MyReadyStatusModel>? {
return nil
}

func updatePreparationStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return nil
}

func updateDepartureStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return nil
}

func updateArrivalStatus(with promiseID: Int) async throws -> ResponseBodyDTO<EmptyModel>? {
return nil
}

func fetchLoginUser() async throws -> ResponseBodyDTO<LoginUserModel>? {
let mockData = ResponseBodyDTO<LoginUserModel>(
success: true,
Expand Down
78 changes: 47 additions & 31 deletions KkuMulKum/Source/Home/ViewController/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class HomeViewController: BaseViewController {
updateUserInfo()
updateNearestPromise()
updateUpcomingPromise()

viewModel.requestLoginUser()
viewModel.requestNearestPromise()
viewModel.requestUpcomingPromise()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true

viewModel.requestLoginUser()
viewModel.requestNearestPromise()
viewModel.requestUpcomingPromise()
}

override func setupAction() {
Expand Down Expand Up @@ -190,15 +190,17 @@ 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
DispatchQueue.main.async {
switch state {
case .prepare:
self?.setPrepareUI()
case .move:
self?.setMoveUI()
case .arrive:
self?.setArriveUI()
case .none:
break
}
}
}
}
Expand Down Expand Up @@ -340,6 +342,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() {
Expand All @@ -348,6 +354,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

Expand All @@ -359,14 +366,24 @@ 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() {
setCompleteButton(rootView.todayPromiseView.prepareButton)
setCompleteButton(rootView.todayPromiseView.moveButton)
setCompleteButton(rootView.todayPromiseView.arriveButton)

rootView.todayPromiseView.prepareButton.isEnabled = false
rootView.todayPromiseView.moveButton.isEnabled = false
rootView.todayPromiseView.arriveButton.isEnabled = false

Expand All @@ -378,9 +395,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
)
}


Expand All @@ -402,31 +433,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()
}
}
Loading