8.5 월간집계: 월별 지표 산출 배치/차트/다운로드(CSV) o

This commit is contained in:
koreacomp5
2025-10-09 17:34:52 +09:00
parent bb6fa2a6d9
commit bd9d3d4b95
3 changed files with 45 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const year = Number(searchParams.get("year")) || new Date().getFullYear();
const month = Number(searchParams.get("month")) || new Date().getMonth() + 1; // 1-12
const start = new Date(year, month - 1, 1);
const end = new Date(year, month, 1);
const posts = await prisma.post.count({ where: { createdAt: { gte: start, lt: end } } });
const comments = await prisma.comment.count({ where: { createdAt: { gte: start, lt: end } } });
const users = await prisma.user.count({ where: { createdAt: { gte: start, lt: end } } });
const reports = await prisma.report.count({ where: { createdAt: { gte: start, lt: end } } });
return NextResponse.json({ year, month, metrics: { posts, comments, users, reports } });
}