Basic VM functionality

This commit is contained in:
headlessdev
2025-04-18 14:35:36 +02:00
parent c266296c4f
commit 406091fdcb
8 changed files with 1015 additions and 256 deletions

View File

@@ -28,6 +28,8 @@ export async function PUT(request: NextRequest) {
const updatedServer = await prisma.server.update({
where: { id },
data: {
host,
hostServer,
name,
os,
ip,

View File

@@ -6,24 +6,39 @@ interface GetRequest {
ITEMS_PER_PAGE?: number;
}
export async function POST(request: NextRequest) {
try {
const body: GetRequest = await request.json();
const page = Math.max(1, body.page || 1);
const ITEMS_PER_PAGE = body.ITEMS_PER_PAGE || 4;
const servers = await prisma.server.findMany({
// Host-Server mit Paginierung holen
const hosts = await prisma.server.findMany({
where: { hostServer: null },
skip: (page - 1) * ITEMS_PER_PAGE,
take: ITEMS_PER_PAGE,
orderBy: { name: 'asc' }
});
const totalCount = await prisma.server.count();
const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE);
// VMs für alle Hosts sammeln
const hostsWithVms = await Promise.all(
hosts.map(async (host) => ({
...host,
hostedVMs: await prisma.server.findMany({
where: { hostServer: host.id },
orderBy: { name: 'asc' }
})
}))
);
const totalHosts = await prisma.server.count({
where: { hostServer: null }
});
const maxPage = Math.ceil(totalHosts / ITEMS_PER_PAGE);
return NextResponse.json({
servers,
servers: hostsWithVms,
maxPage
});
} catch (error: any) {

View File

@@ -0,0 +1,13 @@
import { NextResponse, NextRequest } from "next/server";
import { prisma } from "@/lib/prisma";
export async function GET(request: NextRequest) {
try {
const servers = await prisma.server.findMany({
where: { host: true },
});
return NextResponse.json({ servers });
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}

File diff suppressed because it is too large Load Diff