2026-09-29 18:31:53 +03:00
|
|
|
/**
|
|
|
|
|
* POST /api/practice/sets — create a problem set (202 {id}; generation
|
|
|
|
|
* runs in the background — the fire-and-forget pipeline). Body:
|
2026-09-29 22:16:28 +03:00
|
|
|
* {nodeIds, params, title?, note?} — a node selection, the cluster's
|
|
|
|
|
* label, and the learner's optional
|
|
|
|
|
* free-form note
|
2026-09-29 18:31:53 +03:00
|
|
|
* Validation + typed-error mapping live in the service (server/practice).
|
|
|
|
|
* GET — the set list (createdAt desc, the store's order).
|
|
|
|
|
*/
|
|
|
|
|
import { createPracticeSetResponse, listPracticeSets, practiceErrorResponse } from "@/src/server";
|
|
|
|
|
|
|
|
|
|
export async function POST(req: Request) {
|
|
|
|
|
let body: unknown;
|
|
|
|
|
try {
|
|
|
|
|
body = await req.json();
|
|
|
|
|
} catch {
|
|
|
|
|
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
return createPracticeSetResponse(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
|
try {
|
|
|
|
|
return Response.json({ sets: listPracticeSets() });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return practiceErrorResponse(err);
|
|
|
|
|
}
|
|
|
|
|
}
|