From 15f30c1bc743871af080741de01c2153bec2f6c2 Mon Sep 17 00:00:00 2001 From: koreacomp5 Date: Thu, 9 Oct 2025 17:07:28 +0900 Subject: [PATCH] =?UTF-8?q?7.6=20=EC=9D=B5=EB=AA=85/=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=8C=93=EA=B8=80/=EB=B9=84=EB=8C=93=20=ED=95=B4=EC=8B=9C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/comments/route.ts | 6 +++++- src/app/api/posts/[id]/comments/route.ts | 11 ++++++++++- todolist.txt | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app/api/comments/route.ts b/src/app/api/comments/route.ts index c8f117d..fcfa6ba 100644 --- a/src/app/api/comments/route.ts +++ b/src/app/api/comments/route.ts @@ -1,6 +1,7 @@ import { NextResponse } from "next/server"; import prisma from "@/lib/prisma"; import { z } from "zod"; +import { hashPassword } from "@/lib/password"; const createCommentSchema = z.object({ postId: z.string().min(1), @@ -8,6 +9,7 @@ const createCommentSchema = z.object({ content: z.string().min(1), isAnonymous: z.boolean().optional(), isSecret: z.boolean().optional(), + secretPassword: z.string().min(1).optional(), // 비회원 비밀번호(옵션) }); export async function POST(req: Request) { @@ -16,7 +18,8 @@ export async function POST(req: Request) { if (!parsed.success) { return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 }); } - const { postId, authorId, content, isAnonymous, isSecret } = parsed.data; + const { postId, authorId, content, isAnonymous, isSecret, secretPassword } = parsed.data; + const secretPasswordHash = secretPassword ? hashPassword(secretPassword) : null; const comment = await prisma.comment.create({ data: { postId, @@ -24,6 +27,7 @@ export async function POST(req: Request) { content, isAnonymous: !!isAnonymous, isSecret: !!isSecret, + secretPasswordHash, }, }); return NextResponse.json({ comment }, { status: 201 }); diff --git a/src/app/api/posts/[id]/comments/route.ts b/src/app/api/posts/[id]/comments/route.ts index c635fa2..629efb5 100644 --- a/src/app/api/posts/[id]/comments/route.ts +++ b/src/app/api/posts/[id]/comments/route.ts @@ -11,10 +11,19 @@ export async function GET(_: Request, context: { params: Promise<{ id: string }> content: true, isAnonymous: true, isSecret: true, + secretPasswordHash: true, createdAt: true, }, }); - return NextResponse.json({ comments }); + const presented = comments.map((c) => ({ + id: c.id, + content: c.isSecret ? "비밀댓글입니다." : c.content, + isAnonymous: c.isAnonymous, + isSecret: c.isSecret, + anonId: c.isAnonymous ? c.id.slice(-6) : undefined, + createdAt: c.createdAt, + })); + return NextResponse.json({ comments: presented }); } diff --git a/todolist.txt b/todolist.txt index 30b18ac..5c29bc4 100644 --- a/todolist.txt +++ b/todolist.txt @@ -45,7 +45,7 @@ 7.3 태그/카테고리 모델 및 UI o 7.4 첨부 업로드 및 본문 삽입 o 7.5 추천/신고, 조회수 카운트 o -7.6 익명/비밀댓글/비댓 해시 처리 +7.6 익명/비밀댓글/비댓 해시 처리 o 7.7 신고→알림→블라인드 자동화 훅 7.8 일반 게시판 공용 폼/라우트 템플릿 생성 7.9 일반 카테고리 설정 매핑(공지/가입인사/버그건의/이벤트/소통방/자유/무엇이든/마사지꿀팁/관리사찾아요/청와대/방문후기[승인])