-
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
359 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// LogoutModel.swift | ||
// Spon-us | ||
// | ||
// Created by 박현수 on 2/15/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LogoutModel200: Codable { | ||
let statusCode, message, content: String | ||
} | ||
|
||
struct LogoutModel400: Codable { | ||
let statusCode, message: 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,47 @@ | ||
// | ||
// LogoutViewModel.swift | ||
// Spon-us | ||
// | ||
// Created by 박현수 on 2/15/24. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
class LogoutViewModel: ObservableObject { | ||
@Published var logoutModel200: LogoutModel200? | ||
@Published var logoutModel400: LogoutModel400? | ||
let provider = MoyaProvider<SponusAPI>(plugins: [NetworkLoggerPlugin()]) | ||
|
||
func getLogout(completion: @escaping (Bool) -> Void) { | ||
provider.request(.getLogout) { result in | ||
switch result { | ||
case let .success(response): | ||
switch response.statusCode { | ||
case 200: | ||
do { | ||
let logoutResponse = try response.map(LogoutModel200.self) | ||
self.logoutModel200 = logoutResponse | ||
completion(true) | ||
} | ||
catch { | ||
print("200Error") | ||
} | ||
case 400: | ||
do { | ||
let logoutResponse = try response.map(LogoutModel400.self) | ||
self.logoutModel400 = logoutResponse | ||
completion(false) | ||
} | ||
catch { | ||
print("400Error") | ||
} | ||
default: | ||
print("Unexpected StatusCode") | ||
} | ||
case let .failure(response): | ||
print("response 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
Oops, something went wrong.