-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/CategoryTab/#29
- Loading branch information
Showing
17 changed files
with
334 additions
and
40 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
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,13 @@ | ||
// | ||
// MyPage.swift | ||
// Hyangyu | ||
// | ||
// Created by 배소린 on 2022/02/07. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - message | ||
struct ModifyCheckData: Codable { | ||
let message: String | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageAPI.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,67 @@ | ||
// | ||
// MyPageAPI.swift | ||
// Hyangyu | ||
// | ||
// Created by 배소린 on 2022/02/07. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
public class MyPageAPI { | ||
|
||
static let shared = MyPageAPI() | ||
var myPageProvider = MoyaProvider<MyPageService>() | ||
|
||
public init() { } | ||
|
||
func modifyUserName(completion: @escaping (NetworkResult<Any>) -> Void, email: String, password: String, nickname: String) { | ||
myPageProvider.request(.modifyUserName(email: email, password: password, nickname: nickname)) { | ||
(result) in | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
let networkResult = self.judgeStatus(by: statusCode, data) | ||
completion(networkResult) | ||
|
||
case .failure(let err): | ||
print(err) | ||
} | ||
} | ||
} | ||
|
||
func getUserInfo(completion: @escaping (NetworkResult<Any>) -> Void) { | ||
myPageProvider.request(.getUserInfo) { (result) in | ||
print(result) | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
let networkResult = self.judgeStatus(by: statusCode, data) | ||
completion(networkResult) | ||
case .failure(let err): | ||
print(err) | ||
} | ||
} | ||
} | ||
|
||
private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<ModifyCheckData>.self, from: data as Data) | ||
else { | ||
return .pathErr | ||
} | ||
|
||
switch statusCode { | ||
case 200: | ||
return .success(decodedData.data) | ||
case 400..<500: | ||
return .requestErr(decodedData.message) | ||
case 500: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
Hyangyu/Hyangyu/Sources/APIServices/MyPageAPI/MyPageService.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,82 @@ | ||
// | ||
// MyPageService.swift | ||
// Hyangyu | ||
// | ||
// Created by 배소린 on 2022/02/07. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
enum MyPageService { | ||
|
||
case modifyUserName(email:String, password:String, nickname: String) | ||
|
||
case getUserInfo | ||
|
||
} | ||
|
||
extension MyPageService: TargetType, AccessTokenAuthorizable { | ||
var authorizationType: AuthorizationType? { | ||
return .bearer | ||
} | ||
|
||
var baseURL: URL { | ||
return URL(string: Const.URL.baseURL)! | ||
} | ||
var path: String { | ||
switch self { | ||
case .modifyUserName(_, _, _): | ||
return Const.URL.modifyUserName | ||
case .getUserInfo: | ||
return Const.URL.userView | ||
|
||
|
||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .modifyUserName(_, _, _): | ||
return .post | ||
case .getUserInfo: | ||
return .get | ||
|
||
} | ||
} | ||
|
||
var sampleData: Data { | ||
return Data() | ||
} | ||
|
||
|
||
var task: Task { | ||
switch self { | ||
case .modifyUserName(let email, let password, let nickname): | ||
return .requestParameters(parameters: [ | ||
"email": nil, | ||
"password": nil, | ||
"username": nickname, | ||
], encoding: JSONEncoding.default) | ||
case .getUserInfo: | ||
return .requestPlain | ||
|
||
} | ||
} | ||
|
||
var headers: [String: String]? { | ||
|
||
switch self { | ||
case .modifyUserName(_, _, _): | ||
return [ | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer \(UserDefaults.standard.string(forKey: "jwtToken") ?? "")" | ||
] | ||
case .getUserInfo: | ||
return [ | ||
"Authorization": "Bearer \(UserDefaults.standard.string(forKey: "jwtToken") ?? "")", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// User.swift | ||
// Hyangyu | ||
// | ||
// Created by 배소린 on 2022/02/07. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
class User { | ||
static let shared = User() | ||
|
||
var username: String? | ||
var profileImage: UIImage? | ||
} |
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.