Skip to content

Commit

Permalink
feat(MemberData): Add login method to MemberRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Aug 13, 2024
1 parent f98ea29 commit f2a6a7d
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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
}()
}

This file was deleted.

6 changes: 2 additions & 4 deletions Projects/DI/ContainerDIModule/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct MemberRepositoryImpl: MemberRepository {

public init() {}

public func getMember(param: GetMemberParam) -> Observable<GetMemberResult> {
public func getMember(_ param: GetMemberParam) -> Observable<GetMemberResult> {
return Observable.create { observer in
Task {
do {
Expand All @@ -42,4 +42,46 @@ public struct MemberRepositoryImpl: MemberRepository {
return Disposables.create()
}
}

public func login(_ param: LoginParam) -> Observable<LoginResult> {
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<ReissueResult> {
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()
}
}
}
5 changes: 1 addition & 4 deletions Projects/Data/MemberDataModule/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ import ProjectDescriptionHelpers

let project = Project.makeDataModule(
.member,
dependencies: [
.entity(.member),
.dataInterface(.member)
]
dependencies: [.dataInterface(.member)]
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetMemberResult>

func login(_ param: LoginParam) -> Observable<LoginResult>

func reissue(_ param: ReissueParam) -> Observable<ReissueResult>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ import ProjectDescriptionHelpers

let project = Project.makeDataInterfaceModule(
.member,
dependencies: [
.entity(.member)
]
dependencies: []
)
Original file line number Diff line number Diff line change
@@ -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<Result> {
let requestParam: LoginParam = .init(
body: .json(
.init(
provider: .APPLE,
code: param.authorizationCode
)
)
)

return memberRepository.login(requestParam)
.map { _ in Result() }
}
}
7 changes: 6 additions & 1 deletion Projects/Domain/MemberDomainModule/Project.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import ProjectDescription
import ProjectDescriptionHelpers

let project = Project.makeDomainModule(.member)
let project = Project.makeDomainModule(
.member,
dependencies: [
.di(.container)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import RxCocoa
import SnapKit
import Then

// TODO: authorization 로직 UI 코드와 분리 필요
final public class AppleSignInButton: UIButton {
// MARK: Property
private var authorizationController: ASAuthorizationController = {
Expand Down
2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Project+Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extension Project {
name: "\(target.name)DataInterface",
product: .framework,
bundleId: "\(bundleId).\(target.bundleIdenifier).datainterface",
dependencies: dependencies
dependencies: dependencies + dataDependencies
),
],
schemes: .base
Expand Down

0 comments on commit f2a6a7d

Please sign in to comment.