From 08a5694e451218f1bcb2ad9eb42fd93250afbb96 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Fri, 9 Feb 2024 01:50:35 +0000 Subject: [refactor] Extract the bookmark model to be a high level model to support other type of bookmarks --- packages/web/lib/api.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'packages/web/lib/api.ts') diff --git a/packages/web/lib/api.ts b/packages/web/lib/api.ts index 56686cde..8ee08601 100644 --- a/packages/web/lib/api.ts +++ b/packages/web/lib/api.ts @@ -2,9 +2,9 @@ import { ZodTypeAny, z } from "zod"; import { - ZNewBookmarkedLinkRequest, - zGetLinksResponseSchema, -} from "./types/api/links"; + ZNewBookmarkRequest, + zGetBookmarksResponseSchema, +} from "./types/api/bookmarks"; import serverConfig from "./config"; @@ -57,24 +57,25 @@ async function doRequest( } export default class APIClient { - static async getLinks() { - return await doRequest(`/links`, zGetLinksResponseSchema, { + static async getBookmarks() { + return await doRequest(`/bookmarks`, zGetBookmarksResponseSchema, { next: { tags: ["links"] }, }); } static async bookmarkLink(url: string) { - const body: ZNewBookmarkedLinkRequest = { + const body: ZNewBookmarkRequest = { + type: "link", url, }; - return await doRequest(`/links`, undefined, { + return await doRequest(`/bookmarks`, undefined, { method: "POST", body: JSON.stringify(body), }); } - static async unbookmarkLink(linkId: string) { - return await doRequest(`/links/${linkId}`, undefined, { + static async deleteBookmark(id: string) { + return await doRequest(`/bookmarks/${id}`, undefined, { method: "DELETE", }); } -- cgit v1.2.3-70-g09d2