import pool from "@/lib/db";
import { getSession } from "@/lib/auth";
import { NextResponse } from "next/server";

export async function GET() {
    try {
        const session = await getSession();
        if (!session) {
            return NextResponse.json({ message: "No autorizado" }, { status: 401 });
        }

        const [rows]: any = await pool.execute(
            "SELECT * FROM alumnos ORDER BY apellidos ASC, nombre ASC"
        );

        return NextResponse.json(rows);
    } catch (error) {
        console.error("Error fetching alumnos:", error);
        return NextResponse.json({ message: "Error interno" }, { status: 500 });
    }
}
