- API-Klasse mit allen CRUD-Operationen für Bookmarks - Login/Authentifizierung mit Bearer Token - Bookmarks abrufen (Liste und Details) - Artikel-Inhalt abrufen - DTO-Strukturen in separate Dateien aufgeteilt - UserDto für Authentifizierung - BookmarkDto für Bookmark-Listen - BookmarkDetailDto mit vollständigen Metadaten - MVVM-Architektur mit @Observable - SettingsViewModel für Anmeldung - BookmarksViewModel für Bookmark-Verwaltung - SwiftUI Views mit modernem Design - SettingsView mit Eingabefeldern und Validierung - BookmarksView mit Pull-to-Refresh und Leerzustand - MainTabView als Navigation - Use Case Pattern implementiert - LoginUseCase für Authentifizierung - GetBookmarksUseCase für Datenabfrage - DefaultUseCaseFactory für Dependency Injection - Fehlerbehandlung und Loading States - Protocol-basierte Architektur für bessere Testbarkeit
39 lines
1.0 KiB
Swift
39 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
protocol PBookmarksRepository {
|
|
func fetchBookmarks() async throws -> [Bookmark]
|
|
func addBookmark(bookmark: Bookmark) async throws
|
|
func removeBookmark(id: String) async throws
|
|
}
|
|
|
|
class BookmarksRepository: PBookmarksRepository {
|
|
private var api: PAPI
|
|
|
|
init(api: PAPI) {
|
|
self.api = api
|
|
}
|
|
|
|
func fetchBookmarks() async throws -> [Bookmark] {
|
|
let bookmarkDtos = try await api.getBookmarks()
|
|
api.authToken = UserDefaults.standard.string(forKey: "token")
|
|
return bookmarkDtos.map { dto in
|
|
Bookmark(id: dto.id, title: dto.title, url: dto.url, createdAt: dto.createdAt)
|
|
}
|
|
}
|
|
|
|
func addBookmark(bookmark: Bookmark) async throws {
|
|
// Implement logic to add a bookmark if needed
|
|
}
|
|
|
|
func removeBookmark(id: String) async throws {
|
|
// Implement logic to remove a bookmark if needed
|
|
}
|
|
}
|
|
|
|
struct Bookmark {
|
|
let id: String
|
|
let title: String
|
|
let url: String
|
|
let createdAt: String
|
|
}
|