import { withQuery } from "@/utilities/url"; import { axios, apiBaseUrl, extractResponseData, Page } from "./common"; export interface TimelineBookmark { timelineOwner: string; timelineName: string; position: number; } export interface IHttpBookmarkClient { list( username: string, page?: number, pageSize?: number ): Promise>; post( username: string, timelineOwner: string, timelineName: string ): Promise; delete( username: string, timelineOwner: string, timelineName: string ): Promise; move( username: string, timelineOwner: string, timelineName: string, position: number ): Promise; } export class HttpHighlightClient implements IHttpBookmarkClient { list( username: string, page?: number, pageSize?: number ): Promise> { const url = withQuery(`${apiBaseUrl}/v2/users/${username}/bookmarks`, { page, pageSize, }); return axios.get>(url).then(extractResponseData); } post( username: string, timelineOwner: string, timelineName: string ): Promise { const url = `${apiBaseUrl}/v2/users/${username}/bookmarks`; return axios .post(url, { timelineOwner, timelineName, }) .then(extractResponseData); } delete( username: string, timelineOwner: string, timelineName: string ): Promise { const url = `${apiBaseUrl}/v2/users/${username}/bookmarks/delete`; return axios.post(url, { timelineOwner, timelineName, }); } move( username: string, timelineOwner: string, timelineName: string, position: number ): Promise { const url = `${apiBaseUrl}/v2/users/${username}/bookmarks/move`; return axios .post(url, { timelineOwner, timelineName, position, }) .then(extractResponseData); } } let client: IHttpBookmarkClient = new HttpHighlightClient(); export function getHttpBookmarkClient(): IHttpBookmarkClient { return client; } export function setHttpBookmarkClient( newClient: IHttpBookmarkClient ): IHttpBookmarkClient { const old = client; client = newClient; return old; }