Show Applications & Delete Applications

This commit is contained in:
headlessdev
2025-04-11 22:55:17 +02:00
parent 9b822ad328
commit c27713ba27
12 changed files with 345 additions and 111 deletions

View File

@@ -0,0 +1,23 @@
import { NextResponse, NextRequest } from "next/server";
import { PrismaClient } from '@/lib/generated/prisma'
const prisma = new PrismaClient();
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const id = Number(body.id);
if (!id) {
return NextResponse.json({ error: "Missing ID" }, { status: 400 });
}
await prisma.application.delete({
where: { id: id }
});
return NextResponse.json({ success: true });
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}

View File

@@ -0,0 +1,33 @@
import { NextResponse, NextRequest } from "next/server";
import { PrismaClient } from '@/lib/generated/prisma'
interface GetRequest {
page: number;
}
const prisma = new PrismaClient();
const ITEMS_PER_PAGE = 5;
export async function POST(request: NextRequest) {
try {
const body: GetRequest = await request.json();
const page = Math.max(1, body.page || 1);
const applications = await prisma.application.findMany({
skip: (page - 1) * ITEMS_PER_PAGE,
take: ITEMS_PER_PAGE,
orderBy: { name: 'asc' }
});
// Gesamtanzahl für Seitenberechnung
const totalCount = await prisma.application.count();
const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE);
return NextResponse.json({
applications,
maxPage
});
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}