-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// LoginModel.swift | ||
// Spon-us | ||
// | ||
// Created by 박현수 on 2/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LoginModelContent200: Codable { | ||
let accessToken: String | ||
let refreshToken: String | ||
} | ||
|
||
struct LoginModel200: Codable { | ||
let statusCode: String | ||
let message: String | ||
let content: LoginModelContent200 | ||
} | ||
|
||
struct LoginModel401: Codable { | ||
let statusCode: String | ||
let message: String | ||
let content: String | ||
} | ||
|
||
struct LoginRequestBody: Codable { | ||
let email: String | ||
let password: String | ||
let fcmToken: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// LoginViewModel.swift | ||
// Spon-us | ||
// | ||
// Created by 박현수 on 2/12/24. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
class LoginViewModel: ObservableObject { | ||
@Published var login200: LoginModel200? | ||
@Published var login401: LoginModel401? | ||
|
||
private let provider = MoyaProvider<SponusAPI>(plugins: [NetworkLoggerPlugin()]) | ||
|
||
func postLogin(email: String, password: String, fcmToken: String) { | ||
provider.request(.postLogin(email: email, password: password, fcmToken: fcmToken)) { result in | ||
switch result { | ||
case let .success(response): | ||
do { | ||
if response.statusCode == 200 { | ||
let loginResponse = try response.map(LoginModel200.self) | ||
self.login200 = loginResponse | ||
} | ||
else { | ||
let loginResponse = try response.map(LoginModel401.self) | ||
self.login401 = loginResponse | ||
} | ||
} catch { | ||
print("Error parsing response: \(error)") | ||
} | ||
|
||
case let .failure(error): | ||
print("Network request failed: \(error)") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters