feat: PantryItem (Baslager) - tabell, backend-modul och frontend-sida

This commit is contained in:
Nils-Johan Gynther
2026-04-15 22:06:40 +02:00
parent 65ec74ac7d
commit 47d1aafd9e
12 changed files with 373 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
'use server';
import { revalidatePath } from 'next/cache';
import { API_BASE } from '../../lib/api';
export async function addPantryItem(productId: number) {
const res = await fetch(`${API_BASE}/api/pantry`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ productId }),
cache: 'no-store',
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Kunde inte lägga till i baslagret: ${text}`);
}
revalidatePath('/baslager');
}
export async function removePantryItem(id: number) {
const res = await fetch(`${API_BASE}/api/pantry/${id}`, {
method: 'DELETE',
cache: 'no-store',
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Kunde inte ta bort från baslagret: ${text}`);
}
revalidatePath('/baslager');
}