Initial commit of Dance School App
This commit is contained in:
27
src/app/api/classes/route.ts
Normal file
27
src/app/api/classes/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/infrastructure/db/prisma';
|
||||
|
||||
export async function GET() {
|
||||
const classes = await prisma.danceClass.findMany({
|
||||
include: { branch: true, instructor: true },
|
||||
orderBy: { createdAt: 'desc' }
|
||||
});
|
||||
return NextResponse.json(classes);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const json = await request.json();
|
||||
const cls = await prisma.danceClass.create({
|
||||
data: {
|
||||
name: json.name,
|
||||
branchId: json.branchId, // required
|
||||
instructorId: json.instructorId || undefined, // optional?
|
||||
},
|
||||
});
|
||||
return NextResponse.json(cls);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ error: 'Failed' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user