diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-10-20 13:54:05 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-10-20 14:08:24 +0000 |
| commit | fb297eaadee9b741ddb6731a91eb4648020dcb3b (patch) | |
| tree | 42b5c779dab4ef4d6afbd3a41cbcd6c4d5c86f07 /apps/web/app/api/v1/bookmarks | |
| parent | a822ff26ce83db867d4589181d21da20592fbf7c (diff) | |
| download | karakeep-fb297eaadee9b741ddb6731a91eb4648020dcb3b.tar.zst | |
featue: Add infra for REST APIs and implement GET /bookmarks
Diffstat (limited to 'apps/web/app/api/v1/bookmarks')
| -rw-r--r-- | apps/web/app/api/v1/bookmarks/route.ts | 25 |
1 files changed, 25 insertions, 0 deletions
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) }; + }, + }); |
