10.2 게시판 스키마/설정 관리 UI o

This commit is contained in:
koreacomp5
2025-10-09 18:25:06 +09:00
parent fee16e68f2
commit 4167fcb332
4 changed files with 116 additions and 1 deletions

View File

@@ -0,0 +1,75 @@
"use client";
import useSWR from "swr";
import { useState } from "react";
const fetcher = (url: string) => fetch(url).then((r) => r.json());
export default function AdminBoardsPage() {
const { data, mutate } = useSWR<{ boards: any[] }>("/api/admin/boards", fetcher);
const boards = data?.boards ?? [];
const [savingId, setSavingId] = useState<string | null>(null);
async function save(b: any) {
setSavingId(b.id);
await fetch(`/api/admin/boards/${b.id}`, { method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify(b) });
setSavingId(null);
mutate();
}
return (
<div>
<h1> </h1>
<table style={{ width: "100%", borderCollapse: "collapse" }}>
<thead>
<tr>
<th></th>
<th>slug</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{boards.map((b) => (
<Row key={b.id} b={b} onSave={save} saving={savingId === b.id} />
))}
</tbody>
</table>
</div>
);
}
function Row({ b, onSave, saving }: { b: any; onSave: (b: any) => void; saving: boolean }) {
const [edit, setEdit] = useState(b);
return (
<tr>
<td><input value={edit.name} onChange={(e) => setEdit({ ...edit, name: e.target.value })} /></td>
<td><input value={edit.slug} onChange={(e) => setEdit({ ...edit, slug: e.target.value })} /></td>
<td>
<select value={edit.readLevel} onChange={(e) => setEdit({ ...edit, readLevel: e.target.value })}>
<option value="public">public</option>
<option value="member">member</option>
<option value="moderator">moderator</option>
<option value="admin">admin</option>
</select>
</td>
<td>
<select value={edit.writeLevel} onChange={(e) => setEdit({ ...edit, writeLevel: e.target.value })}>
<option value="public">public</option>
<option value="member">member</option>
<option value="moderator">moderator</option>
<option value="admin">admin</option>
</select>
</td>
<td><input type="checkbox" checked={edit.allowAnonymousPost} onChange={(e) => setEdit({ ...edit, allowAnonymousPost: e.target.checked })} /></td>
<td><input type="checkbox" checked={edit.allowSecretComment} onChange={(e) => setEdit({ ...edit, allowSecretComment: e.target.checked })} /></td>
<td><input type="checkbox" checked={edit.requiresApproval} onChange={(e) => setEdit({ ...edit, requiresApproval: e.target.checked })} /></td>
<td><input type="number" value={edit.sortOrder} onChange={(e) => setEdit({ ...edit, sortOrder: Number(e.target.value) })} style={{ width: 80 }} /></td>
<td><button onClick={() => onSave(edit)} disabled={saving}>{saving ? "저장중" : "저장"}</button></td>
</tr>
);
}

View File

@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export async function PATCH(req: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const body = await req.json().catch(() => ({}));
const data: any = {};
for (const k of ["name", "slug", "description", "sortOrder", "readLevel", "writeLevel", "allowAnonymousPost", "allowSecretComment", "requiresApproval", "status"]) {
if (k in body) data[k] = body[k];
}
const updated = await prisma.board.update({ where: { id }, data });
return NextResponse.json({ board: updated });
}

View File

@@ -0,0 +1,25 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
export async function GET() {
const boards = await prisma.board.findMany({
orderBy: { sortOrder: "asc" },
select: {
id: true,
name: true,
slug: true,
description: true,
sortOrder: true,
readLevel: true,
writeLevel: true,
allowAnonymousPost: true,
allowSecretComment: true,
requiresApproval: true,
type: true,
status: true,
},
});
return NextResponse.json({ boards });
}

View File

@@ -70,7 +70,7 @@
[관리자(Admin)]
10.1 대시보드 핵심 지표 위젯 o
10.2 게시판 스키마/설정 관리 UI
10.2 게시판 스키마/설정 관리 UI o
10.3 사용자 검색/정지/권한 변경
10.4 공지/배너 등록 및 노출 설정
10.5 감사 이력/신고 내역/열람 로그