- BookmarkDetail: Add labels property, display and manage labels in detail view - Add AddLabelsToBookmarkUseCase and RemoveLabelsFromBookmarkUseCase - Update UpdateBookmarkUseCase and BookmarkUpdateRequest for label operations - UI: Show labels in BookmarkDetailView, add label management sheet - DefaultUseCaseFactory: Provide use cases for label management - Localizable: Add/adjust label-related strings, minor cleanup - SettingsServerView: Update debug endpoint - SidebarTab: Change 'Alle' to 'All' - Project: Remove unused region from Xcode project
93 lines
3.7 KiB
Swift
93 lines
3.7 KiB
Swift
import Foundation
|
|
|
|
protocol PBookmarksRepository {
|
|
func fetchBookmarks(state: BookmarkState?, limit: Int?, offset: Int?, search: String?, type: [BookmarkType]?) async throws -> BookmarksPage
|
|
func fetchBookmark(id: String) async throws -> BookmarkDetail
|
|
func fetchBookmarkArticle(id: String) async throws -> String
|
|
func createBookmark(createRequest: CreateBookmarkRequest) async throws -> String
|
|
func updateBookmark(id: String, updateRequest: BookmarkUpdateRequest) async throws
|
|
func deleteBookmark(id: String) async throws
|
|
func searchBookmarks(search: String) async throws -> BookmarksPage
|
|
}
|
|
|
|
class BookmarksRepository: PBookmarksRepository {
|
|
private var api: PAPI
|
|
|
|
init(api: PAPI) {
|
|
self.api = api
|
|
}
|
|
|
|
func fetchBookmarks(state: BookmarkState? = nil, limit: Int? = nil, offset: Int? = nil, search: String? = nil, type: [BookmarkType]? = nil) async throws -> BookmarksPage {
|
|
let bookmarkDtos = try await api.getBookmarks(state: state, limit: limit, offset: offset, search: search, type: type)
|
|
return bookmarkDtos.toDomain()
|
|
}
|
|
|
|
func fetchBookmark(id: String) async throws -> BookmarkDetail {
|
|
let bookmarkDetailDto = try await api.getBookmark(id: id)
|
|
return BookmarkDetail(
|
|
id: bookmarkDetailDto.id,
|
|
title: bookmarkDetailDto.title,
|
|
url: bookmarkDetailDto.url,
|
|
description: bookmarkDetailDto.description,
|
|
siteName: bookmarkDetailDto.siteName,
|
|
authors: bookmarkDetailDto.authors,
|
|
created: bookmarkDetailDto.created,
|
|
updated: bookmarkDetailDto.updated,
|
|
wordCount: bookmarkDetailDto.wordCount,
|
|
readingTime: bookmarkDetailDto.readingTime,
|
|
hasArticle: bookmarkDetailDto.hasArticle,
|
|
isMarked: bookmarkDetailDto.isMarked,
|
|
isArchived: bookmarkDetailDto.isArchived,
|
|
labels: bookmarkDetailDto.labels,
|
|
thumbnailUrl: bookmarkDetailDto.resources.thumbnail?.src ?? "",
|
|
imageUrl: bookmarkDetailDto.resources.image?.src ?? ""
|
|
)
|
|
}
|
|
|
|
func fetchBookmarkArticle(id: String) async throws -> String {
|
|
return try await api.getBookmarkArticle(id: id)
|
|
}
|
|
|
|
func createBookmark(createRequest: CreateBookmarkRequest) async throws -> String {
|
|
let dto = CreateBookmarkRequestDto(
|
|
url: createRequest.url,
|
|
title: createRequest.title,
|
|
labels: createRequest.labels
|
|
)
|
|
|
|
let response = try await api.createBookmark(createRequest: dto)
|
|
|
|
// Prüfe ob die Erstellung erfolgreich war
|
|
guard response.status == 0 || response.status == 202 else {
|
|
throw CreateBookmarkError.serverError(response.message)
|
|
}
|
|
|
|
return response.message
|
|
}
|
|
|
|
func deleteBookmark(id: String) async throws {
|
|
try await api.deleteBookmark(id: id)
|
|
}
|
|
|
|
func updateBookmark(id: String, updateRequest: BookmarkUpdateRequest) async throws {
|
|
let dto = UpdateBookmarkRequestDto(
|
|
addLabels: updateRequest.addLabels,
|
|
isArchived: updateRequest.isArchived,
|
|
isDeleted: updateRequest.isDeleted,
|
|
isMarked: updateRequest.isMarked,
|
|
labels: updateRequest.labels,
|
|
readAnchor: updateRequest.readAnchor,
|
|
readProgress: updateRequest.readProgress,
|
|
removeLabels: updateRequest.removeLabels,
|
|
title: updateRequest.title
|
|
)
|
|
|
|
try await api.updateBookmark(id: id, updateRequest: dto)
|
|
}
|
|
|
|
func searchBookmarks(search: String) async throws -> BookmarksPage {
|
|
let bookmarkDtos = try await api.searchBookmarks(search: search)
|
|
return bookmarkDtos.toDomain()
|
|
}
|
|
}
|