From fb297eaadee9b741ddb6731a91eb4648020dcb3b Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 20 Oct 2024 13:54:05 +0000 Subject: featue: Add infra for REST APIs and implement GET /bookmarks --- apps/web/app/api/v1/bookmarks/route.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 apps/web/app/api/v1/bookmarks/route.ts (limited to 'apps/web/app/api/v1/bookmarks') diff --git a/apps/web/app/api/v1/bookmarks/route.ts b/apps/web/app/api/v1/bookmarks/route.ts new file mode 100644 index 00000000..0d58901d --- /dev/null +++ b/apps/web/app/api/v1/bookmarks/route.ts @@ -0,0 +1,25 @@ +import { NextRequest } from "next/server"; +import { z } from "zod"; + +import { buildHandler } from "../utils/handler"; +import { adaptPagination, zPagination } from "../utils/pagination"; +import { zStringBool } from "../utils/types"; + +export const dynamic = "force-dynamic"; + +export const GET = (req: NextRequest) => + buildHandler({ + req, + searchParamsSchema: z + .object({ + favourited: zStringBool.optional(), + archived: zStringBool.optional(), + }) + .and(zPagination), + handler: async ({ api, searchParams }) => { + const bookmarks = await api.bookmarks.getBookmarks({ + ...searchParams, + }); + return { status: 200, resp: adaptPagination(bookmarks) }; + }, + }); -- cgit v1.2.3-70-g09d2