diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-11 14:54:52 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-11 14:55:09 +0000 |
| commit | 2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d (patch) | |
| tree | c4738ba0bc011d60361f89aca9be3293474ab9e9 /packages/web/app/api/v1/bookmarks/route.ts | |
| parent | c2f1d6d8b8a0f09820153fc736806b147d46abfe (diff) | |
| download | karakeep-2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d.tar.zst | |
refactor: Migrating to trpc instead of next's route handers
Diffstat (limited to 'packages/web/app/api/v1/bookmarks/route.ts')
| -rw-r--r-- | packages/web/app/api/v1/bookmarks/route.ts | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/packages/web/app/api/v1/bookmarks/route.ts b/packages/web/app/api/v1/bookmarks/route.ts deleted file mode 100644 index 98e01080..00000000 --- a/packages/web/app/api/v1/bookmarks/route.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { authOptions } from "@/lib/auth"; -import { bookmarkLink, getBookmarks } from "@/lib/services/bookmarks"; - -import { - zNewBookmarkRequestSchema, - ZGetBookmarksResponse, - ZBookmark, - zGetBookmarksRequestSchema, -} from "@/lib/types/api/bookmarks"; -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 = zNewBookmarkRequestSchema.safeParse(await request.json()); - - if (!linkRequest.success) { - return NextResponse.json( - { - error: linkRequest.error.toString(), - }, - { status: 400 }, - ); - } - - const bookmark = await bookmarkLink(linkRequest.data.url, session.user.id); - - const response: ZBookmark = { ...bookmark }; - return NextResponse.json(response, { status: 201 }); -} - -export async function GET(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 query = request.nextUrl.searchParams; - const params = zGetBookmarksRequestSchema.safeParse(query); - - if (!params.success) { - return new Response(null, { status: 400 }); - } - - const bookmarks = await getBookmarks(session.user.id, params.data); - - const response: ZGetBookmarksResponse = { bookmarks }; - return NextResponse.json(response); -} |
