diff --git a/PingPong/Projects/App/Resources/Preview Content/bakeLoading.gif b/PingPong/Projects/App/Resources/bakeLoading.gif similarity index 100% rename from PingPong/Projects/App/Resources/Preview Content/bakeLoading.gif rename to PingPong/Projects/App/Resources/bakeLoading.gif diff --git a/PingPong/Projects/App/Resources/Preview Content/bakingGIF.gif b/PingPong/Projects/App/Resources/bakingGIF.gif similarity index 100% rename from PingPong/Projects/App/Resources/Preview Content/bakingGIF.gif rename to PingPong/Projects/App/Resources/bakingGIF.gif diff --git a/PingPong/Projects/App/Resources/Preview Content/startViewGIF.gif b/PingPong/Projects/App/Resources/startViewGIF.gif similarity index 100% rename from PingPong/Projects/App/Resources/Preview Content/startViewGIF.gif rename to PingPong/Projects/App/Resources/startViewGIF.gif diff --git a/PingPong/Projects/App/Resources/Preview Content/swipe.gif b/PingPong/Projects/App/Resources/swipe.gif similarity index 100% rename from PingPong/Projects/App/Resources/Preview Content/swipe.gif rename to PingPong/Projects/App/Resources/swipe.gif diff --git a/PingPong/Projects/Core/Authorization/Sources/ViewModel/AuthorizationViewModel.swift b/PingPong/Projects/Core/Authorization/Sources/ViewModel/AuthorizationViewModel.swift index 471659b2..5a75d5b8 100644 --- a/PingPong/Projects/Core/Authorization/Sources/ViewModel/AuthorizationViewModel.swift +++ b/PingPong/Projects/Core/Authorization/Sources/ViewModel/AuthorizationViewModel.swift @@ -147,9 +147,9 @@ public class AuthorizationViewModel: ObservableObject { "uid" : result?.user.uid ?? ""] Firestore.firestore().collection("users") .document(result?.user.uid ?? "") - .setData(data) { data in - debugPrint("DEBUG : Upload user data : \(String(describing: data))") - } +// .setData(data) { data in +// debugPrint("DEBUG : Upload user data : \(String(describing: data))") +// } print("로그인 uid", self.uid, APIHeaderManger.shared.firebaseUid) } } @@ -327,7 +327,7 @@ public class AuthorizationViewModel: ObservableObject { public func loginWithEmail( email: String, - succesCompletion : @escaping () -> Void, + succesCompletion : @escaping (SignUPModel) -> Void, failLoginCompletion: @escaping () -> Void ) async { if let cancellable = loginEmailCancellable { @@ -351,8 +351,9 @@ public class AuthorizationViewModel: ObservableObject { self?.signupToViewModel(model) self?.userid = model.data?.id ?? .zero self?.userUid = model.data?.uid ?? "" + print("로그인 성공", model) - succesCompletion() + succesCompletion(model) } else { self?.signupToViewModel(model) self?.userid = model.data?.id ?? .zero @@ -367,12 +368,14 @@ public class AuthorizationViewModel: ObservableObject { self.commonCodeModel = list } - public func randomNameRequest(commCdTpCd: CommonType) async { + public func randomNameRequest( + commCdTpCd: CommonType, + completion: @escaping (CommonCdModel) -> Void) async { if let cancellable = randomNameCancellable { cancellable.cancel() } - let provider = MoyaProvider(plugins: [MoyaLoggingPlugin()]) + let provider = MoyaProvider(plugins: [MoyaLoggingPlugin()]) randomNameCancellable = provider.requestWithProgressPublisher(.searchCommCode(commCdTpCd: commCdTpCd.description)) .compactMap { $0.response?.data } .receive(on: DispatchQueue.main) @@ -388,13 +391,20 @@ public class AuthorizationViewModel: ObservableObject { if model.status == NetworkCode.success.status { self?.commCodeToViewModel(model) - if let randomCommNm = model.data.commCds.randomElement()?.commNm { + if let randomCommNm = model.data?.commCds.randomElement()?.commNm { self?.randomAuthNickName = randomCommNm Log.network("랜덤 이름", randomCommNm) + completion(model) } + Log.network("랜덤 이름", model) } else { self?.commCodeToViewModel(model) Log.network("유저 코드", model) + + if let randomCommNm = model.data?.commCds.randomElement()?.commNm { + self?.randomAuthNickName = randomCommNm + Log.network("랜덤 이름", randomCommNm) + } } }) } diff --git a/PingPong/Projects/Core/Domain/Model/Sources/Model/Common/CommonCdModel.swift b/PingPong/Projects/Core/Domain/Model/Sources/Model/Common/CommonCdModel.swift index d731cfa0..4e1db392 100644 --- a/PingPong/Projects/Core/Domain/Model/Sources/Model/Common/CommonCdModel.swift +++ b/PingPong/Projects/Core/Domain/Model/Sources/Model/Common/CommonCdModel.swift @@ -10,10 +10,10 @@ import Foundation public struct CommonCdModel: Codable { public let status: Int - public let data: CommonCdResponseModel + public let data: CommonCdResponseModel? public let message: String? - public init(status: Int, data: CommonCdResponseModel, message: String?) { + public init(status: Int, data: CommonCdResponseModel?, message: String?) { self.status = status self.data = data self.message = message diff --git a/PingPong/Projects/Core/Domain/Service/Sources/Common/CommonService.swift b/PingPong/Projects/Core/Domain/Service/Sources/Common/CommonService.swift new file mode 100644 index 00000000..ee52112f --- /dev/null +++ b/PingPong/Projects/Core/Domain/Service/Sources/Common/CommonService.swift @@ -0,0 +1,43 @@ +// +// CommonService.swift +// Service +// +// Created by 서원지 on 12/4/23. +// Copyright © 2023 Wonji Suh. All rights reserved. +// + +import Foundation +import Moya +import API + +public enum CommonService { + case searchCommCode(commCdTpCd: String) +} + + +extension CommonService: NoAuthBaseTargetType { + public var path: String { + switch self { + case .searchCommCode(let commCdTpCd): + return "\(PingPongAPISearch.searchCommonCode)\(commCdTpCd)" + } + } + + public var method: Moya.Method { + switch self { + case .searchCommCode: + return .get + } + } + + public var task: Moya.Task { + switch self { + case .searchCommCode(_): + let parameters : [String : Any] = [ + : + ] + + return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) + } + } +} diff --git a/PingPong/Projects/Core/Domain/Service/Sources/Foundation/APIConstants.swift b/PingPong/Projects/Core/Domain/Service/Sources/Foundation/APIConstants.swift index 296e7ec8..e73599a9 100644 --- a/PingPong/Projects/Core/Domain/Service/Sources/Foundation/APIConstants.swift +++ b/PingPong/Projects/Core/Domain/Service/Sources/Foundation/APIConstants.swift @@ -21,7 +21,12 @@ struct APIConstants{ extension APIConstants { static var baseHeader: Dictionary { [ contentType : APIHeaderManger.shared.contentType, - authorization : "Bearer \(APIHeaderManger.shared.firebaseUid)" + authorization : "Bearer \(APIHeaderManger.shared.firebaseUid)" + ] + } + + static var noAuhtHeader: Dictionary { + [ contentType : APIHeaderManger.shared.contentType ] } } diff --git a/PingPong/Projects/Core/Domain/Service/Sources/Foundation/NoAuthBaseTargetType.swift b/PingPong/Projects/Core/Domain/Service/Sources/Foundation/NoAuthBaseTargetType.swift new file mode 100644 index 00000000..bce6c423 --- /dev/null +++ b/PingPong/Projects/Core/Domain/Service/Sources/Foundation/NoAuthBaseTargetType.swift @@ -0,0 +1,25 @@ +// +// NoAuthBaseTargetType.swift +// Service +// +// Created by 서원지 on 12/4/23. +// Copyright © 2023 Wonji Suh. All rights reserved. +// + +import Foundation +import Moya +import API + +public protocol NoAuthBaseTargetType: TargetType {} + + +extension NoAuthBaseTargetType { + public var baseURL: URL { + return URL(string: PingPongAPI.baseURL)! + } + + public var headers: [String : String]? { + return APIConstants.noAuhtHeader + } + +} diff --git a/PingPong/Projects/Core/Domain/Service/Sources/Search/SearchService.swift b/PingPong/Projects/Core/Domain/Service/Sources/Search/SearchService.swift index 74a8cc46..78a54c9b 100644 --- a/PingPong/Projects/Core/Domain/Service/Sources/Search/SearchService.swift +++ b/PingPong/Projects/Core/Domain/Service/Sources/Search/SearchService.swift @@ -49,9 +49,10 @@ extension SearchService: BaseTargetType { return .requestParameters(parameters: parameters, encoding: JSONEncoding.default) - case .searchCommCode(let commCdTpCd): + case .searchCommCode(_): let parameters : [String : Any] = [ - "commCdTpCd": commCdTpCd +// "commCdTpCd": commCdTpCd + : ] diff --git a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceBreadView.swift b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceBreadView.swift index 17d879ac..a9f686c4 100644 --- a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceBreadView.swift +++ b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceBreadView.swift @@ -106,7 +106,7 @@ public struct ChoiceBreadView: View { let sortedCommCds = commonData.commCds.filter { $0.commCD != "other" && $0.commCD != "proverb" && $0.commCD != "unknown"} ForEach(sortedCommCds, id: \.self) { item in - let source: Source = Source(rawValue: item.commCD) ?? .anime + let source: Source = Source(rawValue: item.commCD ?? "") ?? .anime VStack { Circle() diff --git a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceIngredentView.swift b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceIngredentView.swift index ee522370..58a87824 100644 --- a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceIngredentView.swift +++ b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceIngredentView.swift @@ -112,7 +112,7 @@ public struct ChoiceIngredentView: View { ForEach(commonData.commCds, id: \.self) { item in - let flavor: Flavor = Flavor(rawValue: item.commCD) ?? .light + let flavor: Flavor = Flavor(rawValue: item.commCD ?? "") ?? .light VStack { diff --git a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceToppingView.swift b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceToppingView.swift index 329373d8..8b7410e0 100644 --- a/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceToppingView.swift +++ b/PingPong/Projects/Feature/Bake/Sources/UI/HomeBakingView/ChoiceToppingView.swift @@ -106,7 +106,7 @@ public struct ChoiceToppingView: View { ForEach(commonData.commCds, id: \.self) { item in - let mood: Mood = Mood(rawValue: item.commCD) ?? .motivation + let mood: Mood = Mood(rawValue: item.commCD ?? "") ?? .motivation VStack { Circle() diff --git a/PingPong/Projects/Feature/Home/Sources/UI/View/HomeView/HomeView.swift b/PingPong/Projects/Feature/Home/Sources/UI/View/HomeView/HomeView.swift index 1aaf3bfb..c45bc96b 100644 --- a/PingPong/Projects/Feature/Home/Sources/UI/View/HomeView/HomeView.swift +++ b/PingPong/Projects/Feature/Home/Sources/UI/View/HomeView/HomeView.swift @@ -47,11 +47,15 @@ public struct HomeView: View { } .navigationBarHidden(true) .task { - await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: {}, failLoginCompletion: {}) + await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: { model in + authViewModel.userNickName = model.data?.nickname ?? "" + authViewModel.userid = model.data?.id ?? .zero + }, failLoginCompletion: {}) + authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)") + } .onAppear { - authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)") if !homeViewModel.isOn.isEmpty { homeViewModel.randomQuoteRequest(userID: "\(authViewModel.userid)") { for quoteContent in homeViewModel.homeRandomQuoteModel?.data?.content ?? [] { diff --git a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/FavoriteWiseChoseView/SelectCategoryView.swift b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/FavoriteWiseChoseView/SelectCategoryView.swift index 8de0830f..78d0fd35 100644 --- a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/FavoriteWiseChoseView/SelectCategoryView.swift +++ b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/FavoriteWiseChoseView/SelectCategoryView.swift @@ -119,14 +119,14 @@ public struct SelectCategoryView: View { ForEach(sortedCommCds, id: \.self) { item in VStack { - let favoirte = Source(rawValue: item.commCD) + let favoirte = Source(rawValue: item.commCD ?? "") if viewModel.selectedFavorite.contains(Source(rawValue: (favoirte ?? .anime).rawValue) ?? .anime){ Circle() .frame(width: 96, height: 96) .foregroundColor(.basicGray3) .overlay( - Image(assetName: item.commCD) + Image(assetName: item.commCD ?? "") ) } else { Circle() @@ -137,17 +137,17 @@ public struct SelectCategoryView: View { ) } - Text(item.commNm) + Text(item.commNm ?? "") .pretendardFont(family: .SemiBold, size: 14) } .onTapGesture { - let source = Source(rawValue: item.commCD) + let source = Source(rawValue: item.commCD ?? "") if let favorite = source { self.viewModel.appendAndPopFavorite(favorite: favorite) } - self.viewModel.selectedFavoriteCategory = item.commCD + self.viewModel.selectedFavoriteCategory = item.commCD ?? "" } diff --git a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/LoginSettingView/LoginJobSettingView.swift b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/LoginSettingView/LoginJobSettingView.swift index dd9dbbae..e81f668b 100644 --- a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/LoginSettingView/LoginJobSettingView.swift +++ b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/LoginSettingView/LoginJobSettingView.swift @@ -81,7 +81,7 @@ public struct LoginJobSettingView: View { LazyVGrid(columns: columns, spacing: 10) { let searchUserJob = viewModel.onBoardingSearchUserModel?.data?.filter{$0.commCDTpID == 4} if let firstSearchUserJob = searchUserJob?.first { - let sortedCommCds = firstSearchUserJob.commCds?.sorted(by: { $0.commCDID < $1.commCDID }) ?? [] + let sortedCommCds = firstSearchUserJob.commCds?.sorted(by: { $0.commCDID ?? .zero < $1.commCDID ?? .zero }) ?? [] ForEach(sortedCommCds, id: \.self) { commCDItem in VStack { if viewModel.selectedJob == commCDItem.commCD { @@ -93,7 +93,7 @@ public struct LoginJobSettingView: View { .frame(width: 96, height: 96) .foregroundColor(.primaryOrangeOpacity40) .overlay( - Image(assetName: commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD) + Image(assetName: (commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD) ?? "") ) ) } else { @@ -101,15 +101,15 @@ public struct LoginJobSettingView: View { .frame(width: 96, height: 96) .foregroundColor(.basicGray3) .overlay( - Image(assetName: commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD ) + Image(assetName: (commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD) ?? "" ) ) } - Text(commCDItem.commNm) + Text(commCDItem.commNm ?? "") .pretendardFont(family: .SemiBold, size: 14) } .onTapGesture { self.viewModel.selectedJob = commCDItem.commCD - self.viewModel.selectJobCode = commCDItem.commCDID + self.viewModel.selectJobCode = commCDItem.commCDID ?? .zero } } } diff --git a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/MainView/OnBoardingLoginView.swift b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/MainView/OnBoardingLoginView.swift index af820fb8..d1c66fe4 100644 --- a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/MainView/OnBoardingLoginView.swift +++ b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/MainView/OnBoardingLoginView.swift @@ -145,14 +145,15 @@ public struct OnBoardingLoginView: View { } authViewModel.appleLogin(credential: credential) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + DispatchQueue.main.asyncAfter(deadline: .now() + 1.8) { Task { await authViewModel.loginWithEmail( email: authViewModel.userEmail, - succesCompletion: { - + succesCompletion: { model in commonViewViewModel.isLogin = true commonViewViewModel.isLoginCheck = true + authViewModel.userid = model.data?.id ?? .zero + authViewModel.userNickName = model.data?.nickname ?? "" }, failLoginCompletion: { appState.signUPFaillPOPUP.toggle() @@ -162,8 +163,10 @@ public struct OnBoardingLoginView: View { } case .failure(let error): - appState.signUPFaillPOPUP.toggle() - presentationMode.wrappedValue.dismiss() + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + appState.signUPFaillPOPUP.toggle() + presentationMode.wrappedValue.dismiss() + } } } diff --git a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/OnBoardingPushViiew/CompletOnBoardingView.swift b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/OnBoardingPushViiew/CompletOnBoardingView.swift index 4741c510..5b9e6892 100644 --- a/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/OnBoardingPushViiew/CompletOnBoardingView.swift +++ b/PingPong/Projects/Feature/OnBoarding/Sources/UI/View/OnBoardingPushViiew/CompletOnBoardingView.swift @@ -40,7 +40,7 @@ public struct CompletOnBoardingView: View { .task { authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)") - await authViewModel.randomNameRequest(commCdTpCd: .userDesc) + await authViewModel.randomNameRequest(commCdTpCd: .userDesc, completion: {_ in }) } } diff --git a/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift b/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift index 60e05cd1..ee8db49a 100644 --- a/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift +++ b/PingPong/Projects/Feature/Profile/Sources/UI/View/MainView/ProfileView.swift @@ -17,7 +17,7 @@ public struct ProfileView: View { @StateObject private var appState: AppState @StateObject private var viewModel: CommonViewViewModel @StateObject private var profileViewModel: ProfileViewViewModel = ProfileViewViewModel() - @ObservedObject var authViewModel: AuthorizationViewModel + @StateObject var authViewModel: AuthorizationViewModel @Environment(\.presentationMode) var presentationMode @EnvironmentObject var sheetManager: SheetManager @@ -34,7 +34,7 @@ public struct ProfileView: View { self._appState = StateObject(wrappedValue: appState) self._viewModel = StateObject(wrappedValue: viewModel) self.backAction = backAction - self._authViewModel = ObservedObject(wrappedValue: authViewModel) + self._authViewModel = StateObject(wrappedValue: authViewModel) } @@ -70,15 +70,22 @@ public struct ProfileView: View { .navigationBarBackButtonHidden() .task { - await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: {}, failLoginCompletion: {}) - authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)") - - profileViewModel.changeImage(randomNickName: authViewModel.randomAuthNickName) if authViewModel.randomAuthNickName == "" { - await authViewModel.randomNameRequest(commCdTpCd: .userDesc) + await authViewModel.randomNameRequest(commCdTpCd: .userDesc, completion: { model in + authViewModel.randomAuthNickName = model.data?.commCds.randomElement()?.commNm ?? "" + profileViewModel.changeImage(randomNickName: authViewModel.randomAuthNickName) + }) } + profileViewModel.changeImage(randomNickName: authViewModel.randomAuthNickName) - await profileViewModel.profileUserPrefRequset(userid: "\(authViewModel.userid)", completion: {_ in + await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: { model in + authViewModel.userNickName = model.data?.nickname ?? "" + authViewModel.userid = model.data?.id ?? .zero + }, failLoginCompletion: {}) + + authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)") + + await profileViewModel.profileUserPrefRequset(userid: "\(authViewModel.userid)", completion: { _ in for userFlavor in profileViewModel.profileUserPrefModel?.data?.flavors ?? [] { guard let flavor = Flavor(rawValue: userFlavor) else { continue } if !viewModel.selectedFlavorArray.contains(flavor) { @@ -196,7 +203,7 @@ public struct ProfileView: View { VStack(spacing: .zero) { HStack { - Text("\(authViewModel.signupModel?.data?.nickname ?? "")") + Text(authViewModel.userNickName) .pretendardFont(family: .SemiBold, size: 18) .foregroundColor(Color.basicGray9) Spacer() @@ -204,7 +211,7 @@ public struct ProfileView: View { } HStack { - Text(profileViewModel.randomNickName) + Text(authViewModel.randomAuthNickName) .pretendardFont(family: .Medium, size: 14) .foregroundColor(Color.basicGray7) @@ -483,7 +490,7 @@ public struct ProfileView: View { .onTapGesture { viewModel.isLogin = false viewModel.isLoginCheck = false - + authViewModel.randomAuthNickName = "" presentationMode.wrappedValue.dismiss() } diff --git a/PingPong/Projects/Feature/Profile/Sources/UI/View/ViewModel/ProfileViewViewModel.swift b/PingPong/Projects/Feature/Profile/Sources/UI/View/ViewModel/ProfileViewViewModel.swift index 2657bfac..bc8ad405 100644 --- a/PingPong/Projects/Feature/Profile/Sources/UI/View/ViewModel/ProfileViewViewModel.swift +++ b/PingPong/Projects/Feature/Profile/Sources/UI/View/ViewModel/ProfileViewViewModel.swift @@ -32,7 +32,7 @@ public class ProfileViewViewModel: ObservableObject { @Published var changeNickNameView: Bool = false @Published var changeNickNameSuccessPOPUP: Bool = false @Published public var changeNickName: String = "" - @Published public var changeNickImage: String = "" + @Published public var changeNickImage: String = "mainHomeLogo" @AppStorage("selectedChangeTimeView") public var selectedChangeTimeView: Bool = false @AppStorage("saveDate") public var saveDate: String = "" @@ -311,7 +311,7 @@ public class ProfileViewViewModel: ObservableObject { if model.status == NetworkCode.success.status { self?.commCodeToViewModel(model) - if let randomCommNm = model.data.commCds.randomElement()?.commNm { + if let randomCommNm = model.data?.commCds.randomElement()?.commNm { self?.randomNickName = randomCommNm Log.network("랜덤 이름", randomCommNm) }