From 2872907a982cff5ea3fe181a4dad0d900e810f7e Mon Sep 17 00:00:00 2001 From: "Ruidy (aider)" Date: Sat, 14 Dec 2024 15:09:37 +0100 Subject: [PATCH] feat: Add categories endpoint to recipes router --- server/trpc/routers/recipes.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server/trpc/routers/recipes.ts b/server/trpc/routers/recipes.ts index 9103a2c..fb5573f 100644 --- a/server/trpc/routers/recipes.ts +++ b/server/trpc/routers/recipes.ts @@ -5,6 +5,13 @@ import { parseRecipeData } from "~/utils/recipes"; const { apiUrl } = useRuntimeConfig(); +type Category = { + idCategory: string; + strCategory: string; + strCategoryThumb: string; + strCategoryDescription: string; +}; + export const recipeRouter = router({ recipeGet: publicProcedure .input( @@ -58,4 +65,18 @@ export const recipeRouter = router({ const recipes = parseRecipeData(data); return recipes; }), + categories: publicProcedure.query(async () => { + const data = await $fetch<{ categories: Category[] }>( + new URL("categories.php", apiUrl).toString(), + ); + + if (!data?.categories) { + throw createError({ + statusCode: 500, + statusMessage: "Failed to fetch categories", + }); + } + + return data.categories; + }), });