aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app/api/v1/bookmarks
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-10-20 15:40:51 +0000
committerMohamed Bassem <me@mbassem.com>2024-10-20 15:40:51 +0000
commit20e5225e0547978cab656e94a3519cd590a16d8a (patch)
tree729687533556348a3200c7b409177fbc7ad426b2 /apps/web/app/api/v1/bookmarks
parent10dcf2e7429601fcbde42e3d10c46c074dc9a28a (diff)
downloadkarakeep-20e5225e0547978cab656e94a3519cd590a16d8a.tar.zst
feature(api): Add REST APIs to manipulate lists and tags for bookmarks
Diffstat (limited to 'apps/web/app/api/v1/bookmarks')
-rw-r--r--apps/web/app/api/v1/bookmarks/[bookmarkId]/lists/route.ts18
-rw-r--r--apps/web/app/api/v1/bookmarks/[bookmarkId]/tags/route.ts45
2 files changed, 63 insertions, 0 deletions
diff --git a/apps/web/app/api/v1/bookmarks/[bookmarkId]/lists/route.ts b/apps/web/app/api/v1/bookmarks/[bookmarkId]/lists/route.ts
new file mode 100644
index 00000000..ad3052c9
--- /dev/null
+++ b/apps/web/app/api/v1/bookmarks/[bookmarkId]/lists/route.ts
@@ -0,0 +1,18 @@
+import { NextRequest } from "next/server";
+import { buildHandler } from "@/app/api/v1/utils/handler";
+
+export const dynamic = "force-dynamic";
+
+export const GET = (
+ req: NextRequest,
+ params: { params: { bookmarkId: string } },
+) =>
+ buildHandler({
+ req,
+ handler: async ({ api }) => {
+ const resp = await api.lists.getListsOfBookmark({
+ bookmarkId: params.params.bookmarkId,
+ });
+ return { status: 200, resp };
+ },
+ });
diff --git a/apps/web/app/api/v1/bookmarks/[bookmarkId]/tags/route.ts b/apps/web/app/api/v1/bookmarks/[bookmarkId]/tags/route.ts
new file mode 100644
index 00000000..df464618
--- /dev/null
+++ b/apps/web/app/api/v1/bookmarks/[bookmarkId]/tags/route.ts
@@ -0,0 +1,45 @@
+import { NextRequest } from "next/server";
+import { buildHandler } from "@/app/api/v1/utils/handler";
+import { z } from "zod";
+
+import { zManipulatedTagSchema } from "@hoarder/shared/types/bookmarks";
+
+export const dynamic = "force-dynamic";
+
+export const POST = (
+ req: NextRequest,
+ params: { params: { bookmarkId: string } },
+) =>
+ buildHandler({
+ req,
+ bodySchema: z.object({
+ tags: z.array(zManipulatedTagSchema),
+ }),
+ handler: async ({ api, body }) => {
+ const resp = await api.bookmarks.updateTags({
+ bookmarkId: params.params.bookmarkId,
+ attach: body!.tags,
+ detach: [],
+ });
+ return { status: 200, resp: { attached: resp.attached } };
+ },
+ });
+
+export const DELETE = (
+ req: NextRequest,
+ params: { params: { bookmarkId: string } },
+) =>
+ buildHandler({
+ req,
+ bodySchema: z.object({
+ tags: z.array(zManipulatedTagSchema),
+ }),
+ handler: async ({ api, body }) => {
+ const resp = await api.bookmarks.updateTags({
+ bookmarkId: params.params.bookmarkId,
+ detach: body!.tags,
+ attach: [],
+ });
+ return { status: 200, resp: { detached: resp.detached } };
+ },
+ });