- Add protocols for all UseCases and implement them in their respective classes - Add DefaultUseCaseFactory and MockUseCaseFactory for dependency injection - Implement all mock UseCases with dummy data - Start migration of view models and views to protocol-based UseCase injection (not all migrated yet) - Refactor previews and some initializers for easier testing - Move SectionHeader to Components, update server settings UI text - Add sample article.html for mock content
66 lines
2.9 KiB
Swift
66 lines
2.9 KiB
Swift
import Foundation
|
|
|
|
protocol PUpdateBookmarkUseCase {
|
|
func execute(bookmarkId: String, updateRequest: BookmarkUpdateRequest) async throws
|
|
func toggleArchive(bookmarkId: String, isArchived: Bool) async throws
|
|
func toggleFavorite(bookmarkId: String, isMarked: Bool) async throws
|
|
func markAsDeleted(bookmarkId: String) async throws
|
|
func updateReadProgress(bookmarkId: String, progress: Int, anchor: String?) async throws
|
|
func updateTitle(bookmarkId: String, title: String) async throws
|
|
func updateLabels(bookmarkId: String, labels: [String]) async throws
|
|
func addLabels(bookmarkId: String, labels: [String]) async throws
|
|
func removeLabels(bookmarkId: String, labels: [String]) async throws
|
|
}
|
|
|
|
class UpdateBookmarkUseCase: PUpdateBookmarkUseCase {
|
|
private let repository: PBookmarksRepository
|
|
|
|
init(repository: PBookmarksRepository) {
|
|
self.repository = repository
|
|
}
|
|
|
|
func execute(bookmarkId: String, updateRequest: BookmarkUpdateRequest) async throws {
|
|
try await repository.updateBookmark(id: bookmarkId, updateRequest: updateRequest)
|
|
}
|
|
|
|
// Convenience methods für häufige Aktionen
|
|
func toggleArchive(bookmarkId: String, isArchived: Bool) async throws {
|
|
let request = BookmarkUpdateRequest.archive(isArchived)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func toggleFavorite(bookmarkId: String, isMarked: Bool) async throws {
|
|
let request = BookmarkUpdateRequest.favorite(isMarked)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func markAsDeleted(bookmarkId: String) async throws {
|
|
let request = BookmarkUpdateRequest.delete(true)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func updateReadProgress(bookmarkId: String, progress: Int, anchor: String? = nil) async throws {
|
|
let request = BookmarkUpdateRequest.updateProgress(progress, anchor: anchor)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func updateTitle(bookmarkId: String, title: String) async throws {
|
|
let request = BookmarkUpdateRequest.updateTitle(title)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func updateLabels(bookmarkId: String, labels: [String]) async throws {
|
|
let request = BookmarkUpdateRequest.updateLabels(labels)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func addLabels(bookmarkId: String, labels: [String]) async throws {
|
|
let request = BookmarkUpdateRequest.addLabels(labels)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
func removeLabels(bookmarkId: String, labels: [String]) async throws {
|
|
let request = BookmarkUpdateRequest.removeLabels(labels)
|
|
try await execute(bookmarkId: bookmarkId, updateRequest: request)
|
|
}
|
|
} |