Skip to content

Commit

Permalink
[Feat] #388 - UseCase 주입 및 Repository 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Sep 27, 2024
1 parent 21a4516 commit 44bebe7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ public class DailySoptuneRepository {
}

extension DailySoptuneRepository: DailySoptuneRepositoyInterface {

public func getDailySoptuneResult(date: String) -> AnyPublisher<DailySoptuneResultModel, Error> {
self.fortuneService
.getDailySoptuneResult(date: date)
.map{ $0.toDomain() }
.eraseToAnyPublisher()
}
}
45 changes: 45 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/DailySoptuneUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// DailySoptuneUseCase.swift
// Domain
//
// Created by 강윤서 on 9/27/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Combine

import Core

public protocol DailySoptuneUseCase {
var dailySoptuneResult: PassthroughSubject<DailySoptuneResultModel, Never> { get }

func getDailySoptuneResult(date: String)
}


public class DefaultDailySoptuneUseCase {

private let repository: DailySoptuneRepositoyInterface
private let cancelBag = CancelBag()

public let dailySoptuneResult = PassthroughSubject<DailySoptuneResultModel, Never>()

public init(repository: DailySoptuneRepositoyInterface) {
self.repository = repository
}
}

extension DefaultDailySoptuneUseCase: DailySoptuneUseCase {
public func getDailySoptuneResult(date: String) {
repository.getDailySoptuneResult(date: date)
.sink { event in
print("GetDailySoptuneResult State: \(event)")
} receiveValue: { [weak self] dailySoptuneResult in
self?.dailySoptuneResult.send(dailySoptuneResult)
}
.store(in: cancelBag)

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,13 @@ extension AppDelegate {
)
}
)
container.register(
interface: DailySoptuneRepositoyInterface.self,
implement: {
DailySoptuneRepository(
fortuneService: DefaultFortuneService()
)
}
)
}
}

0 comments on commit 44bebe7

Please sign in to comment.