-
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
1 parent
453b4d0
commit 23146b0
Showing
7 changed files
with
165 additions
and
4 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
58 changes: 58 additions & 0 deletions
58
Umpah-iOS/Umpah-iOS/Network/APIServices/LoginService.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 @@ | ||
// | ||
// LoginService.swift | ||
// Umpah-iOS | ||
// | ||
// Created by SHIN YOON AH on 2022/02/19. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
enum LoginService{ | ||
case login(LoginRequest) | ||
case signup(SignupRequest) | ||
} | ||
|
||
extension LoginService: TargetType { | ||
var baseURL: URL { | ||
return URL(string: GeneralAPI.baseURL)! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .login: | ||
return "/auth/signin" | ||
case .signup: | ||
return "/auth/signup" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self{ | ||
case .login, | ||
.signup: | ||
return .post | ||
} | ||
} | ||
|
||
var sampleData: Data { | ||
return "@@".data(using: .utf8)! | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case .login(let param): | ||
return .requestJSONEncodable(param) | ||
case .signup(let param): | ||
return .requestJSONEncodable(param) | ||
} | ||
} | ||
|
||
var headers: [String : String]? { | ||
switch self { | ||
default: | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
Umpah-iOS/Umpah-iOS/Network/Model/Login/LoginRequest.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,16 @@ | ||
// | ||
// LoginRequest.swift | ||
// Umpah-iOS | ||
// | ||
// Created by SHIN YOON AH on 2022/02/19. | ||
// | ||
|
||
import Foundation | ||
|
||
struct LoginRequest: Codable { | ||
let phone: String | ||
|
||
init(phone: String) { | ||
self.phone = phone | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Umpah-iOS/Umpah-iOS/Network/Model/Login/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,18 @@ | ||
// | ||
// SignupRequest.swift | ||
// Umpah-iOS | ||
// | ||
// Created by SHIN YOON AH on 2022/02/19. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SignupRequest: Codable { | ||
let nickname: String | ||
let phone: String | ||
|
||
init(nickname: String, phone: String) { | ||
self.nickname = nickname | ||
self.phone = phone | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,4 +14,3 @@ struct DayRecordRequest: Codable { | |
self.date = date | ||
} | ||
} | ||
|
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,42 @@ | ||
// | ||
// LoginStorage.swift | ||
// Umpah-iOS | ||
// | ||
// Created by SHIN YOON AH on 2022/02/19. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
final class LoginStorage { | ||
|
||
// MARK: - Shared | ||
|
||
static let shared: LoginStorage = LoginStorage() | ||
|
||
// MARK: - Network | ||
|
||
private let authProvider = MoyaProvider<LoginService>(plugins: [NetworkLoggerPlugin(verbose: true)]) | ||
|
||
// MARK: - POST /auth/signup | ||
func dispatchSignUp(nickname: String, | ||
phone: String, | ||
completion: @escaping (() -> ())) { | ||
let param = SignupRequest(nickname: "최다인", phone: "01012345678") | ||
|
||
self.authProvider.request(.signup(param)) { response in | ||
switch response{ | ||
case .success(let result): | ||
do{ | ||
print(result) | ||
completion() | ||
}catch(let err){ | ||
print(err.localizedDescription) | ||
} | ||
case .failure(let err): | ||
print(err.localizedDescription) | ||
print("와 실패다!") | ||
} | ||
} | ||
} | ||
} |
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