generated from 30th-THE-SOPT-iOS-Part/KimTaeHyeon
-
Notifications
You must be signed in to change notification settings - Fork 0
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
157 additions
and
21 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,50 @@ | ||
// | ||
// SignInAPI.swift | ||
// | ||
// Created by 소연 on 2022/05/13. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
final class SignInAPI { | ||
|
||
// MARK: - Static Properties | ||
|
||
static let shared: SignInAPI = SignInAPI() | ||
private init() { } | ||
|
||
// MARK: - Network Properties | ||
|
||
var authProvider = MoyaProvider<SignInService>(plugins: [MoyaLoggerPlugin()]) | ||
|
||
public private(set) var signInResponse: BaseResponse<SignInResponse>? | ||
public private(set) var signUpData: SignInResponse? | ||
|
||
// MARK: - GET | ||
|
||
func signUp(parameter: AuthRequest, completion: @escaping ((SignInResponse?, Error?) -> ())) { | ||
authProvider.request(.signIn(parameter: parameter)) { [weak self] response in | ||
switch response { | ||
case .success(let result): | ||
do { | ||
self?.signInResponse = try result.map(BaseResponse<SignInResponse>.self) | ||
guard let data = self?.signInResponse?.data else { | ||
completion(nil, Error.self as? Error) | ||
return | ||
} | ||
completion(data, nil) | ||
} catch(let err) { | ||
print(err.localizedDescription) | ||
completion(nil, err) | ||
} | ||
case .failure(let err): | ||
print(err.localizedDescription) | ||
completion(nil, err) | ||
} | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
import Foundation | ||
|
||
import Moya | ||
import Accelerate | ||
|
||
final class SignUpAPI { | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
Instagram/Instagram/Network/DataModel/Auth/AuthRequest.swift
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,12 @@ | ||
// | ||
// AuthRequest.swift | ||
// | ||
// Created by 소연 on 2022/05/13. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AuthRequest: Codable { | ||
let name, email, password: String | ||
} |
59 changes: 59 additions & 0 deletions
59
Instagram/Instagram/Network/Service/Auth/SignInService.swift
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,59 @@ | ||
// | ||
// SignInService.swift | ||
// | ||
// Created by 소연 on 2022/05/13. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
enum SignInService { | ||
case signIn(parameter: AuthRequest) | ||
} | ||
|
||
extension SignInService: TargetType { | ||
var baseURL: URL { | ||
return URL(string: GeneralAPI.baseURL)! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .signIn: | ||
return GeneralAPI.signInURL | ||
} | ||
} | ||
|
||
var parameterEncoding: ParameterEncoding { | ||
switch self { | ||
case .signIn: | ||
return JSONEncoding.default | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .signIn: | ||
return .post | ||
} | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case .signIn(let parameter): | ||
let parameter: [String: Any] = ["name": parameter.name, | ||
"email": parameter.email, | ||
"password": parameter.password] | ||
return .requestParameters(parameters: parameter, encoding: JSONEncoding.default) | ||
} | ||
} | ||
|
||
var headers: [String : String]? { | ||
switch self { | ||
case .signIn: | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
} | ||
|
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