Refactorings: - Extract HTMLImageEmbedder and HTMLImageExtractor utilities - Create UseCases for cached data access (GetCachedBookmarksUseCase, GetCachedArticleUseCase) - Create CreateAnnotationUseCase to remove API dependency from ViewModel - Simplify CachedAsyncImage by extracting helper methods - Fix Kingfisher API compatibility (Source types, Result handling) - Add documentation to OfflineCacheSyncUseCase - Remove unused TestView from production code Enforces Clean Architecture: - ViewModels now only use UseCases, no direct Repository or API access - All data layer access goes through Domain layer
46 lines
1.0 KiB
Swift
46 lines
1.0 KiB
Swift
//
|
|
// CreateAnnotationUseCase.swift
|
|
// readeck
|
|
//
|
|
// Created by Ilyas Hallak on 30.11.25.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
protocol PCreateAnnotationUseCase {
|
|
func execute(
|
|
bookmarkId: String,
|
|
color: String,
|
|
startOffset: Int,
|
|
endOffset: Int,
|
|
startSelector: String,
|
|
endSelector: String
|
|
) async throws -> Annotation
|
|
}
|
|
|
|
class CreateAnnotationUseCase: PCreateAnnotationUseCase {
|
|
private let repository: PAnnotationsRepository
|
|
|
|
init(repository: PAnnotationsRepository) {
|
|
self.repository = repository
|
|
}
|
|
|
|
func execute(
|
|
bookmarkId: String,
|
|
color: String,
|
|
startOffset: Int,
|
|
endOffset: Int,
|
|
startSelector: String,
|
|
endSelector: String
|
|
) async throws -> Annotation {
|
|
return try await repository.createAnnotation(
|
|
bookmarkId: bookmarkId,
|
|
color: color,
|
|
startOffset: startOffset,
|
|
endOffset: endOffset,
|
|
startSelector: startSelector,
|
|
endSelector: endSelector
|
|
)
|
|
}
|
|
}
|