feat(m6): board with threads/comments, markdown, tests, e2e

- BoardRepository (thread/comment CRUD, soft-delete, search, pagination,
  pinned-first ordering) + BoardService (membership permission,
  author/admin edit/delete, comment->board_commented notification,
  board_posted/comment_added activity logs, category validation)
- APIs: threads list/create/detail/edit/delete, comments create/edit/delete
- MarkdownBody (react-markdown + remark-gfm + rehype-sanitize),
  ThreadForm, CommentForm, board list + thread detail screens, ProjectNav link
- Unit tests (BoardRepository, BoardService) + e2e board.spec
This commit is contained in:
Ken Yasue
2026-06-25 01:28:08 +02:00
parent ac598a50f2
commit 2017585f84
16 changed files with 1448 additions and 1 deletions

View File

@ -0,0 +1,75 @@
import { NextRequest, NextResponse } from 'next/server';
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
import { createBoardService } from '@/lib/api/services';
import { UnauthorizedError } from '@/lib/errors';
import { handleApiError, jsonError } from '@/lib/api/handleError';
export const runtime = 'nodejs';
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ projectId: string; threadId: string }> }
) {
const user = await getCurrentUser();
if (!user) return handleApiError(new UnauthorizedError());
const { threadId } = await params;
const service = createBoardService();
try {
const thread = service.getThread(user.id, Number(threadId));
const comments = service.listComments(user.id, Number(threadId));
return NextResponse.json({ thread, comments });
} catch (error) {
return handleApiError(error);
}
}
export async function PATCH(
request: NextRequest,
{ params }: { params: Promise<{ projectId: string; threadId: string }> }
) {
const user = await getCurrentUser();
if (!user) return handleApiError(new UnauthorizedError());
const { threadId } = await params;
let body: Record<string, unknown>;
try {
body = (await request.json()) as Record<string, unknown>;
} catch {
return jsonError(400, 'リクエスト本文が不正です');
}
const service = createBoardService();
try {
const thread = service.updateThread(user.id, Number(threadId), {
title: typeof body.title === 'string' ? body.title : undefined,
bodyMd: typeof body.bodyMd === 'string' ? body.bodyMd : undefined,
category:
typeof body.category === 'string'
? (body.category as never)
: undefined,
isPinned: typeof body.isPinned === 'number' ? body.isPinned : undefined,
isImportant:
typeof body.isImportant === 'number' ? body.isImportant : undefined,
});
return NextResponse.json({ thread });
} catch (error) {
return handleApiError(error);
}
}
export async function DELETE(
_request: NextRequest,
{ params }: { params: Promise<{ projectId: string; threadId: string }> }
) {
const user = await getCurrentUser();
if (!user) return handleApiError(new UnauthorizedError());
const { threadId } = await params;
const service = createBoardService();
try {
service.deleteThread(user.id, Number(threadId));
return NextResponse.json({ ok: true });
} catch (error) {
return handleApiError(error);
}
}