aboutsummaryrefslogtreecommitdiffstats
path: root/web/app/api
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-02-08 15:14:23 +0000
committerMohamedBassem <me@mbassem.com>2024-02-08 15:15:21 +0000
commit80bb8a108f29331cdb2f2695f6801beee104dc89 (patch)
treeb1ae2a512963a9c916c4bfed71f7633f508de131 /web/app/api
parent333429adbaaa592cc96b480a5228f0e3f1de4cc2 (diff)
downloadkarakeep-80bb8a108f29331cdb2f2695f6801beee104dc89.tar.zst
[refactor] Move the different packages to the package subdir
Diffstat (limited to 'web/app/api')
-rw-r--r--web/app/api/auth/[...nextauth]/route.tsx3
-rw-r--r--web/app/api/v1/links/[linkId]/route.ts32
-rw-r--r--web/app/api/v1/links/route.ts49
3 files changed, 0 insertions, 84 deletions
diff --git a/web/app/api/auth/[...nextauth]/route.tsx b/web/app/api/auth/[...nextauth]/route.tsx
deleted file mode 100644
index e722926b..00000000
--- a/web/app/api/auth/[...nextauth]/route.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import { authHandler } from "@/lib/auth";
-
-export { authHandler as GET, authHandler as POST };
diff --git a/web/app/api/v1/links/[linkId]/route.ts b/web/app/api/v1/links/[linkId]/route.ts
deleted file mode 100644
index 39449d6d..00000000
--- a/web/app/api/v1/links/[linkId]/route.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { authOptions } from "@/lib/auth";
-import { unbookmarkLink } from "@/lib/services/links";
-import { Prisma } from "@remember/db";
-
-import { getServerSession } from "next-auth";
-import { NextRequest } from "next/server";
-
-export async function DELETE(
- _request: NextRequest,
- { params }: { params: { linkId: string } },
-) {
- // 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 });
- }
-
- try {
- await unbookmarkLink(params.linkId, session.user.id);
- } catch (e: unknown) {
- if (
- e instanceof Prisma.PrismaClientKnownRequestError &&
- e.code === "P2025" // RecordNotFound
- ) {
- return new Response(null, { status: 404 });
- } else {
- throw e;
- }
- }
-
- return new Response(null, { status: 201 });
-}
diff --git a/web/app/api/v1/links/route.ts b/web/app/api/v1/links/route.ts
deleted file mode 100644
index 87541634..00000000
--- a/web/app/api/v1/links/route.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { authOptions } from "@/lib/auth";
-import { bookmarkLink, getLinks } from "@/lib/services/links";
-
-import {
- zNewBookmarkedLinkRequestSchema,
- ZGetLinksResponse,
- ZBookmarkedLink,
-} from "@/lib/types/api/links";
-import { getServerSession } from "next-auth";
-import { NextRequest, NextResponse } from "next/server";
-
-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 });
- }
-
- const linkRequest = zNewBookmarkedLinkRequestSchema.safeParse(
- await request.json(),
- );
-
- if (!linkRequest.success) {
- return NextResponse.json(
- {
- error: linkRequest.error.toString(),
- },
- { status: 400 },
- );
- }
-
- const link = await bookmarkLink(linkRequest.data.url, session.user.id);
-
- let response: ZBookmarkedLink = { ...link };
- return NextResponse.json(response, { status: 201 });
-}
-
-export async function GET() {
- // 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 });
- }
-
- const links = await getLinks(session.user.id);
-
- let response: ZGetLinksResponse = { links };
- return NextResponse.json(response);
-}