From cd542259a926eca303517d6077b2cb8c8e27ef09 Mon Sep 17 00:00:00 2001 From: kertenkerem Date: Thu, 8 Jan 2026 02:57:38 +0300 Subject: [PATCH] feat: implement lesson creation directly on the schedule calendar via a new API endpoint and database updates. --- prisma/dev.db | Bin 94208 -> 94208 bytes src/app/api/lessons/route.ts | 65 +++++++ src/app/page.tsx | 2 +- src/components/ScheduleCalendar.tsx | 235 ++++++++++++++++++++++-- src/presentation/components/Sidebar.tsx | 3 +- 5 files changed, 287 insertions(+), 18 deletions(-) create mode 100644 src/app/api/lessons/route.ts diff --git a/prisma/dev.db b/prisma/dev.db index 764d9c2f7e105393f480c865a210fc551025baf4..7082937c19993bfb5130bce13b4312bf6e955a6a 100644 GIT binary patch delta 756 zcma*kJ8KkC6bJCRnZ1ZI+0jOe5j9~TS{yR>IeTps7JPvZkST@SxpOZpiU~pjB9fiP z(g)kQiX8U9DWD>XSj!ld-!>R(ibQDD6N-1 zEuoduqwSk%gvKv7zCQH%^U?9oXHX~W;%Fy```x$QL$iZuXZzUEFVVF+!BG)lJco+O z$Sa=HjB{W))xe!&pvqhW8;i%gK5R}zHvEpy`>XyI)s znP8MVZcF3U=yBk)e|LEK!Sd=#*i^l{oQ`&%rKi06>&?f1c_at|9P=Rl5xtqF_;@{<+qRd^U@&suo45=gGpY1yX0$YQXWWy2qN E0H{Y1h5!Hn 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() {
- +