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
struct DocumentPreview: UIViewControllerRepresentable { | |
final class Coordintor: NSObject, UIDocumentInteractionControllerDelegate { | |
private let parent: DocumentPreview | |
init(_ parent: DocumentPreview) { | |
self.parent = parent | |
} | |
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
@Published var categories: [WorsetCategory] = [] | |
@Published var error: Error? | |
@Published var isLoading: Bool = false | |
func fetchWordsetCategories() { | |
guard !isLoading else { return } | |
repo.fetchWordsetCategories() | |
.sink(receiveCompletion: { completion in | |
switch completion { |
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 func fetchWordsetCategories() -> AnyPublisher<[WordsetCategory], Error> { | |
let cachedDataPublisher = dao.fetchCategories() | |
let refreshedDataPublisher = service.getCategories(from: "pl", to: "en") | |
.flatMap { [weak self] categories in | |
self?.dao.update(categories) | |
} | |
.eraseToAnyPublisher() | |
return Publishers.MergeMany(cachedDataPublisher, refreshedDataPublisher) |
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
@objc(WordsetCategory) | |
public class WordsetCategory: NSManagedObject { } | |
extension WordsetCategory { | |
@nonobjc public class func fetchRequest() -> NSFetchRequest<WordsetCategory> { | |
return NSFetchRequest<WordsetCategory>(entityName: "WordsetCategory") | |
} | |
@NSManaged public var categoryId: String? |
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
class WordsetCategoryDao: BaseDao<WordsetCategoryDTO, WordsetCategory>, WordsetCategoryDaoProtocol { | |
func update(_ entities: [WordsetCategoryDTO]) -> Future<UpdateResult, Error> { | |
Future { [weak self] promise in | |
let context = self?.storage.backgroundContext | |
context.perform { | |
switch Self.update(context: context, entities) { | |
case .success(let change): |
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 WordsetCategoryDaoProtocol { | |
// DaoProtocol | |
func insert(_ e: WordsetCategoryDTO) -> Future<WordsetCategory, Error> | |
func delete(_ e: WordsetCategoryDTO) -> Future<Int, Error> | |
func update(_ e: WordsetCategoryDTO) -> Future<WordsetCategory, Error> | |
func load(id: String) -> Future<WordsetCategory, Error> | |
// WordsetCategoryDaoProtocol | |
func update(_ entities: [WordsetCategoryDTO]) -> Future<UpdateResult, Error> |
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
struct WordsetCategoryDTO: Codable { | |
let categoryId: String | |
let foreignName: String | |
let nativeName: String | |
var image: String? | |
enum CodingKeys: String, CodingKey { | |
case categoryId = "cid" | |
case foreignName = "foreignName" | |
case nativeName = "nativeName" |
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
enum WordsetRouter: Router { | |
case getWordsets | |
case getWordset(id: String) | |
static var baseURL: String = "https://mockapi.com" | |
var path: String { | |
switch self { | |
case .getWordsets: |
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 WordsetServiceProtocol { | |
func getCategories(from fromLang: String, to toLang: String) -> AnyPublisher<[WordsetCategoryDTO], Error> | |
} | |
public final class WordsetService: BaseService, WordsetServiceProtocol { | |
func getCategories(from fromLang: String, to toLang: String) -> AnyPublisher<[WordsetCategoryDTO], Error> { | |
let endpoint = Router.wordsetCategories(fromLang: fromLang, toLang: toLang) | |
let xml : AnyPublisher<WordsetCategoriesDTO, Error> = request(endpoint) |
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 |
NewerOlder