7.5 추천/신고, 조회수 카운트 o

This commit is contained in:
koreacomp5
2025-10-09 17:05:19 +09:00
parent 60d7972762
commit 6d37881dd7
7 changed files with 97 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { getUserIdFromRequest } from "@/lib/auth";
export async function POST(req: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const userId = getUserIdFromRequest(req);
const ip = req.headers.get("x-forwarded-for") || undefined;
const userAgent = req.headers.get("user-agent") || undefined;
await prisma.postViewLog.create({ data: { postId: id, userId: userId ?? null, ip, userAgent } });
await prisma.postStat.upsert({ where: { postId: id }, update: { views: { increment: 1 } }, create: { postId: id, views: 1 } });
return NextResponse.json({ ok: true });
}