From 62395ecbbfef38686073369443d99249421b2e22 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 20 Oct 2024 14:23:15 +0000 Subject: feature: Add GET REST APIs for bookmarks, lists and tags --- .../web/app/api/v1/bookmarks/[bookmarkId]/route.ts | 18 ++++++++++++ apps/web/app/api/v1/lists/[listId]/route.ts | 33 ++++++++++++++++++++++ apps/web/app/api/v1/lists/route.ts | 14 +++++++++ apps/web/app/api/v1/tags/[tagId]/route.ts | 33 ++++++++++++++++++++++ apps/web/app/api/v1/tags/route.ts | 14 +++++++++ 5 files changed, 112 insertions(+) create mode 100644 apps/web/app/api/v1/bookmarks/[bookmarkId]/route.ts create mode 100644 apps/web/app/api/v1/lists/[listId]/route.ts create mode 100644 apps/web/app/api/v1/lists/route.ts create mode 100644 apps/web/app/api/v1/tags/[tagId]/route.ts create mode 100644 apps/web/app/api/v1/tags/route.ts (limited to 'apps/web/app') diff --git a/apps/web/app/api/v1/bookmarks/[bookmarkId]/route.ts b/apps/web/app/api/v1/bookmarks/[bookmarkId]/route.ts new file mode 100644 index 00000000..af4c0792 --- /dev/null +++ b/apps/web/app/api/v1/bookmarks/[bookmarkId]/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 bookmark = await api.bookmarks.getBookmark({ + bookmarkId: params.bookmarkId, + }); + return { status: 200, resp: bookmark }; + }, + }); diff --git a/apps/web/app/api/v1/lists/[listId]/route.ts b/apps/web/app/api/v1/lists/[listId]/route.ts new file mode 100644 index 00000000..205a779f --- /dev/null +++ b/apps/web/app/api/v1/lists/[listId]/route.ts @@ -0,0 +1,33 @@ +import { NextRequest } from "next/server"; +import { buildHandler } from "@/app/api/v1/utils/handler"; +import { adaptPagination, zPagination } from "@/app/api/v1/utils/pagination"; + +export const dynamic = "force-dynamic"; + +export const GET = ( + req: NextRequest, + { params }: { params: { listId: string } }, +) => + buildHandler({ + req, + searchParamsSchema: zPagination, + handler: async ({ api, searchParams }) => { + const [list, bookmarks] = await Promise.all([ + api.lists.get({ + listId: params.listId, + }), + api.bookmarks.getBookmarks({ + listId: params.listId, + limit: searchParams.limit, + cursor: searchParams.cursor, + }), + ]); + return { + status: 200, + resp: { + ...list, + ...adaptPagination(bookmarks), + }, + }; + }, + }); diff --git a/apps/web/app/api/v1/lists/route.ts b/apps/web/app/api/v1/lists/route.ts new file mode 100644 index 00000000..f2816219 --- /dev/null +++ b/apps/web/app/api/v1/lists/route.ts @@ -0,0 +1,14 @@ +import { NextRequest } from "next/server"; + +import { buildHandler } from "../utils/handler"; + +export const dynamic = "force-dynamic"; + +export const GET = (req: NextRequest) => + buildHandler({ + req, + handler: async ({ api }) => { + const lists = await api.lists.list(); + return { status: 200, resp: lists }; + }, + }); diff --git a/apps/web/app/api/v1/tags/[tagId]/route.ts b/apps/web/app/api/v1/tags/[tagId]/route.ts new file mode 100644 index 00000000..9c9d15fd --- /dev/null +++ b/apps/web/app/api/v1/tags/[tagId]/route.ts @@ -0,0 +1,33 @@ +import { NextRequest } from "next/server"; +import { buildHandler } from "@/app/api/v1/utils/handler"; +import { adaptPagination, zPagination } from "@/app/api/v1/utils/pagination"; + +export const dynamic = "force-dynamic"; + +export const GET = ( + req: NextRequest, + { params }: { params: { tagId: string } }, +) => + buildHandler({ + req, + searchParamsSchema: zPagination, + handler: async ({ api, searchParams }) => { + const [tag, bookmarks] = await Promise.all([ + api.tags.get({ + tagId: params.tagId, + }), + api.bookmarks.getBookmarks({ + tagId: params.tagId, + limit: searchParams.limit, + cursor: searchParams.cursor, + }), + ]); + return { + status: 200, + resp: { + ...tag, + ...adaptPagination(bookmarks), + }, + }; + }, + }); diff --git a/apps/web/app/api/v1/tags/route.ts b/apps/web/app/api/v1/tags/route.ts new file mode 100644 index 00000000..9625820c --- /dev/null +++ b/apps/web/app/api/v1/tags/route.ts @@ -0,0 +1,14 @@ +import { NextRequest } from "next/server"; + +import { buildHandler } from "../utils/handler"; + +export const dynamic = "force-dynamic"; + +export const GET = (req: NextRequest) => + buildHandler({ + req, + handler: async ({ api }) => { + const tags = await api.tags.list(); + return { status: 200, resp: tags }; + }, + }); -- cgit v1.2.3-70-g09d2