diff --git a/app/api/health/route.ts b/app/api/health/route.ts new file mode 100644 index 0000000..b2cfeaf --- /dev/null +++ b/app/api/health/route.ts @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { dbHealth } from '@/lib/db'; +import { buildInfo } from '@/lib/build-info'; + +export const dynamic = 'force-dynamic'; + +export async function GET() { + const database = await dbHealth(); + const ok = database.status === 'up'; + return NextResponse.json( + { + status: ok ? 'ok' : 'degraded', + version: buildInfo.version, + commit: buildInfo.commit, + sourceHash: buildInfo.sourceHash, + builtAt: buildInfo.builtAt, + uptimeSeconds: Math.round(process.uptime()), + database, + }, + { status: ok ? 200 : 503 } + ); +} diff --git a/app/api/tasks/[id]/route.ts b/app/api/tasks/[id]/route.ts new file mode 100644 index 0000000..4b4f4ab --- /dev/null +++ b/app/api/tasks/[id]/route.ts @@ -0,0 +1,22 @@ +import { NextResponse } from 'next/server'; +import { deleteTask, isStatus, moveTask } from '@/lib/tasks'; + +export const dynamic = 'force-dynamic'; + +type Ctx = { params: Promise<{ id: string }> }; + +export async function PATCH(req: Request, { params }: Ctx) { + const id = Number((await params).id); + const body = await req.json().catch(() => null); + if (!Number.isInteger(id) || !isStatus(body?.status)) { + return NextResponse.json({ error: 'valid id and status (todo|doing|done) required' }, { status: 400 }); + } + const task = await moveTask(id, body.status); + return task ? NextResponse.json(task) : NextResponse.json({ error: 'not found' }, { status: 404 }); +} + +export async function DELETE(_req: Request, { params }: Ctx) { + const id = Number((await params).id); + if (!Number.isInteger(id)) return NextResponse.json({ error: 'invalid id' }, { status: 400 }); + return (await deleteTask(id)) ? new NextResponse(null, { status: 204 }) : NextResponse.json({ error: 'not found' }, { status: 404 }); +} diff --git a/app/api/tasks/route.ts b/app/api/tasks/route.ts new file mode 100644 index 0000000..537b67b --- /dev/null +++ b/app/api/tasks/route.ts @@ -0,0 +1,15 @@ +import { NextResponse } from 'next/server'; +import { createTask, listTasks } from '@/lib/tasks'; + +export const dynamic = 'force-dynamic'; + +export async function GET() { + return NextResponse.json(await listTasks()); +} + +export async function POST(req: Request) { + const body = await req.json().catch(() => null); + const title = typeof body?.title === 'string' ? body.title.trim() : ''; + if (!title) return NextResponse.json({ error: 'title is required' }, { status: 400 }); + return NextResponse.json(await createTask(title, body.assignee), { status: 201 }); +}