aboutsummaryrefslogtreecommitdiffstats
path: root/app/api/v1
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-02-06 01:15:14 +0000
committerMohamedBassem <me@mbassem.com>2024-02-06 01:15:14 +0000
commitd10b76b54745eb6f4972339caa4219cb1f50ae52 (patch)
tree22cf575aeb173c8b100e8adc71620efedec2b3fc /app/api/v1
parent81531a46c368293b736bb3b12c413cfbe6e00ec4 (diff)
downloadkarakeep-d10b76b54745eb6f4972339caa4219cb1f50ae52.tar.zst
[API] Add the POST /api/v1/links api
Diffstat (limited to 'app/api/v1')
-rw-r--r--app/api/v1/links/route.ts28
1 files changed, 28 insertions, 0 deletions
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 });
+}