feat(products): implement category selection and product creation in receipt import

This commit is contained in:
Nils-Johan Gynther
2026-04-19 13:39:26 +02:00
parent 39b91d8c87
commit 632d084dbe
4 changed files with 151 additions and 15 deletions
+5 -3
View File
@@ -1,9 +1,11 @@
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from 'next/server';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export async function GET() {
const res = await fetch(`${API_BASE}/api/categories/tree`, { cache: 'no-store' });
export async function GET(req: NextRequest) {
const isTree = req.nextUrl.searchParams.has('tree');
const endpoint = isTree ? '/api/categories/tree' : '/api/categories';
const res = await fetch(`${API_BASE}${endpoint}`, { cache: 'no-store' });
const text = await res.text();
return new NextResponse(text, {
status: res.status,
+16
View File
@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthHeaders } from '../../../../lib/auth-headers';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export async function PATCH(req: NextRequest, { params }: { params: { id: string } }) {
const authHeaders = await getAuthHeaders();
const body = await req.json();
const res = await fetch(`${API_BASE}/api/products/${params.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify(body),
});
const data = await res.json().catch(() => ({}));
return NextResponse.json(data, { status: res.status });
}
+13 -1
View File
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { getAuthHeaders } from '../../../lib/auth-headers';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
@@ -10,7 +11,18 @@ export async function GET(req: NextRequest) {
const res = await fetch(`${API_BASE}/api/products${query ? `?${query}` : ''}`, {
cache: 'no-store',
});
const data = await res.json();
return NextResponse.json(data, { status: res.status });
}
export async function POST(req: NextRequest) {
const authHeaders = await getAuthHeaders();
const body = await req.json();
const res = await fetch(`${API_BASE}/api/products`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify(body),
});
const data = await res.json();
return NextResponse.json(data, { status: res.status });
}