diff --git a/prisma/dev.db b/prisma/dev.db index 764d9c2..7082937 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/src/app/api/lessons/route.ts b/src/app/api/lessons/route.ts new file mode 100644 index 0000000..458bec2 --- /dev/null +++ b/src/app/api/lessons/route.ts @@ -0,0 +1,65 @@ +import { prisma } from "@/infrastructure/db/prisma"; +import { NextResponse } from "next/server"; + +export async function GET() { + try { + const lessons = await prisma.lesson.findMany({ + include: { + instructor: true, + branch: true, + class: true, + }, + }); + return NextResponse.json(lessons); + } catch (error) { + return NextResponse.json({ error: "Dersler yüklenemedi" }, { status: 500 }); + } +} + +export async function POST(request: Request) { + try { + const json = await request.json(); + const { startTime, endTime, instructorId, branchId, classId, type, hallNumber, occurrenceCount = 1, period = 'NONE' } = json; + + const start = new Date(startTime); + const end = new Date(endTime); + const lessons = []; + + for (let i = 0; i < occurrenceCount; i++) { + const currentStart = new Date(start); + const currentEnd = new Date(end); + + if (period === 'DAILY') { + currentStart.setDate(start.getDate() + i); + currentEnd.setDate(end.getDate() + i); + } else if (period === 'WEEKLY') { + currentStart.setDate(start.getDate() + (i * 7)); + currentEnd.setDate(end.getDate() + (i * 7)); + } else if (period === 'MONTHLY') { + currentStart.setMonth(start.getMonth() + i); + currentEnd.setMonth(end.getMonth() + i); + } else if (period === 'SIX_MONTHLY') { + currentStart.setMonth(start.getMonth() + (i * 6)); + currentEnd.setMonth(end.getMonth() + (i * 6)); + } + + const lesson = await prisma.lesson.create({ + data: { + startTime: currentStart, + endTime: currentEnd, + type, + hallNumber: parseInt(hallNumber), + branchId, + instructorId, + classId: classId || null, + } + }); + lessons.push(lesson); + } + + return NextResponse.json({ message: `${lessons.length} ders başarıyla oluşturuldu`, lessons }); + } catch (error: any) { + console.error('Lesson creation error:', error); + return NextResponse.json({ error: "Ders oluşturulamadı", details: error.message }, { status: 500 }); + } +} diff --git a/src/app/page.tsx b/src/app/page.tsx index c5feb9d..3310be4 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -46,7 +46,7 @@ export default async function Home() {
- +