- 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
36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
protocol PRemoveLabelsFromBookmarkUseCase {
|
|
func execute(bookmarkId: String, labels: [String]) async throws
|
|
func execute(bookmarkId: String, label: String) async throws
|
|
}
|
|
|
|
class RemoveLabelsFromBookmarkUseCase: PRemoveLabelsFromBookmarkUseCase {
|
|
private let repository: PBookmarksRepository
|
|
|
|
init(repository: PBookmarksRepository) {
|
|
self.repository = repository
|
|
}
|
|
|
|
func execute(bookmarkId: String, labels: [String]) async throws {
|
|
// Validierung der Labels
|
|
guard !labels.isEmpty else {
|
|
throw BookmarkUpdateError.emptyLabels
|
|
}
|
|
|
|
// Entferne leere Labels und Duplikate
|
|
let cleanLabels = Array(Set(labels.filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }))
|
|
|
|
guard !cleanLabels.isEmpty else {
|
|
throw BookmarkUpdateError.emptyLabels
|
|
}
|
|
|
|
let request = BookmarkUpdateRequest.removeLabels(cleanLabels)
|
|
try await repository.updateBookmark(id: bookmarkId, updateRequest: request)
|
|
}
|
|
|
|
// Convenience method für einzelne Labels
|
|
func execute(bookmarkId: String, label: String) async throws {
|
|
try await execute(bookmarkId: bookmarkId, labels: [label])
|
|
}
|
|
} |