ReadKeep/readeck/Data/Repository/AnnotationsRepository.swift
Ilyas Hallak 8dc5f3000a feat: Add annotations, cache management, and offline feature improvements
- Add annotation creation to API and repository layer (AnnotationsRepository)
- Add DtoMapper for AnnotationDto to domain model conversion
- Extend PAnnotationsRepository protocol with createAnnotation method
- Add cache management to SettingsRepository (getCacheSize, getMaxCacheSize, updateMaxCacheSize, clearCache)
- Extend PSettingsRepository protocol with cache settings methods
- Use localized Highlight label in annotation overlay JavaScript for WebView and NativeWebView
- Improve API error handling with detailed logging for HTTP errors and response data
- Add LocalizedError extension for APIError with human-readable descriptions
- Update localization strings for German and English (Highlight, Synchronization, VPN warning)
- Update RELEASE_NOTES.md with version 2.0.0 offline reading feature details
2025-12-01 22:01:23 +01:00

37 lines
1.2 KiB
Swift

import Foundation
class AnnotationsRepository: PAnnotationsRepository {
private let api: PAPI
init(api: PAPI) {
self.api = api
}
func createAnnotation(bookmarkId: String, color: String, startOffset: Int, endOffset: Int, startSelector: String, endSelector: String) async throws -> Annotation {
try await api.createAnnotation(bookmarkId: bookmarkId, color: color, startOffset: startOffset, endOffset: endOffset, startSelector: startSelector, endSelector: endSelector)
.toDomain()
}
func fetchAnnotations(bookmarkId: String) async throws -> [Annotation] {
let annotationDtos = try await api.getBookmarkAnnotations(bookmarkId: bookmarkId)
return annotationDtos.map { dto in
Annotation(
id: dto.id,
text: dto.text,
created: dto.created,
startOffset: dto.startOffset,
endOffset: dto.endOffset,
startSelector: dto.startSelector,
endSelector: dto.endSelector
)
}
}
func deleteAnnotation(bookmarkId: String, annotationId: String) async throws {
try await api.deleteAnnotation(bookmarkId: bookmarkId, annotationId: annotationId)
}
}