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 +++++++++++++++++++++++++++++++++--------- FrontEnd/src/http/common.ts | 8 ++++ FrontEnd/src/http/highlight.ts | 49 ---------------------- FrontEnd/src/http/timeline.ts | 7 ++-- 4 files changed, 88 insertions(+), 71 deletions(-) delete mode 100644 FrontEnd/src/http/highlight.ts (limited to 'FrontEnd/src/http') 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); } } diff --git a/FrontEnd/src/http/common.ts b/FrontEnd/src/http/common.ts index e1672985..0a27b908 100644 --- a/FrontEnd/src/http/common.ts +++ b/FrontEnd/src/http/common.ts @@ -212,3 +212,11 @@ export function convertToBlobWithEtag(res: AxiosResponse): BlobWithEtag { export function extractEtag(res: AxiosResponse): string { return (res.headers as Record<"etag", string>)["etag"]; } + +export interface Page { + pageNumber: number; + pageSize: number; + totalPageCount: number; + totalCount: number; + items: T[]; +} diff --git a/FrontEnd/src/http/highlight.ts b/FrontEnd/src/http/highlight.ts deleted file mode 100644 index fddf0729..00000000 --- a/FrontEnd/src/http/highlight.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { axios, apiBaseUrl, extractResponseData } from "./common"; - -import { HttpTimelineInfo } from "./timeline"; - -export interface HttpHighlightMoveRequest { - timeline: string; - newPosition: number; -} - -export interface IHttpHighlightClient { - list(): Promise; - put(timeline: string): Promise; - delete(timeline: string): Promise; - move(req: HttpHighlightMoveRequest): Promise; -} - -export class HttpHighlightClient implements IHttpHighlightClient { - list(): Promise { - return axios - .get(`${apiBaseUrl}/highlights`) - .then(extractResponseData); - } - - put(timeline: string): Promise { - return axios.put(`${apiBaseUrl}/highlights/${timeline}`).then(); - } - - delete(timeline: string): Promise { - return axios.delete(`${apiBaseUrl}/highlights/${timeline}`).then(); - } - - move(req: HttpHighlightMoveRequest): Promise { - return axios.post(`${apiBaseUrl}/highlightop/move`, req).then(); - } -} - -let client: IHttpHighlightClient = new HttpHighlightClient(); - -export function getHttpHighlightClient(): IHttpHighlightClient { - return client; -} - -export function setHttpHighlightClient( - newClient: IHttpHighlightClient -): IHttpHighlightClient { - const old = client; - client = newClient; - return old; -} diff --git a/FrontEnd/src/http/timeline.ts b/FrontEnd/src/http/timeline.ts index 49a7b8f2..65717a83 100644 --- a/FrontEnd/src/http/timeline.ts +++ b/FrontEnd/src/http/timeline.ts @@ -8,6 +8,7 @@ import { extractResponseData, convertToIfStatusCodeIs, getHttpToken, + Page, } from "./common"; import { HttpUser } from "./user"; @@ -115,7 +116,7 @@ export interface IHttpTimelineClient { listPost( ownerUsername: string, timelineName: string - ): Promise; + ): Promise>; generatePostDataUrl( ownerUsername: string, timelineName: string, @@ -217,9 +218,9 @@ export class HttpTimelineClient implements IHttpTimelineClient { listPost( ownerUsername: string, timelineName: string - ): Promise { + ): Promise> { return axios - .get( + .get>( `${apiBaseUrl}/v2/timelines/${ownerUsername}/${timelineName}/posts` ) .then(extractResponseData); -- cgit v1.2.3