ReadKeep/readeck/Domain/UseCase/GetBookmarksUseCase.swift
Ilyas Hallak 930779169b feat: introduce protocol-based UseCase architecture and mock factory
- 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
2025-07-18 00:46:07 +02:00

35 lines
1.3 KiB
Swift

import Foundation
protocol PGetBookmarksUseCase {
func execute(state: BookmarkState?, limit: Int?, offset: Int?, search: String?, type: [BookmarkType]?, tag: String?) async throws -> BookmarksPage
}
class GetBookmarksUseCase: PGetBookmarksUseCase {
private let repository: PBookmarksRepository
init(repository: PBookmarksRepository) {
self.repository = repository
}
func execute(state: BookmarkState? = nil, limit: Int? = nil, offset: Int? = nil, search: String? = nil, type: [BookmarkType]? = nil, tag: String? = nil) async throws -> BookmarksPage {
var allBookmarks = try await repository.fetchBookmarks(state: state, limit: limit, offset: offset, search: search, type: type, tag: tag)
if let state = state {
allBookmarks.bookmarks = allBookmarks.bookmarks.filter { bookmark in
switch state {
case .all:
return true
case .unread:
return !bookmark.isArchived && !bookmark.isMarked
case .favorite:
return bookmark.isMarked
case .archived:
return bookmark.isArchived
}
}
}
return allBookmarks
}
}