mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Basic VM functionality
This commit is contained in:
@@ -28,6 +28,8 @@ export async function PUT(request: NextRequest) {
|
||||
const updatedServer = await prisma.server.update({
|
||||
where: { id },
|
||||
data: {
|
||||
host,
|
||||
hostServer,
|
||||
name,
|
||||
os,
|
||||
ip,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
13
app/api/servers/hosts/route.ts
Normal file
13
app/api/servers/hosts/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user