feat: Implement admin dashboard with user management, statistics, and role-based access control.

This commit is contained in:
Yusuf İpek
2026-02-20 15:17:32 +03:00
parent 1bb1c8e574
commit 83eeffe5c0
10 changed files with 685 additions and 5 deletions
+49
View File
@@ -0,0 +1,49 @@
import { NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { auth } from '@/lib/auth';
import { getCachedTotalStorage } from '@/lib/admin-stats';
export async function GET() {
try {
const session = await auth();
if (!session?.user?.isAdmin) {
return new NextResponse('Unauthorized', { status: 403 });
}
// 1. Database Stats
const [
totalUsers,
totalProjects,
totalVideos,
totalComments,
totalVoiceComments,
] = await Promise.all([
db.user.count(),
db.project.count(),
db.video.count(),
db.comment.count(),
db.comment.count({
where: {
voiceUrl: {
not: null,
}
}
})
]);
// 2. Storage Stats (Cached)
const totalStorageBytes = await getCachedTotalStorage();
return NextResponse.json({
totalUsers,
totalProjects,
totalVideos,
totalComments,
totalVoiceComments,
totalStorageBytes,
});
} catch (error) {
console.error('[ADMIN_STATS_GET]', error);
return new NextResponse('Internal Error', { status: 500 });
}
}
+34
View File
@@ -0,0 +1,34 @@
import { NextResponse } from 'next/server';
import { db } from '@/lib/db';
import { auth } from '@/lib/auth';
export async function GET() {
try {
const session = await auth();
if (!session?.user?.isAdmin) {
return new NextResponse('Unauthorized', { status: 403 });
}
const users = await db.user.findMany({
orderBy: { createdAt: 'desc' },
select: {
id: true,
name: true,
email: true,
createdAt: true,
_count: {
select: {
ownedWorkspaces: true,
projects: true,
comments: true,
}
}
}
});
return NextResponse.json({ users });
} catch (error) {
console.error('[ADMIN_USERS_GET]', error);
return new NextResponse('Internal Error', { status: 500 });
}
}