From f2a6a7d28f088ac4c6eb14a40a8df676e666ddf4 Mon Sep 17 00:00:00 2001 From: leedoyeon849 Date: Wed, 14 Aug 2024 01:00:07 +0900 Subject: [PATCH] feat(MemberData): Add login method to MemberRepository --- .../Container/Sources/Contaner+Shared.swift | 23 ++++++++++ .../Container/Sources/Sample.swift | 1 - Projects/DI/ContainerDIModule/Project.swift | 6 +-- .../Repository/MemberRepositoryImpl.swift | 44 +++++++++++++++++- Projects/Data/MemberDataModule/Project.swift | 5 +-- .../Sources/MemberRepository.swift | 18 +++++--- .../MemberDataInterfaceModule/Project.swift | 4 +- .../Sources/AppleLoginUsecase.swift | 45 +++++++++++++++++++ .../Domain/MemberDomainModule/Project.swift | 7 ++- .../SignupExample/SignupExample.entitlements | 10 +++++ .../Sources/AppleSignInButton.swift | 1 + .../Project+Templates.swift | 2 +- 12 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 Projects/DI/ContainerDIModule/Container/Sources/Contaner+Shared.swift delete mode 100644 Projects/DI/ContainerDIModule/Container/Sources/Sample.swift create mode 100644 Projects/Domain/MemberDomainModule/MemberUsecase/Sources/AppleLoginUsecase.swift create mode 100644 Projects/Example/SignupExampleModule/SignupExample/SignupExample.entitlements diff --git a/Projects/DI/ContainerDIModule/Container/Sources/Contaner+Shared.swift b/Projects/DI/ContainerDIModule/Container/Sources/Contaner+Shared.swift new file mode 100644 index 00000000..bffb2cc6 --- /dev/null +++ b/Projects/DI/ContainerDIModule/Container/Sources/Contaner+Shared.swift @@ -0,0 +1,23 @@ +// +// Contaner+Shared.swift +// Container +// +// Created by DOYEON LEE on 8/14/24. +// + +import Swinject + +import MemberDataInterface +import MemberData + +public extension Container { + static let shared: Container = { + let container = Container() + + container.register(MemberRepository.self) { _ in + MemberRepositoryImpl() + } + + return container + }() +} diff --git a/Projects/DI/ContainerDIModule/Container/Sources/Sample.swift b/Projects/DI/ContainerDIModule/Container/Sources/Sample.swift deleted file mode 100644 index 8b137891..00000000 --- a/Projects/DI/ContainerDIModule/Container/Sources/Sample.swift +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Projects/DI/ContainerDIModule/Project.swift b/Projects/DI/ContainerDIModule/Project.swift index c69138c9..e2a79d68 100644 --- a/Projects/DI/ContainerDIModule/Project.swift +++ b/Projects/DI/ContainerDIModule/Project.swift @@ -4,16 +4,14 @@ import ProjectDescriptionHelpers let project = Project.makeDIModule( .container, dependencies: [ - // entity - .entity(.organization), - .entity(.announcement), - .entity(.todo), // data interface .dataInterface(.organization), .dataInterface(.announcement), + .dataInterface(.member), // data .data(.organization), .data(.announcement), + .data(.member), // third party .thirdParty(.swinject), .thirdParty(.rxSwift) diff --git a/Projects/Data/MemberDataModule/MemberData/Sources/Repository/MemberRepositoryImpl.swift b/Projects/Data/MemberDataModule/MemberData/Sources/Repository/MemberRepositoryImpl.swift index 9b0d7406..7881c0b7 100644 --- a/Projects/Data/MemberDataModule/MemberData/Sources/Repository/MemberRepositoryImpl.swift +++ b/Projects/Data/MemberDataModule/MemberData/Sources/Repository/MemberRepositoryImpl.swift @@ -22,7 +22,7 @@ public struct MemberRepositoryImpl: MemberRepository { public init() {} - public func getMember(param: GetMemberParam) -> Observable { + public func getMember(_ param: GetMemberParam) -> Observable { return Observable.create { observer in Task { do { @@ -42,4 +42,46 @@ public struct MemberRepositoryImpl: MemberRepository { return Disposables.create() } } + + public func login(_ param: LoginParam) -> Observable { + return Observable.create { observer in + Task { + do { + let response = try await client.login(param) + + if let data = try response.ok.body.json.data { + observer.onNext(data) + observer.onCompleted() + } else { + observer.onError(MemberError.invalidResponse) + } + } catch { + observer.onError(MemberError.underlying(error)) + } + } + + return Disposables.create() + } + } + + public func reissue(_ param: ReissueParam) -> Observable { + return Observable.create { observer in + Task { + do { + let response = try await client.reissue(param) + + if let data = try response.ok.body.json.data { + observer.onNext(data) + observer.onCompleted() + } else { + observer.onError(MemberError.invalidResponse) + } + } catch { + observer.onError(MemberError.underlying(error)) + } + } + + return Disposables.create() + } + } } diff --git a/Projects/Data/MemberDataModule/Project.swift b/Projects/Data/MemberDataModule/Project.swift index 97657412..0816ada6 100644 --- a/Projects/Data/MemberDataModule/Project.swift +++ b/Projects/Data/MemberDataModule/Project.swift @@ -3,8 +3,5 @@ import ProjectDescriptionHelpers let project = Project.makeDataModule( .member, - dependencies: [ - .entity(.member), - .dataInterface(.member) - ] + dependencies: [.dataInterface(.member)] ) diff --git a/Projects/DataInterface/MemberDataInterfaceModule/MemberDataInterface/Sources/MemberRepository.swift b/Projects/DataInterface/MemberDataInterfaceModule/MemberDataInterface/Sources/MemberRepository.swift index fc5fced0..fc510e71 100644 --- a/Projects/DataInterface/MemberDataInterfaceModule/MemberDataInterface/Sources/MemberRepository.swift +++ b/Projects/DataInterface/MemberDataInterfaceModule/MemberDataInterface/Sources/MemberRepository.swift @@ -7,13 +7,21 @@ import OpenapiGenerated +import RxSwift + public typealias GetMemberParam = Operations.getMember.Input public typealias GetMemberResult = Components.Schemas.MemberResponse -public protocol MemberRepository { - -} - - +public typealias LoginParam = Operations.login.Input +public typealias LoginResult = Components.Schemas.SocialAuthResponse +public typealias ReissueParam = Operations.reissue.Input +public typealias ReissueResult = Components.Schemas.TokenResponse +public protocol MemberRepository { + func getMember(_ param: GetMemberParam) -> Observable + + func login(_ param: LoginParam) -> Observable + + func reissue(_ param: ReissueParam) -> Observable +} diff --git a/Projects/DataInterface/MemberDataInterfaceModule/Project.swift b/Projects/DataInterface/MemberDataInterfaceModule/Project.swift index 2d6897da..a57a7c58 100644 --- a/Projects/DataInterface/MemberDataInterfaceModule/Project.swift +++ b/Projects/DataInterface/MemberDataInterfaceModule/Project.swift @@ -3,7 +3,5 @@ import ProjectDescriptionHelpers let project = Project.makeDataInterfaceModule( .member, - dependencies: [ - .entity(.member) - ] + dependencies: [] ) diff --git a/Projects/Domain/MemberDomainModule/MemberUsecase/Sources/AppleLoginUsecase.swift b/Projects/Domain/MemberDomainModule/MemberUsecase/Sources/AppleLoginUsecase.swift new file mode 100644 index 00000000..7044f7be --- /dev/null +++ b/Projects/Domain/MemberDomainModule/MemberUsecase/Sources/AppleLoginUsecase.swift @@ -0,0 +1,45 @@ +// +// AppleLoginUsecase.swift +// MemberUsecase +// +// Created by DOYEON LEE on 8/14/24. +// + +import Container +import MemberEntity +import MemberDataInterface + +import Swinject +import RxSwift + +public struct AppleLoginUsecase { + // MARK: DTO + public struct Param { + let authorizationCode: String // TODO: 추후 가능하면 identityToken으로 변경 + } + + public struct Result { + + } + + // MARK: Dependency + let memberRepository = Container.shared.resolve(MemberRepository.self)! + + // MARK: Initializer + public init() { } + + // MARK: Execute method + public func execute(_ param: Param) -> Observable { + let requestParam: LoginParam = .init( + body: .json( + .init( + provider: .APPLE, + code: param.authorizationCode + ) + ) + ) + + return memberRepository.login(requestParam) + .map { _ in Result() } + } +} diff --git a/Projects/Domain/MemberDomainModule/Project.swift b/Projects/Domain/MemberDomainModule/Project.swift index 7ab54e13..a2c5e51f 100644 --- a/Projects/Domain/MemberDomainModule/Project.swift +++ b/Projects/Domain/MemberDomainModule/Project.swift @@ -1,4 +1,9 @@ import ProjectDescription import ProjectDescriptionHelpers -let project = Project.makeDomainModule(.member) +let project = Project.makeDomainModule( + .member, + dependencies: [ + .di(.container) + ] +) diff --git a/Projects/Example/SignupExampleModule/SignupExample/SignupExample.entitlements b/Projects/Example/SignupExampleModule/SignupExample/SignupExample.entitlements new file mode 100644 index 00000000..a812db50 --- /dev/null +++ b/Projects/Example/SignupExampleModule/SignupExample/SignupExample.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.developer.applesignin + + Default + + + diff --git a/Projects/Present/SignupPresentModule/SignupPresent/Sources/AppleSignInButton.swift b/Projects/Present/SignupPresentModule/SignupPresent/Sources/AppleSignInButton.swift index fa37e5da..040bc2dd 100644 --- a/Projects/Present/SignupPresentModule/SignupPresent/Sources/AppleSignInButton.swift +++ b/Projects/Present/SignupPresentModule/SignupPresent/Sources/AppleSignInButton.swift @@ -13,6 +13,7 @@ import RxCocoa import SnapKit import Then +// TODO: authorization 로직 UI 코드와 분리 필요 final public class AppleSignInButton: UIButton { // MARK: Property private var authorizationController: ASAuthorizationController = { diff --git a/Tuist/ProjectDescriptionHelpers/Project+Templates.swift b/Tuist/ProjectDescriptionHelpers/Project+Templates.swift index 3ef042ca..b357a465 100644 --- a/Tuist/ProjectDescriptionHelpers/Project+Templates.swift +++ b/Tuist/ProjectDescriptionHelpers/Project+Templates.swift @@ -153,7 +153,7 @@ extension Project { name: "\(target.name)DataInterface", product: .framework, bundleId: "\(bundleId).\(target.bundleIdenifier).datainterface", - dependencies: dependencies + dependencies: dependencies + dataDependencies ), ], schemes: .base