| 1 | import { NextResponse, type NextRequest } from "next/server"; |
| 2 | import { parsePaging, type ItemList } from "@/lib/db"; |
| 3 | import { getAwardsFiltered, type Award } from "@/lib/feed"; |
| 4 | |
| 5 | export const dynamic = "force-dynamic"; |
| 6 | |
| 7 | |
| 8 | export async function GET(req: NextRequest) { |
| 9 | const sp = req.nextUrl.searchParams; |
| 10 | const { limit, offset } = parsePaging(sp); |
| 11 | const q = sp.get("q") || undefined; |
| 12 | const sortParam = sp.get("sort") ?? ""; |
| 13 | const sort = |
| 14 | sortParam === "date" ? "date" : |
| 15 | sortParam === "agency" ? "agency" : |
| 16 | undefined; |
| 17 | |
| 18 | const allItems = getAwardsFiltered(q, sort); |
| 19 | const total = allItems.length; |
| 20 | const items = allItems.slice(offset, offset + limit); |
| 21 | const body: ItemList<Award> = { items, total, limit, offset }; |
| 22 | return NextResponse.json(body); |
| 23 | } |