feat: add comparison and user API endpoints
New API routes under src/app/api/ for comparisons and user operations.
This commit is contained in:
24
src/app/api/comparisons/[slug]/route.ts
Normal file
24
src/app/api/comparisons/[slug]/route.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user