From 8d1584cdb885fcb9da1cef8fab5a8eb9d7fc3f2f Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Fri, 17 Apr 2026 19:01:09 +0200 Subject: [PATCH] feat: add API routes for GET, PATCH, and DELETE operations on recipes --- .../app/admin/products/EditProductForm.tsx | 2 +- frontend/app/api/recipes/[id]/route.ts | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 frontend/app/api/recipes/[id]/route.ts diff --git a/frontend/app/admin/products/EditProductForm.tsx b/frontend/app/admin/products/EditProductForm.tsx index 6eb07061..b31d4d69 100644 --- a/frontend/app/admin/products/EditProductForm.tsx +++ b/frontend/app/admin/products/EditProductForm.tsx @@ -18,7 +18,7 @@ const CATEGORIES: Record = { 'Glass, godis & snacks': ['Glass', 'Godis', 'Snacks'], 'Kött, chark & fågel': ['Nötkött', 'Fläsk', 'Fågel', 'Charkuteri', 'Vilt'], 'Mejeri, ost & ägg': ['Mjölk', 'Grädde', 'Ost', 'Yoghurt & fil', 'Smör & margarin', 'Ägg'], - 'Skafferi': ['Mjöl & bakning', 'Pasta & ris', 'Baljväxter', 'Nötter & frön', 'Socker & sötningsmedel', 'Kryddor & örter', 'Konserver & burkar'], + 'Skafferi': ['Mjöl & bakning', 'Pasta & ris', 'Baljväxter', 'Nötter & frön', 'Socker & sötningsmedel', 'Kryddor & örter', 'Konserver & burkar', 'Sylt, mos & marmelad'], 'Vegetariskt': ['Vegetariska proteinkällor', 'Vegetariska färdigrätter', 'Vegetariska korvar & burgare'], 'Övrigt': [], }; diff --git a/frontend/app/api/recipes/[id]/route.ts b/frontend/app/api/recipes/[id]/route.ts new file mode 100644 index 00000000..f2df7c6b --- /dev/null +++ b/frontend/app/api/recipes/[id]/route.ts @@ -0,0 +1,47 @@ +import { NextRequest, NextResponse } from 'next/server'; + +const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080'; + +export async function GET( + _request: NextRequest, + { params }: { params: Promise<{ id: string }> }, +) { + const { id } = await params; + const res = await fetch(`${API_BASE}/api/recipes/${id}`, { cache: 'no-store' }); + const text = await res.text(); + return new NextResponse(text, { + status: res.status, + headers: { 'Content-Type': 'application/json' }, + }); +} + +export async function PATCH( + request: NextRequest, + { params }: { params: Promise<{ id: string }> }, +) { + const { id } = await params; + const body = await request.json(); + const res = await fetch(`${API_BASE}/api/recipes/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(body), + cache: 'no-store', + }); + const text = await res.text(); + return new NextResponse(text, { + status: res.status, + headers: { 'Content-Type': 'application/json' }, + }); +} + +export async function DELETE( + _request: NextRequest, + { params }: { params: Promise<{ id: string }> }, +) { + const { id } = await params; + const res = await fetch(`${API_BASE}/api/recipes/${id}`, { + method: 'DELETE', + cache: 'no-store', + }); + return new NextResponse(null, { status: res.status }); +}