Spaces:
Sleeping
Sleeping
| import { NextRequest, NextResponse } from "next/server"; | |
| import { createClient } from "@/lib/supabase/server"; | |
| export async function GET(req: NextRequest) { | |
| const supabase = await createClient(); | |
| const { data: { user } } = await supabase.auth.getUser(); | |
| if (!user) { | |
| return NextResponse.json({ error: "Not authenticated" }, { status: 401 }); | |
| } | |
| const url = new URL(req.url); | |
| const limit = Math.min(parseInt(url.searchParams.get("limit") || "20"), 100); | |
| const offset = parseInt(url.searchParams.get("offset") || "0"); | |
| const { data: analyses, count, error } = await supabase | |
| .from("analyses") | |
| .select("*", { count: "exact" }) | |
| .eq("user_id", user.id) | |
| .order("created_at", { ascending: false }) | |
| .range(offset, offset + limit - 1); | |
| if (error) { | |
| return NextResponse.json({ error: error.message }, { status: 500 }); | |
| } | |
| return NextResponse.json({ | |
| analyses: analyses || [], | |
| total: count || 0, | |
| limit, | |
| offset, | |
| }); | |
| } | |