Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/app/api/ao/list/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/****
* AO list search API route.
*
* Responsibilities:
* - Parse and validate the search query parameter.
* - Guard against overly-broad searches.
* - Delegate AO search to the BigQuery layer.
*/
import { NextResponse } from "next/server";
import { searchAOsByName } from "@/lib/bq/aos";
import { getSessionUser } from "@/lib/auth/server";

export async function GET(request: Request) {
const user = await getSessionUser();
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const { searchParams } = new URL(request.url);
const rawQuery = searchParams.get("q") || "";
const q = rawQuery.trim();

// Guardrail: do not allow overly-broad or empty searches.
if (q.length < 2) {
return NextResponse.json([], { status: 200 });
}

try {
const aos = await searchAOsByName(q, user.email);
return NextResponse.json(aos, { status: 200 });
} catch (err) {
console.error("AO search failed:", err);
return NextResponse.json(
{ error: "AO search failed. Please try again." },
{ status: 500 },
);
}
}
5 changes: 4 additions & 1 deletion src/app/api/pax/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export async function GET(request: Request) {
return NextResponse.json([], { status: 200 });
}

const rawRegionId = searchParams.get("region_id");
const regionId = rawRegionId !== null ? parseInt(rawRegionId, 10) : undefined;

try {
const users = await searchUsersByName(q, user.email);
const users = await searchUsersByName(q, user.email, regionId);
return NextResponse.json(users, { status: 200 });
} catch (err) {
console.error("Pax search failed:", err);
Expand Down
Loading
Loading