From d10b76b54745eb6f4972339caa4219cb1f50ae52 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 6 Feb 2024 01:15:14 +0000 Subject: [API] Add the POST /api/v1/links api --- app/api/v1/links/route.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/api/v1/links/route.ts (limited to 'app/api/v1') diff --git a/app/api/v1/links/route.ts b/app/api/v1/links/route.ts new file mode 100644 index 00000000..9103830b --- /dev/null +++ b/app/api/v1/links/route.ts @@ -0,0 +1,28 @@ +import { authOptions } from "@/lib/auth"; +import prisma from "@/lib/prisma"; +import { getServerSession } from "next-auth"; +import { NextRequest, NextResponse } from "next/server"; + +interface NewLinkRequest { + url: string, +} + +export async function POST(request: NextRequest) { + // TODO: We probably should be using an API key here instead of the session; + const session = await getServerSession(authOptions); + if (!session) { + return new Response(null, { status: 401 }); + } + + // TODO: We need proper type assertion here + const body: NewLinkRequest = await request.json(); + + const link = await prisma.bookmarkedLink.create({ + data: { + url: body.url, + userId: session.user.id, + } + }) + + return NextResponse.json(link, { status: 201 }); +} -- cgit v1.2.3-70-g09d2