diff --git a/app/api/dashboard/get/route.ts b/app/api/dashboard/get/route.ts new file mode 100644 index 0000000..f9be35c --- /dev/null +++ b/app/api/dashboard/get/route.ts @@ -0,0 +1,24 @@ +import { NextResponse, NextRequest } from "next/server"; +import { PrismaClient } from '@/lib/generated/prisma'; + +const prisma = new PrismaClient(); + +export async function POST(request: NextRequest) { + try { + const serverCount = await prisma.server.count(); + + const applicationCount = await prisma.application.count(); + + const onlineApplicationsCount = await prisma.application.count({ + where: { online: true } + }); + + return NextResponse.json({ + serverCount, + applicationCount, + onlineApplicationsCount + }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} diff --git a/app/dashboard/Dashboard.tsx b/app/dashboard/Dashboard.tsx index e2648a7..efcba43 100644 --- a/app/dashboard/Dashboard.tsx +++ b/app/dashboard/Dashboard.tsx @@ -13,8 +13,38 @@ import { SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar" +import { useEffect, useState } from "react" +import axios from "axios" +import { + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card" +import { Skeleton } from "@/components/ui/skeleton" export default function Dashboard() { + const [serverCount, setServerCount] = useState(0) + const [applicationCount, setApplicationCount] = useState(0) + const [onlineApplicationsCount, setOnlineApplicationsCount] = useState(0) + + const getStats = async () => { + try { + const response = await axios.post('/api/dashboard/get', { }); + setServerCount(response.data.serverCount) + setApplicationCount(response.data.applicationCount) + setOnlineApplicationsCount(response.data.onlineApplicationsCount) + } catch (error: any) { + console.log(error.response); + } + } + + useEffect(() => { + getStats(); + }, []); + return ( @@ -38,10 +68,49 @@ export default function Dashboard() { -
- Test +
+
+ + +
+
+ {serverCount} + Servers +
+
+
+
+ + +
+
+ {applicationCount} + Applications +
+
+
+
+ + +
+
+ {onlineApplicationsCount}/{applicationCount} + Applications are online +
+
+
+
+
+
+ COMMING SOON +
+
+
+ COMMING SOON +
+
) -} +} \ No newline at end of file