Created
December 12, 2021 10:38
-
-
Save michzio/f285a3c1959159209bcb83e730c77965 to your computer and use it in GitHub Desktop.
SwiftUI MVVM architecture - Repository
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
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