Web app ready

This commit is contained in:
2026-06-06 17:08:04 +02:00
parent ff187a5bd4
commit 3e127afbae
39 changed files with 2622 additions and 123 deletions
+24
View File
@@ -0,0 +1,24 @@
import { NextResponse } from 'next/server';
import db from '@/lib/db';
export const dynamic = 'force-dynamic';
export async function GET() {
const counters = db.prepare('SELECT * FROM counters ORDER BY order_index ASC, id ASC').all();
return NextResponse.json(counters);
}
export async function POST(request: Request) {
const { name, value = 0, group_id = null, image_path = null } = await request.json();
if (!name?.trim()) {
return NextResponse.json({ error: 'Name is required' }, { status: 400 });
}
const maxOrder = (db.prepare(
'SELECT COALESCE(MAX(order_index), -1) AS m FROM counters'
).get() as { m: number }).m;
const result = db.prepare(
'INSERT INTO counters (name, value, group_id, image_path, order_index) VALUES (?, ?, ?, ?, ?)'
).run(name.trim(), value, group_id, image_path, maxOrder + 1);
const counter = db.prepare('SELECT * FROM counters WHERE id = ?').get(result.lastInsertRowid);
return NextResponse.json(counter, { status: 201 });
}