From 9c0cb8f8d3944c813ef28ff9f736f148fd701a66 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 11 Apr 2022 22:59:41 +0800 Subject: ... --- FrontEnd/src/http/bookmark.ts | 95 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 19 deletions(-) (limited to 'FrontEnd/src/http/bookmark.ts') diff --git a/FrontEnd/src/http/bookmark.ts b/FrontEnd/src/http/bookmark.ts index 3e5be229..382543ff 100644 --- a/FrontEnd/src/http/bookmark.ts +++ b/FrontEnd/src/http/bookmark.ts @@ -1,36 +1,93 @@ -import { axios, apiBaseUrl, extractResponseData } from "./common"; +import { applyQueryParameters } from "@/utilities/url"; +import { axios, apiBaseUrl, extractResponseData, Page } from "./common"; -import { HttpTimelineInfo } from "./timeline"; - -export interface HttpHighlightMoveRequest { - timeline: string; - newPosition: number; +export interface TimelineBookmark { + timelineOwner: string; + timelineName: string; + position: number; } export interface IHttpBookmarkClient { - list(): Promise; - put(timeline: string): Promise; - delete(timeline: string): Promise; - move(req: HttpHighlightMoveRequest): Promise; + 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(): Promise { + list( + username: string, + page?: number, + pageSize?: number + ): Promise> { + const url = applyQueryParameters( + `${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 - .get(`${apiBaseUrl}/bookmarks`) + .post(url, { + timelineOwner, + timelineName, + }) .then(extractResponseData); } - put(timeline: string): Promise { - return axios.put(`${apiBaseUrl}/bookmarks/${timeline}`).then(); - } + delete( + username: string, + timelineOwner: string, + timelineName: string + ): Promise { + const url = `${apiBaseUrl}/v2/users/${username}/bookmarks/delete`; - delete(timeline: string): Promise { - return axios.delete(`${apiBaseUrl}/bookmarks/${timeline}`).then(); + return axios.post(url, { + timelineOwner, + timelineName, + }); } - move(req: HttpHighlightMoveRequest): Promise { - return axios.post(`${apiBaseUrl}/bookmarkop/move`, req).then(); + 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); } } -- cgit v1.2.3