// =======================================================================
// src/routes/api/movies/+server.ts (확장자 변경 및 타입 추가)
// =======================================================================
import { json } from '@sveltejs/kit';
import pool from '$lib/server/database';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async () => {
  try {
    const result = await pool.query<{ IndexMovie: number }>(
      'SELECT DISTINCT "IndexMovie" FROM public."TumerDatasetRef" ORDER BY "IndexMovie" ASC'
    );
    return json(result.rows.map(row => row.IndexMovie));
  } catch (err) {
    console.error('API Error fetching movies:', err);
    return json({ error: 'Failed to fetch movie list' }, { status: 500 });
  }
};
