-
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.
- Loading branch information
Showing
12 changed files
with
552 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
|
||
import Foundation | ||
|
||
struct EmptyResponseDTO: Codable { } | ||
public struct EmptyResponseDTO: Codable { } |
57 changes: 57 additions & 0 deletions
57
..._iOS/Projects/Features/MyPageFeature/Sources/Refactor_MyFeature/Service/API/AuthAPI.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,57 @@ | ||
// | ||
// AuthAPI.swift | ||
// MyPageFeatureInterface | ||
// | ||
// Created by 류희재 on 8/13/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
import Domain | ||
|
||
enum AuthAPI { | ||
case revoke | ||
case logout | ||
} | ||
|
||
extension AuthAPI: BaseAPI { | ||
public static var apiType: APIType = .auth | ||
|
||
var path: String { | ||
switch self { | ||
case .revoke: | ||
return "user" | ||
case .logout: | ||
return "user/logout" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .revoke: | ||
return .delete | ||
case .logout: | ||
return .post | ||
} | ||
} | ||
|
||
var task: Moya.Task { | ||
switch self { | ||
case .revoke: | ||
return .requestPlain | ||
case .logout: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
var validationType: ValidationType { | ||
switch self { | ||
case .revoke: | ||
return .successCodes | ||
case .logout: | ||
return .successCodes | ||
} | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
..._iOS/Projects/Features/MyPageFeature/Sources/Refactor_MyFeature/Service/AuthService.swift
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...jects/Features/MyPageFeature/Sources/Refactor_MyFeature/Service/Foundation/APIError.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 @@ | ||
// | ||
// APIError.swift | ||
// MyPageFeatureInterface | ||
// | ||
// Created by 류희재 on 8/13/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum APIError: Error, Equatable { | ||
case network(statusCode: Int, response: ErrorResponse) | ||
case unknown | ||
case tokenReissuanceFailed | ||
|
||
init(error: Error, statusCode: Int? = 0, response: ErrorResponse) { | ||
guard let statusCode else { self = .unknown ; return } | ||
|
||
self = .network(statusCode: statusCode, response: response) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ojects/Features/MyPageFeature/Sources/Refactor_MyFeature/Service/Foundation/BaseAPI.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,68 @@ | ||
// | ||
// BaseAPI.swift | ||
// MyPageFeatureInterface | ||
// | ||
// Created by 류희재 on 8/13/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Alamofire | ||
import Moya | ||
import Foundation | ||
import Core | ||
|
||
public enum APIType { | ||
case auth | ||
case user | ||
} | ||
|
||
public protocol BaseAPI: TargetType { | ||
static var apiType: APIType { get set } | ||
} | ||
|
||
extension BaseAPI { | ||
public var baseURL: URL { | ||
var base = "Config.Network.baseURL" | ||
let operationBaseURL = "Config.Network.operationBaseURL" | ||
|
||
switch Self.apiType { | ||
case .auth: | ||
base += "/auth" | ||
case .user: | ||
base += "/user" | ||
} | ||
|
||
guard let url = URL(string: base) else { | ||
fatalError("baseURL could not be configured") | ||
} | ||
|
||
return url | ||
} | ||
|
||
public var headers: [String: String]? { | ||
return HeaderType.jsonWithToken.value | ||
} | ||
|
||
public var validationType: ValidationType { | ||
return .customCodes(Array(200..<600).filter { $0 != 401 }) | ||
} | ||
} | ||
|
||
public enum HeaderType { | ||
case json | ||
case jsonWithToken | ||
case multipartWithToken | ||
|
||
public var value: [String: String] { | ||
switch self { | ||
case .json: | ||
return ["Content-Type": "application/json"] | ||
case .jsonWithToken: | ||
return ["Content-Type": "application/json", | ||
"Authorization": UserManager.shared.accessToken] | ||
case .multipartWithToken: | ||
return ["Content-Type": "multipart/form-data", | ||
"Authorization": UserManager.shared.accessToken] | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...cts/Features/MyPageFeature/Sources/Refactor_MyFeature/Service/Foundation/BaseEntity.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,26 @@ | ||
// | ||
// BaseEntity.swift | ||
// MyPageFeatureInterface | ||
// | ||
// Created by 류희재 on 8/13/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct BaseEntity<T: Decodable>: Decodable { | ||
public let success: Bool | ||
public let message: String | ||
public let data: T? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case success, message, data | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
success = try values.decode(Bool.self, forKey: .success) | ||
message = try values.decode(String.self, forKey: .message) | ||
data = try? values.decodeIfPresent(T.self, forKey: .data) | ||
} | ||
} |
Oops, something went wrong.