feat: add comparison and user API endpoints

New API routes under src/app/api/ for comparisons and user operations.
This commit is contained in:
Christopher Mayor
2026-04-26 15:57:58 -07:00
parent 3c5df6a74c
commit c9e6e156ac
4 changed files with 181 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { db } from "@/lib/db";
import { comparisons } from "@/lib/db/schema";
import { eq, sql } from "drizzle-orm";
import { getComparison } from "@/app/actions/comparison";
export async function GET(
_request: Request,
{ params }: { params: Promise<{ slug: string }> }
) {
const { slug } = await params;
await db
.update(comparisons)
.set({ viewCount: sql`${comparisons.viewCount} + 1` })
.where(eq(comparisons.slug, slug));
const comparison = await getComparison(slug);
if (!comparison) {
return Response.json({ error: "Not found" }, { status: 404 });
}
return Response.json(comparison);
}