Working prototype
This commit is contained in:
1 parent
a1f6dd7b08
commit
5cd6f3c640
20 files changed
+2392
-151
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import { toNoteDto } from "@/lib/notes";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { createNoteSchema } from "@/lib/validation";
|
||||
|
||||
export async function GET() {
|
||||
const notes = await prisma.note.findMany({ orderBy: { createdAt: "desc" } });
|
||||
return Response.json(notes.map(toNoteDto));
|
||||
}
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const input = createNoteSchema.safeParse(await request.json());
|
||||
if (!input.success) return Response.json({ error: input.error.issues[0]?.message ?? "Некорректные данные." }, { status: 400 });
|
||||
const note = await prisma.note.create({ data: input.data });
|
||||
return Response.json(toNoteDto(note), { status: 201 });
|
||||
} catch { return Response.json({ error: "Некорректный JSON-запрос." }, { status: 400 }); }
|
||||
}
|
||||
Reference in new issue
Block a user