// // CookbookApi.swift // Nextcloud Cookbook iOS Client // // Created by Vincent Meilinger on 13.11.23. // import Foundation import OSLog import UIKit /// The Cookbook API version. enum CookbookApiVersion: String { case v1 = "v1" } /// A protocol defining common API endpoints for the Cookbook API. protocol CookbookApiProtocol { func importRecipe(url: String) async throws -> RecipeDetail func getImage(id: Int, size: RecipeImage.RecipeImageSize) async throws -> UIImage? func getRecipes() async throws -> [Recipe] func createRecipe(_ recipe: RecipeDetail) async throws -> Int func getRecipe(id: Int) async throws -> RecipeDetail func updateRecipe(_ recipe: RecipeDetail) async throws -> Int func deleteRecipe(id: Int) async throws func getCategories() async throws -> [Category] func getCategory(named: String) async throws -> [Recipe] func renameCategory(named: String, to newName: String) async throws func getTags() async throws -> [RecipeKeyword] func getRecipesTagged(keyword: String) async throws -> [Recipe] func searchRecipes(query: String) async throws -> [Recipe] } enum CookbookApiFactory { static func makeClient( version: CookbookApiVersion = UserSettings.shared.cookbookApiVersion, settings: UserSettings = .shared ) -> CookbookApiProtocol { switch version { case .v1: return CookbookApiClient(settings: settings) } } }