import { NextRequest, NextResponse } from 'next/server' import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url) const type = searchParams.get('type') || 'all' console.log(`πŸ” 使用 SQL ε³ζ™‚ζ•Έζ“šη²ε–: type=${type}`) // δ½Ώη”¨εŽŸε§‹ SQL ζŸ₯詒避免 Prisma ηš„ζŽ’εΊε•ι‘Œ let wishes if (type === 'public') { wishes = await prisma.$queryRaw` SELECT id, title, current_pain, expected_solution, expected_effect, is_public, email, images, user_session, status, category, priority, created_at, updated_at FROM wishes WHERE is_public = true AND status = 'active' LIMIT 100 ` } else { wishes = await prisma.$queryRaw` SELECT id, title, current_pain, expected_solution, expected_effect, is_public, email, images, user_session, status, category, priority, created_at, updated_at FROM wishes WHERE status = 'active' LIMIT 100 ` } console.log(`βœ… ζˆεŠŸη²ε– ${(wishes as any[]).length} η­†ε›°ζ“Ύζ‘ˆδΎ‹ (type: ${type})`) // θ½‰ζ›ζ•Έζ“šζ ΌεΌ const formattedWishes = (wishes as any[]).map((wish) => ({ id: Number(wish.id), title: wish.title, current_pain: wish.current_pain, expected_solution: wish.expected_solution, expected_effect: wish.expected_effect, is_public: Boolean(wish.is_public), email: wish.email, images: wish.images, user_session: wish.user_session, status: wish.status, category: wish.category, priority: Number(wish.priority), like_count: 0, // ζš«ζ™‚θ¨­η‚Ί 0 created_at: wish.created_at ? new Date(wish.created_at).toISOString() : new Date().toISOString(), updated_at: wish.updated_at ? new Date(wish.updated_at).toISOString() : new Date().toISOString() })) console.log(`βœ… ζˆεŠŸεΎžθ³‡ζ–™εΊ«η²ε– ${formattedWishes.length} η­†ε³ζ™‚ζ•Έζ“š`) return NextResponse.json({ success: true, data: formattedWishes }) } catch (error) { console.error('API Error:', error) return NextResponse.json( { success: false, error: error.message }, { status: 500 } ) } }