diff --git a/Spon-us.xcodeproj/project.pbxproj b/Spon-us.xcodeproj/project.pbxproj index 7280726..5661229 100644 --- a/Spon-us.xcodeproj/project.pbxproj +++ b/Spon-us.xcodeproj/project.pbxproj @@ -73,6 +73,8 @@ DF90A5BE2B6E39A600BC54D0 /* RegisterPWView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5BD2B6E39A600BC54D0 /* RegisterPWView.swift */; }; DF90A5C02B6E534500BC54D0 /* SelectUserTypeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5BF2B6E534500BC54D0 /* SelectUserTypeView.swift */; }; DF91F4042B4864330021291A /* Portfolio.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91F4032B4864330021291A /* Portfolio.swift */; }; + DFB22ED72B766FF3007903DF /* JoinModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB22ED62B766FF3007903DF /* JoinModel.swift */; }; + DFB22ED92B767003007903DF /* JoinViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB22ED82B767003007903DF /* JoinViewModel.swift */; }; DFCD247C2B54D08100B00515 /* PopupView in Frameworks */ = {isa = PBXBuildFile; productRef = DFCD247B2B54D08100B00515 /* PopupView */; }; DFCD24822B5A67FC00B00515 /* DocumentPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFCD24812B5A67FC00B00515 /* DocumentPicker.swift */; }; /* End PBXBuildFile section */ @@ -140,6 +142,8 @@ DF90A5BD2B6E39A600BC54D0 /* RegisterPWView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterPWView.swift; sourceTree = ""; }; DF90A5BF2B6E534500BC54D0 /* SelectUserTypeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectUserTypeView.swift; sourceTree = ""; }; DF91F4032B4864330021291A /* Portfolio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Portfolio.swift; sourceTree = ""; }; + DFB22ED62B766FF3007903DF /* JoinModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinModel.swift; sourceTree = ""; }; + DFB22ED82B767003007903DF /* JoinViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinViewModel.swift; sourceTree = ""; }; DFCD24812B5A67FC00B00515 /* DocumentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentPicker.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -174,6 +178,8 @@ children = ( 100A1E372B734DB200AAC1E8 /* EmailModel.swift */, 100A1E392B734DDE00AAC1E8 /* EmailViewModel.swift */, + DFB22ED62B766FF3007903DF /* JoinModel.swift */, + DFB22ED82B767003007903DF /* JoinViewModel.swift */, ); path = Onboarding; sourceTree = ""; @@ -502,6 +508,7 @@ 100D38B32B4EF15600498977 /* HomeView.swift in Sources */, 10C8AC632B5C34C400B40547 /* CompanyPostView.swift in Sources */, DF3AD3DF2B61626300DBFCCC /* OnBoardingView.swift in Sources */, + DFB22ED92B767003007903DF /* JoinViewModel.swift in Sources */, 100A1E302B71637A00AAC1E8 /* MyProfileView.swift in Sources */, 3BFC8D1F2B5597C9000D6006 /* ProfileView.swift in Sources */, 3B36F09C2B6FEBA00000ACFB /* ChargerInfoViewTest.swift in Sources */, @@ -524,6 +531,7 @@ 3B36F0A82B6FEC3C0000ACFB /* PubData.swift in Sources */, 3B36F09A2B6FEB800000ACFB /* PaymentSettingView.swift in Sources */, DFCD24822B5A67FC00B00515 /* DocumentPicker.swift in Sources */, + DFB22ED72B766FF3007903DF /* JoinModel.swift in Sources */, 3B36F0A32B6FEC0B0000ACFB /* PortOneViewModel.swift in Sources */, 3B36F09E2B6FEBBC0000ACFB /* PaymentView.swift in Sources */, 80FA316D2B5EBA6B0076453B /* SearchOfferView.swift in Sources */, diff --git a/Spon-us/Model/Onboarding/JoinModel.swift b/Spon-us/Model/Onboarding/JoinModel.swift new file mode 100644 index 0000000..46c3f49 --- /dev/null +++ b/Spon-us/Model/Onboarding/JoinModel.swift @@ -0,0 +1,18 @@ +// +// JoinModel.swift +// Spon-us +// +// Created by 박현수 on 2/9/24. +// + +import Foundation + +struct JoinContent: Codable { + let id: Int + let email, name: String +} + +struct JoinModel: Codable { + let statusCode, message: String + let content: JoinContent +} diff --git a/Spon-us/Model/Onboarding/JoinViewModel.swift b/Spon-us/Model/Onboarding/JoinViewModel.swift new file mode 100644 index 0000000..7da6972 --- /dev/null +++ b/Spon-us/Model/Onboarding/JoinViewModel.swift @@ -0,0 +1,38 @@ +// +// JoinViewModel.swift +// Spon-us +// +// Created by 박현수 on 2/9/24. +// + +import Foundation +import Combine +import Moya + +class JoinViewModel: ObservableObject { + @Published var join: JoinModel? + @Published var isButtonEnabled = false + private let provider = MoyaProvider(plugins: [NetworkLoggerPlugin()]) + + func postJoin(name: String, email: String, password: String, orgType: OrgType, subOrgType: SubOrgType?) { + provider.request(.postJoin(name: name, email: email, password: password, orgType: orgType, subOrgType: subOrgType)) { result in + switch result { + case let .success(response): + do { + if response.statusCode == 200 { + self.isButtonEnabled = true + } + print(self.isButtonEnabled) + print(try response.mapJSON()) + let joinResponse = try response.map(JoinModel.self) + self.join = joinResponse + } catch { + print("Error parsing response: \(error)") + } + + case let .failure(error): + print("Network request failed: \(error)") + } + } + } +} diff --git a/Spon-us/SponusAPI.swift b/Spon-us/SponusAPI.swift index d736061..90d7565 100644 --- a/Spon-us/SponusAPI.swift +++ b/Spon-us/SponusAPI.swift @@ -9,8 +9,25 @@ import Foundation import Moya import KeychainSwift +enum OrgType { + case student, company +} + +enum SubOrgType { + case studentCouncil, studentClub +} + +struct JoinRequestBody: Codable { + let name: String + let email: String + let password: String + let organizationType: String + let suborganizationType: String? +} + enum SponusAPI { case postEmail(email: String) + case postJoin(name: String, email: String, password: String, orgType: OrgType, subOrgType: SubOrgType?) } extension SponusAPI: TargetType { @@ -20,8 +37,10 @@ extension SponusAPI: TargetType { var path: String { switch self { - case .postEmail(let email): + case .postEmail: return "/api/v1/organizations/email" + case .postJoin: + return "/api/v1/organizations/join" } } @@ -29,6 +48,8 @@ extension SponusAPI: TargetType { switch self { case .postEmail: return .post + case .postJoin: + return .post } } @@ -36,6 +57,17 @@ extension SponusAPI: TargetType { switch self { case .postEmail: return Data() + case .postJoin: + let response: [String : Any] = [ + "statusCode": "OK", + "message": "OK", + "content": [ + "id": 0, + "email": "test@test.com", + "name": "test" + ] + ] + return try! JSONSerialization.data(withJSONObject: response, options: .prettyPrinted) } } @@ -44,6 +76,21 @@ extension SponusAPI: TargetType { case .postEmail(let email): let parameters: [String: Any] = ["email": email] return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) + case .postJoin(let name, let email, let password, let orgType, let subOrgType): + switch orgType { + case .student: + switch subOrgType! { + case .studentCouncil: + let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: "STUDENT_COUNCIL") + return .requestJSONEncodable(requestBody) + case .studentClub: + let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: "STUDENT_CLUB") + return .requestJSONEncodable(requestBody) + } + case .company: + let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: nil) + return .requestJSONEncodable(requestBody) + } } } @@ -51,6 +98,8 @@ extension SponusAPI: TargetType { switch self { case .postEmail: return nil + case .postJoin: + return nil /* case .postLike: return ["Content-Type": "application/json", diff --git a/Spon-us/View/Onboarding/RegisterIDView.swift b/Spon-us/View/Onboarding/RegisterIDView.swift index 6a2924a..784f085 100644 --- a/Spon-us/View/Onboarding/RegisterIDView.swift +++ b/Spon-us/View/Onboarding/RegisterIDView.swift @@ -169,10 +169,10 @@ struct RegisterIDView: View { Spacer() NavigationLink { - RegisterPWView() + RegisterPWView(userID: userID) } label: { Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!isAuthenticated ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16) - }.disabled(!isAuthenticated) + }//.disabled(!isAuthenticated) }.navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden(true) .navigationBarItems(leading: CustomBackButton()) diff --git a/Spon-us/View/Onboarding/RegisterPWView.swift b/Spon-us/View/Onboarding/RegisterPWView.swift index 594b9e3..bd6b62c 100644 --- a/Spon-us/View/Onboarding/RegisterPWView.swift +++ b/Spon-us/View/Onboarding/RegisterPWView.swift @@ -8,6 +8,7 @@ import SwiftUI struct RegisterPWView: View { + @State var userID: String @State private var userPW = "" @State private var userPWConfirm = "" @State private var isPWSecure = true @@ -98,7 +99,7 @@ struct RegisterPWView: View { } Spacer() NavigationLink { - SelectUserTypeView() + SelectUserTypeView(userID: userID, userPW: userPW) } label: { Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!isValidPW ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16) }.disabled(!isValidPW) @@ -110,5 +111,5 @@ struct RegisterPWView: View { } #Preview { - RegisterPWView() + RegisterPWView(userID: "temp") } diff --git a/Spon-us/View/Onboarding/SelectUserTypeView.swift b/Spon-us/View/Onboarding/SelectUserTypeView.swift index 40c50cb..0579b4b 100644 --- a/Spon-us/View/Onboarding/SelectUserTypeView.swift +++ b/Spon-us/View/Onboarding/SelectUserTypeView.swift @@ -7,11 +7,9 @@ import SwiftUI -enum GroupType { - case studentCouncil, studentClub, company -} - struct SelectUserTypeView: View { + @State var userID: String + @State var userPW: String @State var isStudent = false @State var isCompany = false @@ -48,10 +46,10 @@ struct SelectUserTypeView: View { Spacer() NavigationLink { if isStudent { - StudentTypeView() + StudentTypeView(userID: userID, userPW: userPW) } else { - fillInGroupNameView(groupType: .company) + fillInGroupNameView(userID: userID, userPW: userPW, orgType: .company, subOrgType: nil) } } label: { Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!(isStudent || isCompany) ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16) @@ -64,6 +62,8 @@ struct SelectUserTypeView: View { } struct StudentTypeView: View { + @State var userID: String + @State var userPW: String @State var isCouncil = false @State var isClub = false @@ -100,10 +100,10 @@ struct StudentTypeView: View { Spacer() NavigationLink { if isCouncil { - fillInGroupNameView(groupType: .studentCouncil) + fillInGroupNameView(userID: userID, userPW: userPW, orgType: .student, subOrgType: .studentCouncil) } else { - fillInGroupNameView(groupType: .studentClub) + fillInGroupNameView(userID: userID, userPW: userPW, orgType: .student, subOrgType: .studentClub) } } label: { Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!(isCouncil || isClub) ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16) @@ -117,7 +117,10 @@ struct StudentTypeView: View { struct fillInGroupNameView: View { - @State var groupType: GroupType + @State var userID: String + @State var userPW: String + @State var orgType: OrgType + @State var subOrgType: SubOrgType? @State var groupName = "" @FocusState private var isTextFieldFocused: Bool var body: some View { @@ -140,14 +143,7 @@ struct fillInGroupNameView: View { Spacer() NavigationLink { - switch groupType { - case .company: - OnboardingCompletedView(groupType: .company, groupName: groupName) - case .studentCouncil: - OnboardingCompletedView(groupType: .studentCouncil, groupName: groupName) - case .studentClub: - OnboardingCompletedView(groupType: .studentClub, groupName: groupName) - } + OnboardingCompletedView(userID: userID, userPW: userPW, orgType: orgType, subOrgType: subOrgType, groupName: groupName) } label: { Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(groupName.isEmpty ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16) }.disabled(groupName.isEmpty) @@ -159,9 +155,15 @@ struct fillInGroupNameView: View { } struct OnboardingCompletedView: View { - @State var groupType: GroupType + @StateObject var joinViewModel = JoinViewModel() + + @State var userID: String + @State var userPW: String + @State var orgType: OrgType + @State var subOrgType: SubOrgType? @State var groupName: String @State var goToContentView = false + var body: some View { VStack(spacing: 0) { Spacer() @@ -181,15 +183,18 @@ struct OnboardingCompletedView: View { Button { goToContentView = true } label: { - Text("시작하기").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background( .sponusPrimary).padding(.bottom, 16) - }.fullScreenCover(isPresented: $goToContentView, content: { + Text("시작하기").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(joinViewModel.isButtonEnabled ? .sponusPrimary : .sponusGrey600).padding(.bottom, 16) + }.disabled(!joinViewModel.isButtonEnabled).fullScreenCover(isPresented: $goToContentView, content: { ContentView() }) }.padding(.horizontal, 20) .toolbar(.hidden, for: .navigationBar) + .onAppear() { + joinViewModel.postJoin(name: groupName, email: userID, password: userPW, orgType: orgType, subOrgType: subOrgType) + } } } -#Preview { - OnboardingCompletedView(groupType: .company, groupName: "") -} +//#Preview { +// OnboardingCompletedView(userID: "temp", userPW: "temp", orgType: .student, subOrgType: nil, groupName: "temp") +//}