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
122 changed files
with
19,214 additions
and
2,381 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// SignUpAPI.swift | ||
// | ||
// Created by 소연 on 2022/05/10. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
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) | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
// | ||
// HomeAPI.swift | ||
// | ||
// Created by 소연 on 2022/05/13. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
final class HomeAPI { | ||
|
||
// MARK: - Static Properties | ||
|
||
static let shared: HomeAPI = HomeAPI() | ||
private init() { } | ||
|
||
// MARK: - Network Properties | ||
|
||
private let homeProvider = MoyaProvider<HomeService>(plugins: [MoyaLoggerPlugin()]) | ||
|
||
public private(set) var homeResponse: BaseArrayResponseType<HomeResponse>? | ||
public private(set) var homeData: [HomeResponse]? | ||
|
||
func getImageList(completion: @escaping (([HomeResponse]?, Error?) -> ())) { | ||
homeProvider.request(.imageList) { [weak self] response in | ||
guard let self = self else { return } | ||
switch response { | ||
case .success(let result): | ||
do { | ||
self.homeResponse = try result.map(BaseArrayResponseType<HomeResponse>.self) | ||
guard let data = self.homeResponse?.data else { | ||
completion(nil, Error.self as? Error) | ||
return | ||
} | ||
self.homeData = data | ||
|
||
completion(data, nil) | ||
} catch(let err) { | ||
print(err.localizedDescription) | ||
completion(nil, err) | ||
} | ||
case .failure(let err): | ||
print(err.localizedDescription) | ||
completion(nil, err) | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
Instagram/Instagram/Network/APIModel/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 | ||
} |
14 changes: 14 additions & 0 deletions
14
Instagram/Instagram/Network/APIModel/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/APIModel/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/APIModel/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/APIModel/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 | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
Instagram/Instagram/Network/APIModel/Home/HomeResponse.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,21 @@ | ||
// | ||
// HomeResponse.swift | ||
// | ||
// Created by 소연 on 2022/05/13. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - HomeResponse | ||
|
||
struct HomeResponse: Codable { | ||
let id, author: String | ||
let width, height: Int | ||
let url, downloadURL: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id, author, width, height, url | ||
case downloadURL = "download_url" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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"] | ||
} | ||
} | ||
} | ||
|
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"] | ||
} | ||
} | ||
} |
Oops, something went wrong.