WIP - Complete App refactoring
This commit is contained in:
@@ -9,7 +9,7 @@ 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 }
|
||||
@@ -24,12 +24,12 @@ protocol ReadInterface {
|
||||
func getImage(
|
||||
id: String,
|
||||
size: RecipeImage.RecipeImageSize
|
||||
) async -> (UIImage?, UserAlert?)
|
||||
) async -> UIImage?
|
||||
|
||||
/// Get all recipe stubs.
|
||||
/// - Returns: A list of all recipes.
|
||||
func getRecipeStubs(
|
||||
) async -> ([RecipeStub]?, UserAlert?)
|
||||
) async -> [RecipeStub]?
|
||||
|
||||
/// Get the recipe with the specified id.
|
||||
/// - Parameters:
|
||||
@@ -37,12 +37,12 @@ protocol ReadInterface {
|
||||
/// - Returns: The recipe if it exists. A UserAlert if the request fails.
|
||||
func getRecipe(
|
||||
id: String
|
||||
) async -> (Recipe?, UserAlert?)
|
||||
) async -> Recipe?
|
||||
|
||||
/// Get all categories.
|
||||
/// - Returns: A list of categories. A UserAlert if the request fails.
|
||||
func getCategories(
|
||||
) async -> ([Category]?, UserAlert?)
|
||||
) async -> [Category]?
|
||||
|
||||
/// Get all recipes of a specified category.
|
||||
/// - Parameters:
|
||||
@@ -50,12 +50,12 @@ protocol ReadInterface {
|
||||
/// - Returns: A list of recipes. A UserAlert if the request fails.
|
||||
func getRecipeStubsForCategory(
|
||||
named categoryName: String
|
||||
) async -> ([RecipeStub]?, UserAlert?)
|
||||
) async -> [RecipeStub]?
|
||||
|
||||
/// Get all keywords/tags.
|
||||
/// - Returns: A list of tag strings. A UserAlert if the request fails.
|
||||
func getTags(
|
||||
) async -> ([RecipeKeyword]?, UserAlert?)
|
||||
) async -> [RecipeKeyword]?
|
||||
|
||||
/// Get all recipes tagged with the specified keyword.
|
||||
/// - Parameters:
|
||||
@@ -63,7 +63,7 @@ protocol ReadInterface {
|
||||
/// - Returns: A list of recipes tagged with the specified keyword. A UserAlert if the request fails.
|
||||
func getRecipesTagged(
|
||||
keyword: String
|
||||
) async -> ([RecipeStub]?, UserAlert?)
|
||||
) async -> [RecipeStub]?
|
||||
}
|
||||
|
||||
protocol WriteInterface {
|
||||
@@ -111,3 +111,4 @@ protocol WriteInterface {
|
||||
newName: String
|
||||
) async -> (UserAlert?)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
/*
|
||||
|
||||
class LocalDataInterface: CookbookInterface {
|
||||
var id: String
|
||||
@@ -49,49 +49,36 @@ class LocalDataInterface: CookbookInterface {
|
||||
// MARK: - Local Read Interface
|
||||
|
||||
extension LocalDataInterface: ReadInterface {
|
||||
|
||||
func getImage(id: String, size: RecipeImage.RecipeImageSize) async -> (UIImage?, (any UserAlert)?) {
|
||||
func getImage(id: String, size: RecipeImage.RecipeImageSize) async -> UIImage? {
|
||||
guard let data: String = await load(path: .image(id: id, size: size)) else {
|
||||
return (nil, PersistenceAlert.LOAD_FAILED)
|
||||
return nil
|
||||
}
|
||||
guard let dataDecoded = Data(base64Encoded: data) else { return (nil, PersistenceAlert.DECODING_FAILED) }
|
||||
if let image = UIImage(data: dataDecoded) {
|
||||
return (image, nil)
|
||||
}
|
||||
return (nil, nil)
|
||||
guard let dataDecoded = Data(base64Encoded: data) else { return nil }
|
||||
return UIImage(data: dataDecoded)
|
||||
}
|
||||
|
||||
func getRecipeStubs() async -> ([RecipeStub]?, (any UserAlert)?) {
|
||||
return (nil, PersistenceAlert.LOAD_FAILED)
|
||||
func getRecipeStubs() async -> [RecipeStub]? {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRecipe(id: String) async -> (Recipe?, (any UserAlert)?) {
|
||||
if let recipe: Recipe? = await load(path: LocalDataPath.recipe(id: id)) {
|
||||
return (recipe, nil)
|
||||
}
|
||||
return (nil, nil)
|
||||
func getRecipe(id: String) async -> Recipe? {
|
||||
return await load(path: LocalDataPath.recipe(id: id))
|
||||
}
|
||||
|
||||
func getCategories() async -> ([Category]?, (any UserAlert)?) {
|
||||
return (await load(path: LocalDataPath.categories), nil)
|
||||
func getCategories() async -> [Category]? {
|
||||
return await load(path: LocalDataPath.categories)
|
||||
}
|
||||
|
||||
func getRecipeStubsForCategory(named categoryName: String) async -> ([RecipeStub]?, (any UserAlert)?) {
|
||||
if let stubs: [RecipeStub] = await load(path: .recipeStubs(category: categoryName)) {
|
||||
return (stubs, nil)
|
||||
}
|
||||
return (nil, PersistenceAlert.LOAD_FAILED)
|
||||
func getRecipeStubsForCategory(named categoryName: String) async -> [RecipeStub]? {
|
||||
return await load(path: .recipeStubs(category: categoryName))
|
||||
}
|
||||
|
||||
func getTags() async -> ([RecipeKeyword]?, (any UserAlert)?) {
|
||||
if let keywords: [RecipeKeyword] = await load(path: .keywords) {
|
||||
return (keywords, nil)
|
||||
}
|
||||
return (nil, PersistenceAlert.LOAD_FAILED)
|
||||
func getTags() async -> [RecipeKeyword]? {
|
||||
return await load(path: .keywords)
|
||||
}
|
||||
|
||||
func getRecipesTagged(keyword: String) async -> ([RecipeStub]?, (any UserAlert)?) {
|
||||
return (nil, PersistenceAlert.LOAD_FAILED)
|
||||
func getRecipesTagged(keyword: String) async -> [RecipeStub]? {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -109,6 +96,7 @@ extension LocalDataInterface: WriteInterface {
|
||||
path: LocalDataPath.image(id: id, size: size)
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func postRecipe(recipe: Recipe) async -> ((any UserAlert)?) {
|
||||
@@ -129,8 +117,9 @@ extension LocalDataInterface: WriteInterface {
|
||||
guard let stubs: [RecipeStub] = await load(path: .recipeStubs(category: categoryName)) else {
|
||||
return PersistenceAlert.LOAD_FAILED
|
||||
}
|
||||
await delete(path: .recipeStubs(category: categoryName))
|
||||
await save(stubs, path: .recipeStubs(category: newName))
|
||||
await delete(path: .recipeStubs(category: categoryName))
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
@@ -159,3 +148,4 @@ extension LocalDataInterface {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
|
||||
/*
|
||||
class NextcloudDataInterface: CookbookInterface {
|
||||
var id: String
|
||||
|
||||
@@ -31,39 +31,35 @@ class NextcloudDataInterface: CookbookInterface {
|
||||
// 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 getImage(id: String, size: RecipeImage.RecipeImageSize) async -> UIImage? {
|
||||
return await api.getImage(auth: auth.token, id: id, size: size).0
|
||||
}
|
||||
|
||||
func getRecipeStubs() async -> ([RecipeStub]?, UserAlert?) {
|
||||
return await api.getRecipes(auth: auth.token)
|
||||
func getRecipeStubs() async -> [RecipeStub]? {
|
||||
return await api.getRecipes(auth: auth.token).0
|
||||
}
|
||||
|
||||
func getRecipe(id: String) async -> (Recipe?, UserAlert?) {
|
||||
return await api.getRecipe(auth: auth.token, id: id)
|
||||
func getRecipe(id: String) async -> Recipe?{
|
||||
return await api.getRecipe(auth: auth.token, id: id).0
|
||||
}
|
||||
|
||||
func getCategories() async -> ([Category]?, UserAlert?) {
|
||||
return await api.getCategories(auth: auth.token)
|
||||
func getCategories() async -> [Category]? {
|
||||
return await api.getCategories(auth: auth.token).0
|
||||
}
|
||||
|
||||
func getRecipeStubsForCategory(named categoryName: String) async -> ([RecipeStub]?, UserAlert?) {
|
||||
func getRecipeStubsForCategory(named categoryName: String) async -> [RecipeStub]? {
|
||||
return await api.getCategory(
|
||||
auth: UserSettings.shared.authString,
|
||||
named: categoryName
|
||||
)
|
||||
).0
|
||||
}
|
||||
|
||||
func getTags() async -> ([RecipeKeyword]?, (any UserAlert)?) {
|
||||
return await api.getTags(auth: auth.token)
|
||||
func getTags() async -> [RecipeKeyword]? {
|
||||
return await api.getTags(auth: auth.token).0
|
||||
}
|
||||
|
||||
func getRecipesTagged(keyword: String) async -> ([RecipeStub]?, UserAlert?) {
|
||||
return await api.getRecipesTagged(auth: auth.token, keyword: keyword)
|
||||
func getRecipesTagged(keyword: String) async -> [RecipeStub]? {
|
||||
return await api.getRecipesTagged(auth: auth.token, keyword: keyword).0
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,3 +89,4 @@ extension NextcloudDataInterface: WriteInterface {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user