switch to createOrUpdate endpoint

This commit is contained in:
Anika Raemer 2025-10-10 19:42:16 +02:00
parent 8027fce80d
commit 47ffe8c74d
3 changed files with 9 additions and 31 deletions

View file

@ -1,5 +1,5 @@
import type { RecipeDto } from "../dtos/RecipeDto";
import { get, postJson, putJson } from "../utils/requests";
import { get, postJson } from "../utils/requests";
/**
@ -24,21 +24,11 @@ export async function fetchRecipe(id: string): Promise<RecipeDto> {
}
/**
* Create new Recipe
* @param recipe Recipe to create
* Either create a new recipe or update an existing one
* @param recipe Recipe to create or update
* @returns Saved recipe
*/
export async function createRecipe(recipe: RecipeDto): Promise<RecipeDto> {
const res = await postJson(RECIPE_URL, JSON.stringify(recipe));
return res.json();
}
/**
* Save an existing recipe
* @param recipe Recipe to save. This recipe must have an ID!
* @returns Saved recipe
*/
export async function updateRecipe(recipe: RecipeDto): Promise<RecipeDto> {
const res = await putJson(`${RECIPE_URL}/${recipe.id}`, JSON.stringify(recipe));
export async function createOrUpdateRecipe(recipe: RecipeDto): Promise<RecipeDto> {
const res = await postJson(RECIPE_URL + "/create-or-update", JSON.stringify(recipe));
return res.json();
}