Skip to content

Commit

Permalink
feature: Add DELETE REST APIs for bookmarks, lists and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Oct 20, 2024
1 parent 62395ec commit 719e25d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
14 changes: 14 additions & 0 deletions apps/web/app/api/v1/bookmarks/[bookmarkId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ export const GET = (
return { status: 200, resp: bookmark };
},
});

export const DELETE = (
req: NextRequest,
{ params }: { params: { bookmarkId: string } },
) =>
buildHandler({
req,
handler: async ({ api }) => {
await api.bookmarks.deleteBookmark({
bookmarkId: params.bookmarkId,
});
return { status: 204 };
},
});
16 changes: 16 additions & 0 deletions apps/web/app/api/v1/lists/[listId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ export const GET = (
};
},
});

export const DELETE = (
req: NextRequest,
{ params }: { params: { listId: string } },
) =>
buildHandler({
req,
handler: async ({ api }) => {
await api.lists.delete({
listId: params.listId,
});
return {
status: 204,
};
},
});
16 changes: 16 additions & 0 deletions apps/web/app/api/v1/tags/[tagId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ export const GET = (
};
},
});

export const DELETE = (
req: NextRequest,
{ params }: { params: { tagId: string } },
) =>
buildHandler({
req,
handler: async ({ api }) => {
await api.tags.delete({
tagId: params.tagId,
});
return {
status: 204,
};
},
});
4 changes: 2 additions & 2 deletions apps/web/app/api/v1/utils/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function buildHandler<
bodySchema,
}: {
req: NextRequest;
handler: (req: InputT) => Promise<{ status: number; resp: object }>;
handler: (req: InputT) => Promise<{ status: number; resp?: object }>;
searchParamsSchema?: SearchParamsT | undefined;
bodySchema?: BodyT | undefined;
}) {
Expand All @@ -108,7 +108,7 @@ export async function buildHandler<
body,
} as InputT);

return new Response(JSON.stringify(resp), {
return new Response(resp ? JSON.stringify(resp) : null, {
status,
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 719e25d

Please sign in to comment.