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
16 changed files
with
303 additions
and
91 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 @@ | ||
// | ||
// SignUpAPI.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
import Accelerate | ||
|
||
final class SignUpAPI { | ||
|
||
// MARK: - Static Properties | ||
|
||
static let shared: SignUpAPI = SignUpAPI() | ||
private init() { } | ||
|
||
// MARK: - Network Properties | ||
|
||
var authProvider = MoyaProvider<SignUpService>(plugins: [MoyaLoggerPlugin()]) | ||
|
||
public private(set) var signUpResponse: BaseResponse<SignUpResponse>? | ||
public private(set) var signUpData: SignUpResponse? | ||
|
||
// MARK: - GET | ||
|
||
func signUp(parameter: SignUpRequest, completion: @escaping ((SignUpResponse?, Error?) -> ())) { | ||
authProvider.request(.signUp(parameter: parameter)) { [weak self] response in | ||
switch response { | ||
case .success(let result): | ||
do { | ||
self?.signUpResponse = try result.map(BaseResponse<SignUpResponse>.self) | ||
guard let data = self?.signUpResponse?.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) | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Instagram/Instagram/Network/DataModel/Auth/SignInRequest.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,14 @@ | ||
// | ||
// SignInRequest.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - SignUp Request | ||
|
||
struct SignInRequest: Codable { | ||
let email, password: String | ||
} |
14 changes: 14 additions & 0 deletions
14
Instagram/Instagram/Network/DataModel/Auth/SignInResponse.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,14 @@ | ||
// | ||
// SignInResponse.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - SignIn Response | ||
|
||
struct SignInResponse: Codable { | ||
let name, email: String | ||
} |
14 changes: 14 additions & 0 deletions
14
Instagram/Instagram/Network/DataModel/Auth/SignUpRequest.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,14 @@ | ||
// | ||
// SignUpRequest.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - SignUp Request | ||
|
||
struct SignUpRequest: Codable { | ||
let name, email, password: String | ||
} |
15 changes: 15 additions & 0 deletions
15
Instagram/Instagram/Network/DataModel/Auth/SignUpResponse.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,15 @@ | ||
// | ||
// SignUpResponse.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - SignUp Response | ||
|
||
struct SignUpResponse: Codable { | ||
let id: Int | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
Instagram/Instagram/Network/Service/Auth/SignUpService.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,58 @@ | ||
// | ||
// AuthService.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
enum SignUpService { | ||
case signUp(parameter: SignUpRequest) | ||
} | ||
|
||
extension SignUpService: TargetType { | ||
var baseURL: URL { | ||
return URL(string: GeneralAPI.baseURL)! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .signUp: | ||
return GeneralAPI.signUpURL | ||
} | ||
} | ||
|
||
var parameterEncoding: ParameterEncoding { | ||
switch self { | ||
case .signUp: | ||
return JSONEncoding.default | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .signUp: | ||
return .post | ||
} | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case .signUp(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 .signUp: | ||
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
Oops, something went wrong.