import { NextRequest, NextResponse } from 'next/server'; import supabase from '@/lib/db'; // GET - Ambil data mahasiswa dengan filter tahun angkatan untuk tabel detail export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url); const tahunAngkatan = searchParams.get('tahun_angkatan'); let query = supabase .from('mahasiswa') .select('nim, nama, status_kuliah, tahun_angkatan') .order('nama'); // Jika ada filter tahun angkatan, terapkan filter if (tahunAngkatan && tahunAngkatan !== 'all') { query = query.eq('tahun_angkatan', parseInt(tahunAngkatan)); } const { data, error } = await query; if (error) { console.error('Error fetching data:', error); return NextResponse.json( { message: 'Failed to fetch data', error: error.message }, { status: 500 } ); } return NextResponse.json(data || [], { headers: { 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', }, }); } catch (error) { console.error('Error in tabeldetail API:', error); return NextResponse.json( { message: 'Internal Server Error' }, { status: 500 } ); } }