Files
Nextcloud-Cookbook-iOS/Nextcloud Cookbook iOS Client/Persistence/Interfaces/DataInterface.swift
2025-05-26 15:52:12 +02:00

114 lines
3.5 KiB
Swift

//
// PersistenceInterface.swift
// Nextcloud Cookbook iOS Client
//
// Created by Vincent Meilinger on 06.05.24.
//
import Foundation
import SwiftUI
import KeychainSwift
protocol CookbookInterface {
/// A unique id of the interface. Used to associate recipes to their respective accounts.
var id: String { get }
}
protocol ReadInterface {
/// Get either the full image or a thumbnail sized version.
/// - Parameters:
/// - id: The according recipe id.
/// - size: The size of the image.
/// - Returns: The image of the recipe with the specified id. A UserAlert if the request fails, otherwise nil.
func getImage(
id: String,
size: RecipeImage.RecipeImageSize
) async -> (UIImage?, UserAlert?)
/// Get all recipe stubs.
/// - Returns: A list of all recipes.
func getRecipeStubs(
) async -> ([RecipeStub]?, UserAlert?)
/// Get the recipe with the specified id.
/// - Parameters:
/// - id: The recipe id.
/// - Returns: The recipe if it exists. A UserAlert if the request fails.
func getRecipe(
id: String
) async -> (Recipe?, UserAlert?)
/// Get all categories.
/// - Returns: A list of categories. A UserAlert if the request fails.
func getCategories(
) async -> ([Category]?, UserAlert?)
/// Get all recipes of a specified category.
/// - Parameters:
/// - categoryName: The category name.
/// - Returns: A list of recipes. A UserAlert if the request fails.
func getRecipeStubsForCategory(
named categoryName: String
) async -> ([RecipeStub]?, UserAlert?)
/// Get all keywords/tags.
/// - Returns: A list of tag strings. A UserAlert if the request fails.
func getTags(
) async -> ([RecipeKeyword]?, UserAlert?)
/// Get all recipes tagged with the specified keyword.
/// - Parameters:
/// - keyword: The keyword.
/// - Returns: A list of recipes tagged with the specified keyword. A UserAlert if the request fails.
func getRecipesTagged(
keyword: String
) async -> ([RecipeStub]?, UserAlert?)
}
protocol WriteInterface {
/// Post either the full image or a thumbnail sized version.
/// - Parameters:
/// - id: The according recipe id.
/// - size: The size of the image.
/// - Returns: A UserAlert if the request fails, otherwise nil.
func postImage(
id: String,
image: UIImage,
size: RecipeImage.RecipeImageSize
) async -> (UserAlert?)
/// Create a new recipe.
/// - Parameters:
/// - Returns: A UserAlert if the request fails. Nil otherwise.
func postRecipe(
recipe: Recipe
) async -> (UserAlert?)
/// Update an existing recipe with new entries.
/// - Parameters:
/// - recipe: The recipe.
/// - Returns: A UserAlert if the request fails. Nil otherwise.
func updateRecipe(
recipe: Recipe
) async -> (UserAlert?)
/// Delete the recipe with the specified id.
/// - Parameters:
/// - id: The recipe id.
/// - Returns: A UserAlert if the request fails. Nil otherwise.
func deleteRecipe(
id: String
) async -> (UserAlert?)
/// Rename an existing category.
/// - Parameters:
/// - categoryName: The name of the category to be renamed.
/// - newName: The new category name.
/// - Returns: A UserAlert if the request fails.
func renameCategory(
named categoryName: String,
newName: String
) async -> (UserAlert?)
}