Skip to content

Commit 4a5c28a

Browse files
committed
[#73] 회원가입 API연동 완료
1 parent d2f94f3 commit 4a5c28a

File tree

7 files changed

+147
-28
lines changed

7 files changed

+147
-28
lines changed

Spon-us.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
DF90A5BE2B6E39A600BC54D0 /* RegisterPWView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5BD2B6E39A600BC54D0 /* RegisterPWView.swift */; };
7474
DF90A5C02B6E534500BC54D0 /* SelectUserTypeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF90A5BF2B6E534500BC54D0 /* SelectUserTypeView.swift */; };
7575
DF91F4042B4864330021291A /* Portfolio.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF91F4032B4864330021291A /* Portfolio.swift */; };
76+
DFB22ED72B766FF3007903DF /* JoinModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB22ED62B766FF3007903DF /* JoinModel.swift */; };
77+
DFB22ED92B767003007903DF /* JoinViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB22ED82B767003007903DF /* JoinViewModel.swift */; };
7678
DFCD247C2B54D08100B00515 /* PopupView in Frameworks */ = {isa = PBXBuildFile; productRef = DFCD247B2B54D08100B00515 /* PopupView */; };
7779
DFCD24822B5A67FC00B00515 /* DocumentPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFCD24812B5A67FC00B00515 /* DocumentPicker.swift */; };
7880
/* End PBXBuildFile section */
@@ -140,6 +142,8 @@
140142
DF90A5BD2B6E39A600BC54D0 /* RegisterPWView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterPWView.swift; sourceTree = "<group>"; };
141143
DF90A5BF2B6E534500BC54D0 /* SelectUserTypeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectUserTypeView.swift; sourceTree = "<group>"; };
142144
DF91F4032B4864330021291A /* Portfolio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Portfolio.swift; sourceTree = "<group>"; };
145+
DFB22ED62B766FF3007903DF /* JoinModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinModel.swift; sourceTree = "<group>"; };
146+
DFB22ED82B767003007903DF /* JoinViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinViewModel.swift; sourceTree = "<group>"; };
143147
DFCD24812B5A67FC00B00515 /* DocumentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentPicker.swift; sourceTree = "<group>"; };
144148
/* End PBXFileReference section */
145149

@@ -174,6 +178,8 @@
174178
children = (
175179
100A1E372B734DB200AAC1E8 /* EmailModel.swift */,
176180
100A1E392B734DDE00AAC1E8 /* EmailViewModel.swift */,
181+
DFB22ED62B766FF3007903DF /* JoinModel.swift */,
182+
DFB22ED82B767003007903DF /* JoinViewModel.swift */,
177183
);
178184
path = Onboarding;
179185
sourceTree = "<group>";
@@ -502,6 +508,7 @@
502508
100D38B32B4EF15600498977 /* HomeView.swift in Sources */,
503509
10C8AC632B5C34C400B40547 /* CompanyPostView.swift in Sources */,
504510
DF3AD3DF2B61626300DBFCCC /* OnBoardingView.swift in Sources */,
511+
DFB22ED92B767003007903DF /* JoinViewModel.swift in Sources */,
505512
100A1E302B71637A00AAC1E8 /* MyProfileView.swift in Sources */,
506513
3BFC8D1F2B5597C9000D6006 /* ProfileView.swift in Sources */,
507514
3B36F09C2B6FEBA00000ACFB /* ChargerInfoViewTest.swift in Sources */,
@@ -524,6 +531,7 @@
524531
3B36F0A82B6FEC3C0000ACFB /* PubData.swift in Sources */,
525532
3B36F09A2B6FEB800000ACFB /* PaymentSettingView.swift in Sources */,
526533
DFCD24822B5A67FC00B00515 /* DocumentPicker.swift in Sources */,
534+
DFB22ED72B766FF3007903DF /* JoinModel.swift in Sources */,
527535
3B36F0A32B6FEC0B0000ACFB /* PortOneViewModel.swift in Sources */,
528536
3B36F09E2B6FEBBC0000ACFB /* PaymentView.swift in Sources */,
529537
80FA316D2B5EBA6B0076453B /* SearchOfferView.swift in Sources */,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// JoinModel.swift
3+
// Spon-us
4+
//
5+
// Created by 박현수 on 2/9/24.
6+
//
7+
8+
import Foundation
9+
10+
struct JoinContent: Codable {
11+
let id: Int
12+
let email, name: String
13+
}
14+
15+
struct JoinModel: Codable {
16+
let statusCode, message: String
17+
let content: JoinContent
18+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// JoinViewModel.swift
3+
// Spon-us
4+
//
5+
// Created by 박현수 on 2/9/24.
6+
//
7+
8+
import Foundation
9+
import Combine
10+
import Moya
11+
12+
class JoinViewModel: ObservableObject {
13+
@Published var join: JoinModel?
14+
@Published var isButtonEnabled = false
15+
private let provider = MoyaProvider<SponusAPI>(plugins: [NetworkLoggerPlugin()])
16+
17+
func postJoin(name: String, email: String, password: String, orgType: OrgType, subOrgType: SubOrgType?) {
18+
provider.request(.postJoin(name: name, email: email, password: password, orgType: orgType, subOrgType: subOrgType)) { result in
19+
switch result {
20+
case let .success(response):
21+
do {
22+
if response.statusCode == 200 {
23+
self.isButtonEnabled = true
24+
}
25+
print(self.isButtonEnabled)
26+
print(try response.mapJSON())
27+
let joinResponse = try response.map(JoinModel.self)
28+
self.join = joinResponse
29+
} catch {
30+
print("Error parsing response: \(error)")
31+
}
32+
33+
case let .failure(error):
34+
print("Network request failed: \(error)")
35+
}
36+
}
37+
}
38+
}

Spon-us/SponusAPI.swift

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,25 @@ import Foundation
99
import Moya
1010
import KeychainSwift
1111

12+
enum OrgType {
13+
case student, company
14+
}
15+
16+
enum SubOrgType {
17+
case studentCouncil, studentClub
18+
}
19+
20+
struct JoinRequestBody: Codable {
21+
let name: String
22+
let email: String
23+
let password: String
24+
let organizationType: String
25+
let suborganizationType: String?
26+
}
27+
1228
enum SponusAPI {
1329
case postEmail(email: String)
30+
case postJoin(name: String, email: String, password: String, orgType: OrgType, subOrgType: SubOrgType?)
1431
}
1532

1633
extension SponusAPI: TargetType {
@@ -20,22 +37,37 @@ extension SponusAPI: TargetType {
2037

2138
var path: String {
2239
switch self {
23-
case .postEmail(let email):
40+
case .postEmail:
2441
return "/api/v1/organizations/email"
42+
case .postJoin:
43+
return "/api/v1/organizations/join"
2544
}
2645
}
2746

2847
var method: Moya.Method {
2948
switch self {
3049
case .postEmail:
3150
return .post
51+
case .postJoin:
52+
return .post
3253
}
3354
}
3455

3556
var sampleData: Data {
3657
switch self {
3758
case .postEmail:
3859
return Data()
60+
case .postJoin:
61+
let response: [String : Any] = [
62+
"statusCode": "OK",
63+
"message": "OK",
64+
"content": [
65+
"id": 0,
66+
"email": "[email protected]",
67+
"name": "test"
68+
]
69+
]
70+
return try! JSONSerialization.data(withJSONObject: response, options: .prettyPrinted)
3971
}
4072
}
4173

@@ -44,13 +76,30 @@ extension SponusAPI: TargetType {
4476
case .postEmail(let email):
4577
let parameters: [String: Any] = ["email": email]
4678
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
79+
case .postJoin(let name, let email, let password, let orgType, let subOrgType):
80+
switch orgType {
81+
case .student:
82+
switch subOrgType! {
83+
case .studentCouncil:
84+
let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: "STUDENT_COUNCIL")
85+
return .requestJSONEncodable(requestBody)
86+
case .studentClub:
87+
let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: "STUDENT_CLUB")
88+
return .requestJSONEncodable(requestBody)
89+
}
90+
case .company:
91+
let requestBody = JoinRequestBody(name: name, email: email, password: password, organizationType: "STUDENT", suborganizationType: nil)
92+
return .requestJSONEncodable(requestBody)
93+
}
4794
}
4895
}
4996

5097
var headers: [String: String]? {
5198
switch self {
5299
case .postEmail:
53100
return nil
101+
case .postJoin:
102+
return nil
54103
/*
55104
case .postLike:
56105
return ["Content-Type": "application/json",

Spon-us/View/Onboarding/RegisterIDView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ struct RegisterIDView: View {
169169
Spacer()
170170

171171
NavigationLink {
172-
RegisterPWView()
172+
RegisterPWView(userID: userID)
173173
} label: {
174174
Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!isAuthenticated ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16)
175-
}.disabled(!isAuthenticated)
175+
}//.disabled(!isAuthenticated)
176176
}.navigationBarTitleDisplayMode(.inline)
177177
.navigationBarBackButtonHidden(true)
178178
.navigationBarItems(leading: CustomBackButton())

Spon-us/View/Onboarding/RegisterPWView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99

1010
struct RegisterPWView: View {
11+
@State var userID: String
1112
@State private var userPW = ""
1213
@State private var userPWConfirm = ""
1314
@State private var isPWSecure = true
@@ -98,7 +99,7 @@ struct RegisterPWView: View {
9899
}
99100
Spacer()
100101
NavigationLink {
101-
SelectUserTypeView()
102+
SelectUserTypeView(userID: userID, userPW: userPW)
102103
} label: {
103104
Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(!isValidPW ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16)
104105
}.disabled(!isValidPW)
@@ -110,5 +111,5 @@ struct RegisterPWView: View {
110111
}
111112

112113
#Preview {
113-
RegisterPWView()
114+
RegisterPWView(userID: "temp")
114115
}

Spon-us/View/Onboarding/SelectUserTypeView.swift

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
import SwiftUI
99

10-
enum GroupType {
11-
case studentCouncil, studentClub, company
12-
}
13-
1410
struct SelectUserTypeView: View {
11+
@State var userID: String
12+
@State var userPW: String
1513
@State var isStudent = false
1614
@State var isCompany = false
1715

@@ -48,10 +46,10 @@ struct SelectUserTypeView: View {
4846
Spacer()
4947
NavigationLink {
5048
if isStudent {
51-
StudentTypeView()
49+
StudentTypeView(userID: userID, userPW: userPW)
5250
}
5351
else {
54-
fillInGroupNameView(groupType: .company)
52+
fillInGroupNameView(userID: userID, userPW: userPW, orgType: .company, subOrgType: nil)
5553
}
5654
} label: {
5755
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 {
6462
}
6563

6664
struct StudentTypeView: View {
65+
@State var userID: String
66+
@State var userPW: String
6767
@State var isCouncil = false
6868
@State var isClub = false
6969

@@ -100,10 +100,10 @@ struct StudentTypeView: View {
100100
Spacer()
101101
NavigationLink {
102102
if isCouncil {
103-
fillInGroupNameView(groupType: .studentCouncil)
103+
fillInGroupNameView(userID: userID, userPW: userPW, orgType: .student, subOrgType: .studentCouncil)
104104
}
105105
else {
106-
fillInGroupNameView(groupType: .studentClub)
106+
fillInGroupNameView(userID: userID, userPW: userPW, orgType: .student, subOrgType: .studentClub)
107107
}
108108
} label: {
109109
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 {
117117

118118

119119
struct fillInGroupNameView: View {
120-
@State var groupType: GroupType
120+
@State var userID: String
121+
@State var userPW: String
122+
@State var orgType: OrgType
123+
@State var subOrgType: SubOrgType?
121124
@State var groupName = ""
122125
@FocusState private var isTextFieldFocused: Bool
123126
var body: some View {
@@ -140,14 +143,7 @@ struct fillInGroupNameView: View {
140143

141144
Spacer()
142145
NavigationLink {
143-
switch groupType {
144-
case .company:
145-
OnboardingCompletedView(groupType: .company, groupName: groupName)
146-
case .studentCouncil:
147-
OnboardingCompletedView(groupType: .studentCouncil, groupName: groupName)
148-
case .studentClub:
149-
OnboardingCompletedView(groupType: .studentClub, groupName: groupName)
150-
}
146+
OnboardingCompletedView(userID: userID, userPW: userPW, orgType: orgType, subOrgType: subOrgType, groupName: groupName)
151147
} label: {
152148
Text("다음").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(groupName.isEmpty ? .sponusGrey600 : .sponusPrimary).padding(.bottom, 16)
153149
}.disabled(groupName.isEmpty)
@@ -159,9 +155,15 @@ struct fillInGroupNameView: View {
159155
}
160156

161157
struct OnboardingCompletedView: View {
162-
@State var groupType: GroupType
158+
@StateObject var joinViewModel = JoinViewModel()
159+
160+
@State var userID: String
161+
@State var userPW: String
162+
@State var orgType: OrgType
163+
@State var subOrgType: SubOrgType?
163164
@State var groupName: String
164165
@State var goToContentView = false
166+
165167
var body: some View {
166168
VStack(spacing: 0) {
167169
Spacer()
@@ -181,15 +183,18 @@ struct OnboardingCompletedView: View {
181183
Button {
182184
goToContentView = true
183185
} label: {
184-
Text("시작하기").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background( .sponusPrimary).padding(.bottom, 16)
185-
}.fullScreenCover(isPresented: $goToContentView, content: {
186+
Text("시작하기").font(.Body04).frame(maxWidth: .infinity).frame(height: 56).foregroundStyle(.sponusWhite).background(joinViewModel.isButtonEnabled ? .sponusPrimary : .sponusGrey600).padding(.bottom, 16)
187+
}.disabled(!joinViewModel.isButtonEnabled).fullScreenCover(isPresented: $goToContentView, content: {
186188
ContentView()
187189
})
188190
}.padding(.horizontal, 20)
189191
.toolbar(.hidden, for: .navigationBar)
192+
.onAppear() {
193+
joinViewModel.postJoin(name: groupName, email: userID, password: userPW, orgType: orgType, subOrgType: subOrgType)
194+
}
190195
}
191196
}
192197

193-
#Preview {
194-
OnboardingCompletedView(groupType: .company, groupName: "")
195-
}
198+
//#Preview {
199+
// OnboardingCompletedView(userID: "temp", userPW: "temp", orgType: .student, subOrgType: nil, groupName: "temp")
200+
//}

0 commit comments

Comments
 (0)