-
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
560d532
commit f6332f2
Showing
26 changed files
with
517 additions
and
16 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
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,47 @@ | ||
import Moya | ||
import Domain | ||
import AppNetwork | ||
|
||
enum AuthAPI { | ||
case login(LoginRequestQuery) | ||
case signup(SignupRequestQuery) | ||
} | ||
|
||
extension AuthAPI: EmotingAPI { | ||
typealias ErrorType = Error | ||
|
||
var domain: EmotingDomain { | ||
.auth | ||
} | ||
|
||
var urlPath: String { | ||
switch self { | ||
case .login: | ||
return "/login" | ||
case .signup: | ||
return "/signup" | ||
} | ||
} | ||
|
||
var method: Method { | ||
return .post | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case let .login(req): | ||
return .requestJSONEncodable(req) | ||
|
||
case let .signup(req): | ||
return .requestJSONEncodable(req) | ||
} | ||
} | ||
|
||
var jwtTokenType: JwtTokenType { | ||
return .none | ||
} | ||
|
||
var errorMap: [Int: ErrorType]? { | ||
return nil | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Projects/Data/Sources/Auth/DataSource/Remote/RemoteAuthDataSource.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 @@ | ||
import RxSwift | ||
import Domain | ||
import AppNetwork | ||
|
||
protocol RemoteAuthDataSource { | ||
func login(req: LoginRequestQuery) -> Single<TokenDTO> | ||
func signup(req: SignupRequestQuery) -> Completable | ||
} | ||
|
||
final class RemoteAuthDataSourceImpl: RemoteBaseDataSource<AuthAPI>, RemoteAuthDataSource { | ||
func login(req: LoginRequestQuery) -> Single<TokenDTO> { | ||
return request(.login(req)) | ||
.map(TokenDTO.self) | ||
} | ||
|
||
func signup(req: SignupRequestQuery) -> Completable { | ||
return request(.signup(req)) | ||
.asCompletable() | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
Projects/Data/Sources/Auth/Repository/AuthRepositoryImpl.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,19 @@ | ||
import RxSwift | ||
import Domain | ||
|
||
struct AuthRepositoryImpl: AuthRepository { | ||
private let remoteAuthDataSource: any RemoteAuthDataSource | ||
|
||
init(remoteAuthDataSource: any RemoteAuthDataSource) { | ||
self.remoteAuthDataSource = remoteAuthDataSource | ||
} | ||
|
||
func login(req: Domain.LoginRequestQuery) -> RxSwift.Completable { | ||
remoteAuthDataSource.login(req: req) | ||
.asCompletable() | ||
} | ||
|
||
func signup(req: Domain.SignupRequestQuery) -> RxSwift.Completable { | ||
remoteAuthDataSource.signup(req: req) | ||
} | ||
} |
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,51 @@ | ||
import Moya | ||
import Domain | ||
import AppNetwork | ||
import Foundation | ||
import RxSwift | ||
import RxMoya | ||
import Core | ||
import Alamofire | ||
|
||
class RemoteBaseDataSource<API: EmotingAPI> { | ||
private let keychain: any Keychain | ||
|
||
private let provider: MoyaProvider<API> | ||
|
||
init(keychain: any Keychain) { | ||
self.keychain = keychain | ||
#if DEBUG | ||
self.provider = MoyaProvider<API>(plugins: [JwtPlugin(keychain: keychain), MoyaLogginPlugin()]) | ||
#else | ||
self.provider = MoyaProvider<API>(plugins: [JwtPlugin(keychain: keychain)]) | ||
#endif | ||
} | ||
|
||
func request(_ api: API) -> Single<Response> { | ||
return .create { single in | ||
var disposables: [Disposable] = [] | ||
disposables.append( | ||
self.defaultRequest(api) | ||
.subscribe( | ||
onSuccess: { single(.success($0)) }, | ||
onFailure: { single(.failure($0)) } | ||
) | ||
) | ||
return Disposables.create(disposables) | ||
} | ||
} | ||
} | ||
|
||
private extension RemoteBaseDataSource { | ||
func defaultRequest(_ api: API) -> Single<Response> { | ||
return provider.rx | ||
.request(api) | ||
.timeout(.seconds(120), scheduler: MainScheduler.asyncInstance) | ||
.catch { error in | ||
guard let code = (error as? MoyaError)?.response?.statusCode else { | ||
return .error(error) | ||
} | ||
return .error(api.errorMap?[code] ?? error) | ||
} | ||
} | ||
} |
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 @@ | ||
import Foundation | ||
import Swinject | ||
import Core | ||
import Domain | ||
|
||
public final class DataSourceAssembly: Assembly { | ||
public init() {} | ||
|
||
private let keychain = { (resolver: Resolver) in | ||
resolver.resolve(Keychain.self)! | ||
} | ||
|
||
public func assemble(container: Container) { | ||
container.register(RemoteAuthDataSource.self) { resolver in | ||
RemoteAuthDataSourceImpl(keychain: self.keychain(resolver)) | ||
} | ||
} | ||
} |
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 @@ | ||
import Foundation | ||
import Swinject | ||
import Domain | ||
|
||
public final class RepositoryAssembly: Assembly { | ||
public init() {} | ||
|
||
// swiftlint:disable function_body_length | ||
public func assemble(container: Container) { | ||
container.register(AuthRepository.self) { resolver in | ||
AuthRepositoryImpl(remoteAuthDataSource: resolver.resolve(RemoteAuthDataSource.self)!) | ||
} | ||
} | ||
// swiftlint:enable function_body_length | ||
} |
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,23 @@ | ||
import Foundation | ||
import Swinject | ||
import Domain | ||
|
||
public final class UseCaseAssembly: Assembly { | ||
public init() {} | ||
|
||
// swiftlint:disable function_body_length | ||
public func assemble(container: Container) { | ||
// Auth | ||
container.register(LoginUseCase.self) { resolver in | ||
LoginUseCase( | ||
authRepository: resolver.resolve(AuthRepository.self)! | ||
) | ||
} | ||
container.register(SignupUseCase.self) { resolver in | ||
SignupUseCase( | ||
authRepository: resolver.resolve(AuthRepository.self)! | ||
) | ||
} | ||
} | ||
// swiftlint:enable function_body_length | ||
} |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Projects/Domain/Sources/Auth/Parameter/LoginRequestQuery.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,11 @@ | ||
import Foundation | ||
|
||
public struct LoginRequestQuery: Encodable { | ||
public let email: String | ||
public let password: String | ||
|
||
public init(email: String, password: String) { | ||
self.email = email | ||
self.password = password | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Projects/Domain/Sources/Auth/Parameter/SignupRequestQuery.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 @@ | ||
import Foundation | ||
|
||
public struct SignupRequestQuery: Encodable { | ||
public let email: String | ||
public let password: String | ||
public let nickname: String | ||
public let age: Int | ||
|
||
public init(email: String, password: String, nickname: String, age: Int) { | ||
self.email = email | ||
self.password = password | ||
self.nickname = nickname | ||
self.age = age | ||
} | ||
} |
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,6 @@ | ||
import RxSwift | ||
|
||
public protocol AuthRepository { | ||
func login(req: LoginRequestQuery) -> Completable | ||
func signup(req: SignupRequestQuery) -> Completable | ||
} |
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 @@ | ||
import RxSwift | ||
|
||
public struct LoginUseCase { | ||
public init(authRepository: AuthRepository) { | ||
self.authRepository = authRepository | ||
} | ||
|
||
private let authRepository: AuthRepository | ||
|
||
public func execute(req: LoginRequestQuery) -> Completable { | ||
return authRepository.login(req: req) | ||
} | ||
} |
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 @@ | ||
import RxSwift | ||
|
||
public struct SignupUseCase { | ||
public init(authRepository: AuthRepository) { | ||
self.authRepository = authRepository | ||
} | ||
|
||
private let authRepository: AuthRepository | ||
|
||
public func execute(req: SignupRequestQuery) -> Completable { | ||
return authRepository.signup(req: req) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
Projects/Modules/AppNetwork/Sources/Plugin/EmotingAPI.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,45 @@ | ||
import Foundation | ||
import Moya | ||
|
||
public protocol EmotingAPI: TargetType, JwtAuthorizable { | ||
associatedtype ErrorType: Error | ||
var domain: EmotingDomain { get } | ||
var urlPath: String { get } | ||
var errorMap: [Int: ErrorType]? { get } | ||
} | ||
|
||
public extension EmotingAPI { | ||
var baseURL: URL { | ||
URL( | ||
string: "http://52.79.170.221:8080" | ||
) ?? URL(string: "https://www.google.com")! | ||
} | ||
|
||
var path: String { | ||
domain.asURLString + urlPath | ||
} | ||
|
||
var headers: [String: String]? { | ||
["Content-Type": "application/json"] | ||
} | ||
|
||
var validationType: ValidationType { | ||
return .successCodes | ||
} | ||
} | ||
|
||
public enum EmotingDomain: String { | ||
case auth | ||
} | ||
|
||
extension EmotingDomain { | ||
var asURLString: String { | ||
"/\(self.rawValue)" | ||
} | ||
} | ||
|
||
private class BundleFinder {} | ||
|
||
extension Foundation.Bundle { | ||
static let module = Bundle(for: BundleFinder.self) | ||
} |
10 changes: 10 additions & 0 deletions
10
Projects/Modules/AppNetwork/Sources/Plugin/Jwt/JwtAuthorizable.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,10 @@ | ||
import Moya | ||
|
||
public enum JwtTokenType: String { | ||
case accessToken = "Authorization" | ||
case none | ||
} | ||
|
||
public protocol JwtAuthorizable { | ||
var jwtTokenType: JwtTokenType { get } | ||
} |
Oops, something went wrong.