import { NextRequest, NextResponse } from 'next/server'; import prisma from '@/lib/prisma'; import { getCurrentUser } from '@/lib/auth'; import type { ListAppsResponse } from '@/types/api-types'; export async function GET(request: NextRequest) { try { const user = await getCurrentUser(); if (!user) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const { searchParams } = new URL(request.url); const limit = parseInt(searchParams.get('limit') || '50'); const offset = parseInt(searchParams.get('offset') || '0'); const [apps, total] = await Promise.all([ prisma.generatedApp.findMany({ where: { userId: user.id }, orderBy: { createdAt: 'desc' }, skip: offset, take: limit, select: { id: true, title: true, description: true, appType: true, status: true, createdAt: true, } }), prisma.generatedApp.count({ where: { userId: user.id } }) ]); const response: ListAppsResponse = { apps: apps.map(app => ({ id: app.id, title: app.title, description: app.description || undefined, appType: app.appType || undefined, status: app.status, createdAt: app.createdAt.toISOString(), })), total, }; return NextResponse.json(response, { status: 200 }); } catch (error) { console.error('List apps error:', error); return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); } }