WIP - Complete App refactoring
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user