Skip to content

Instantly share code, notes, and snippets.

@michzio
Created December 12, 2021 10:38
Show Gist options
  • Save michzio/f285a3c1959159209bcb83e730c77965 to your computer and use it in GitHub Desktop.
Save michzio/f285a3c1959159209bcb83e730c77965 to your computer and use it in GitHub Desktop.
SwiftUI MVVM architecture - Repository
public protocol WordsetCategoriesRepositoryProtocol {
func syncWordsetCategories() -> AnyPublisher<UpdateResult, Error>
func insertWordsetCategory() -> AnyPublisher<WordsetCategory, Error>
}
public final class WordsetCategoriesRepository: WordsetCategoryRepositoryProtocol {
@Inject private var service: WordsetCategoriesServiceProtocol
@Inject private var dao: WordsetCategoriesDaoProtocol
public func syncWordsetCategories() -> AnyPublisher<UpdateResult, Error> {
service.getCategories(from: "pl", to: "en")
.flatMap { [weak self] categories in
self?.dao.update(categories)
}
.eraseToAnyPublisher()
}
public func insertWordsetCategory() -> AnyPublisher<WordsetCategory, Error> {
dao.insertReplacing(WordsetCategoryDTO(categoryId: "1", foreignName: "Test", nativeName: "Test", image: nil))
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment