WIP - Complete App refactoring
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// NextcloudDataInterface.swift
|
||||
// Nextcloud Cookbook iOS Client
|
||||
//
|
||||
// Created by Vincent Meilinger on 07.05.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
|
||||
class NextcloudDataInterface: CookbookInterface {
|
||||
var id: String
|
||||
|
||||
var auth: Authentication
|
||||
var api: CookbookApi.Type
|
||||
|
||||
init(auth: Authentication, version: String) {
|
||||
self.id = UUID().uuidString
|
||||
self.auth = auth
|
||||
switch version {
|
||||
case "1.0":
|
||||
self.api = CookbookApiV1.self
|
||||
default:
|
||||
self.api = CookbookApiV1.self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Nextcloud Read Interface
|
||||
extension NextcloudDataInterface: ReadInterface {
|
||||
|
||||
func getImage(id: String, size: RecipeImage.RecipeImageSize) async -> (UIImage?, UserAlert?) {
|
||||
let (image, error) = await api.getImage(auth: auth.token, id: id, size: size)
|
||||
if let image {
|
||||
return (image, nil)
|
||||
}
|
||||
return (nil, error)
|
||||
}
|
||||
|
||||
func getRecipeStubs() async -> ([RecipeStub]?, UserAlert?) {
|
||||
return await api.getRecipes(auth: auth.token)
|
||||
}
|
||||
|
||||
func getRecipe(id: String) async -> (Recipe?, UserAlert?) {
|
||||
return await api.getRecipe(auth: auth.token, id: id)
|
||||
}
|
||||
|
||||
func getCategories() async -> ([Category]?, UserAlert?) {
|
||||
return await api.getCategories(auth: auth.token)
|
||||
}
|
||||
|
||||
func getRecipeStubsForCategory(named categoryName: String) async -> ([RecipeStub]?, UserAlert?) {
|
||||
return await api.getCategory(
|
||||
auth: UserSettings.shared.authString,
|
||||
named: categoryName
|
||||
)
|
||||
}
|
||||
|
||||
func getTags() async -> ([RecipeKeyword]?, (any UserAlert)?) {
|
||||
return await api.getTags(auth: auth.token)
|
||||
}
|
||||
|
||||
func getRecipesTagged(keyword: String) async -> ([RecipeStub]?, UserAlert?) {
|
||||
return await api.getRecipesTagged(auth: auth.token, keyword: keyword)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Nextcloud Write Interface
|
||||
extension NextcloudDataInterface: WriteInterface {
|
||||
|
||||
func postImage(id: String, image: UIImage, size: RecipeImage.RecipeImageSize) async -> ((any UserAlert)?) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func postRecipe(recipe: Recipe) async -> (UserAlert?) {
|
||||
return await api.createRecipe(auth: auth.token, recipe: recipe)
|
||||
}
|
||||
|
||||
func updateRecipe(recipe: Recipe) async -> (UserAlert?) {
|
||||
return await api.updateRecipe(auth: auth.token, recipe: recipe)
|
||||
}
|
||||
|
||||
func deleteRecipe(id: String) async -> (UserAlert?) {
|
||||
return await api.deleteRecipe(auth: auth.token, id: id)
|
||||
}
|
||||
|
||||
func renameCategory(named categoryName: String, newName: String) async -> (UserAlert?) {
|
||||
return await api.renameCategory(auth: auth.token, named: categoryName, newName: newName)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user