From 1c611678337e1d517d4f86dad3450e97a3b86df7 Mon Sep 17 00:00:00 2001 From: hhhello Date: Mon, 7 Oct 2024 15:05:14 +0900 Subject: [PATCH] Fix editting profile --- .../api/user/dto/EditUserReq.kt | 2 +- .../EditGrade/EditGraduatingYearView.swift | 4 ++- .../Feature/EditProfile/EditProfileView.swift | 28 +++++++++++-------- .../EditProfile/EditProfileViewModel.swift | 14 ++++++++-- .../Feature/EditSchool/EditSchoolView.swift | 2 +- .../Feature/ViewModel/AppState.swift | 1 - Graduating-iOS/Shared/Combine/Flow.swift | 3 +- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/user/dto/EditUserReq.kt b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/user/dto/EditUserReq.kt index ec2b10b..b457d6e 100644 --- a/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/user/dto/EditUserReq.kt +++ b/Graduating-Server/src/main/kotlin/com/bestswlkh0310/graduating/graduatingserver/api/user/dto/EditUserReq.kt @@ -5,6 +5,6 @@ import jakarta.validation.constraints.Size data class EditUserReq( @Size(min = 1, max = 24) val nickname: String?, - val graduatingYear: Int, + val graduatingYear: Int?, val schoolId: Long?, ) \ No newline at end of file diff --git a/Graduating-iOS/Graduating/Feature/EditGrade/EditGraduatingYearView.swift b/Graduating-iOS/Graduating/Feature/EditGrade/EditGraduatingYearView.swift index 5bda963..974ee27 100644 --- a/Graduating-iOS/Graduating/Feature/EditGrade/EditGraduatingYearView.swift +++ b/Graduating-iOS/Graduating/Feature/EditGrade/EditGraduatingYearView.swift @@ -38,10 +38,12 @@ extension EditGraduatingYearView { .padding(insets) } .onReceive(viewModel.$editGraduatingYearFlow) { flow in + print("WOWOWOWOW") + print(flow) switch flow { case .success: - router.toRoot() appState.fetchCurrentUser() + router.toRoot() case .failure: dialog.present( .init(title: "수정 실패") diff --git a/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileView.swift b/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileView.swift index 3682bbf..2c9623e 100644 --- a/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileView.swift +++ b/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileView.swift @@ -29,10 +29,25 @@ extension EditProfileView: View { } } +extension EditProfileView { + @ViewBuilder + func safeAreaContent() -> some View { + MyButton( + "수정 완료", + isEnabled: viewModel.isValidInput, + expanded: true + ) { + viewModel.editProfile() + } + .padding(.horizontal, 20) + .padding(.bottom, 8) + } +} + extension EditProfileView { func initNickname() { guard let user = appState.currentUser.data else { return } - viewModel.nickname = user.nickname + viewModel.initNickname(user.nickname) } func receiveEditProfileFlow(flow: Flow) { @@ -41,8 +56,8 @@ extension EditProfileView { dialog.present( .init(title: "프로필 수정 성공") .primaryButton("닫기") { + appState.fetchCurrentUser() router.pop() -// appState.fetchCurrentUser() // TODO: Handle } ) case .failure: @@ -54,13 +69,4 @@ extension EditProfileView { break } } - - @ViewBuilder - func safeAreaContent() -> some View { - MyButton("수정 완료", expanded: true) { - viewModel.editProfile() - } - .padding(.horizontal, 20) - .padding(.bottom, 8) - } } diff --git a/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileViewModel.swift b/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileViewModel.swift index 99c7f21..d59d6bb 100644 --- a/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileViewModel.swift +++ b/Graduating-iOS/Graduating/Feature/EditProfile/EditProfileViewModel.swift @@ -6,16 +6,24 @@ import Shared final class EditProfileViewModel: ObservableObject { @Published var editProfileFlow = Flow.idle + var originNickname: String? @Published var nickname = "" var subscriptions = Set() + + var isValidInput: Bool { + !nickname.isEmpty && originNickname != nickname + } } extension EditProfileViewModel { + func initNickname(_ nickname: String) { + self.originNickname = nickname + self.nickname = nickname + } + func editProfile() { UserService.shared.editUser( - .init( - nickname: nickname - ) + .init(nickname: nickname) ) .flow(\.editProfileFlow, on: self) .silentSink() diff --git a/Graduating-iOS/Graduating/Feature/EditSchool/EditSchoolView.swift b/Graduating-iOS/Graduating/Feature/EditSchool/EditSchoolView.swift index 8c31367..615874e 100644 --- a/Graduating-iOS/Graduating/Feature/EditSchool/EditSchoolView.swift +++ b/Graduating-iOS/Graduating/Feature/EditSchool/EditSchoolView.swift @@ -37,8 +37,8 @@ extension EditSchoolView { .onReceive(viewModel.$editSchoolFlow) { flow in switch flow { case .success: - router.toRoot() appState.fetchCurrentUser() + router.toRoot() case .failure: dialog.present( .init(title: "수정 실패") diff --git a/Graduating-iOS/Graduating/Feature/ViewModel/AppState.swift b/Graduating-iOS/Graduating/Feature/ViewModel/AppState.swift index 1f9785b..69aa190 100644 --- a/Graduating-iOS/Graduating/Feature/ViewModel/AppState.swift +++ b/Graduating-iOS/Graduating/Feature/ViewModel/AppState.swift @@ -36,7 +36,6 @@ extension AppState { } func fetchCurrentUser() { - guard currentUser.data == nil else { return } UserService.shared.getMe() .resource(\.currentUser, on: self) .sink { diff --git a/Graduating-iOS/Shared/Combine/Flow.swift b/Graduating-iOS/Shared/Combine/Flow.swift index 3864772..4b022ac 100644 --- a/Graduating-iOS/Shared/Combine/Flow.swift +++ b/Graduating-iOS/Shared/Combine/Flow.swift @@ -7,7 +7,6 @@ public enum Flow { case fetching case success case failure(Error) - case finished } public extension Publisher { @@ -27,7 +26,7 @@ public extension Publisher { receiveCompletion: { completion in switch completion { case .finished: - object[keyPath: keyPath] = .finished + break case .failure(let error): object[keyPath: keyPath] = .failure(error) }