Better API call handling.

This commit is contained in:
Vicnet
2023-11-17 12:47:21 +01:00
parent 23e1a665df
commit 5e4b87b201
9 changed files with 286 additions and 346 deletions

View File

@@ -86,13 +86,17 @@ class CookbookApiV1: CookbookApi {
return (JSONDecoder.safeDecode(data), nil)
}
static func updateRecipe(from serverAdress: String, auth: String, id: Int) async -> (NetworkError?) {
static func updateRecipe(from serverAdress: String, auth: String, recipe: RecipeDetail) async -> (NetworkError?) {
guard let recipeData = JSONEncoder.safeEncode(recipe) else {
return .dataError
}
let request = ApiRequest(
serverAdress: serverAdress,
path: "/api/v1/recipes/\(id)",
path: "/api/v1/recipes/\(recipe.id)",
method: .PUT,
authString: auth,
headerFields: [HeaderField.ocsRequest(value: true), HeaderField.accept(value: .JSON)]
headerFields: [HeaderField.ocsRequest(value: true), HeaderField.accept(value: .JSON)],
body: recipeData
)
let (data, error) = await request.send()