import { NextRequest, NextResponse } from 'next/server'; import { supabase } from '@/lib/supabase'; export async function GET( request: NextRequest, { params }: { params: { id: string } } ) { const { data, error } = await supabase .from('project_members') .select('user_id, users(id, name, role, avatar_url)') .eq('project_id', params.id); if (error) { return NextResponse.json({ error: error.message }, { status: 500 }); } return NextResponse.json(data); } export async function POST( request: NextRequest, { params }: { params: { id: string } } ) { const body = await request.json(); const { user_id } = body; if (!user_id) { return NextResponse.json({ error: '用户ID为必填项' }, { status: 400 }); } const { data, error } = await supabase .from('project_members') .insert({ project_id: params.id, user_id }) .select() .single(); if (error) { return NextResponse.json({ error: error.message }, { status: 500 }); } return NextResponse.json(data, { status: 201 }); } export async function DELETE( request: NextRequest, { params }: { params: { id: string } } ) { const { searchParams } = new URL(request.url); const userId = searchParams.get('user_id'); if (!userId) { return NextResponse.json({ error: '用户ID为必填项' }, { status: 400 }); } const { error } = await supabase .from('project_members') .delete() .eq('project_id', params.id) .eq('user_id', userId); if (error) { return NextResponse.json({ error: error.message }, { status: 500 }); } return NextResponse.json({ success: true }); }