feat: add functionality for managing deleted products, including restoration and permanent deletion

This commit is contained in:
Nils-Johan Gynther
2026-04-21 13:30:44 +02:00
parent 4074b850cb
commit 87eab4d0ca
7 changed files with 323 additions and 22 deletions
@@ -0,0 +1,29 @@
import { withAuth } from '../../../../../../lib/with-auth';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export const POST = withAuth(async (_req, session, context) => {
const { id } = await context.params;
const productId = Number(id);
if (!productId) return Response.json({ error: 'Ogiltigt id' }, { status: 400 });
const res = await fetch(`${API_BASE}/api/products/${productId}/restore`, {
method: 'POST',
headers: { Authorization: `Bearer ${session.accessToken}` },
});
const data = await res.json().catch(() => ({}));
return Response.json(data, { status: res.status });
});
export const DELETE = withAuth(async (_req, session, context) => {
const { id } = await context.params;
const productId = Number(id);
if (!productId) return Response.json({ error: 'Ogiltigt id' }, { status: 400 });
const res = await fetch(`${API_BASE}/api/products/${productId}/permanent`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${session.accessToken}` },
});
const data = await res.json().catch(() => ({}));
return Response.json(data, { status: res.status });
});
@@ -0,0 +1,11 @@
import { withAuth } from '../../../../lib/with-auth';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export const GET = withAuth(async (_req, session) => {
const res = await fetch(`${API_BASE}/api/products/deleted`, {
headers: { Authorization: `Bearer ${session.accessToken}` },
});
const data = await res.json().catch(() => ([]));
return Response.json(data, { status: res.status });
});