diff options
author | crupest <crupest@outlook.com> | 2022-04-11 22:59:41 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-11 22:59:41 +0800 |
commit | 9c0cb8f8d3944c813ef28ff9f736f148fd701a66 (patch) | |
tree | 69842e08eaf6d16a055d464d46ba435a188c8d39 /FrontEnd/src/http | |
parent | 65210138df643a475632690e2fb20401c1edbb95 (diff) | |
download | timeline-9c0cb8f8d3944c813ef28ff9f736f148fd701a66.tar.gz timeline-9c0cb8f8d3944c813ef28ff9f736f148fd701a66.tar.bz2 timeline-9c0cb8f8d3944c813ef28ff9f736f148fd701a66.zip |
...
Diffstat (limited to 'FrontEnd/src/http')
-rw-r--r-- | FrontEnd/src/http/bookmark.ts | 95 | ||||
-rw-r--r-- | FrontEnd/src/http/common.ts | 8 | ||||
-rw-r--r-- | FrontEnd/src/http/highlight.ts | 49 | ||||
-rw-r--r-- | FrontEnd/src/http/timeline.ts | 7 |
4 files changed, 88 insertions, 71 deletions
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<HttpTimelineInfo[]>; - put(timeline: string): Promise<void>; - delete(timeline: string): Promise<void>; - move(req: HttpHighlightMoveRequest): Promise<void>; + list( + username: string, + page?: number, + pageSize?: number + ): Promise<Page<TimelineBookmark>>; + post( + username: string, + timelineOwner: string, + timelineName: string + ): Promise<TimelineBookmark>; + delete( + username: string, + timelineOwner: string, + timelineName: string + ): Promise<void>; + move( + username: string, + timelineOwner: string, + timelineName: string, + position: number + ): Promise<TimelineBookmark>; } export class HttpHighlightClient implements IHttpBookmarkClient { - list(): Promise<HttpTimelineInfo[]> { + list( + username: string, + page?: number, + pageSize?: number + ): Promise<Page<TimelineBookmark>> { + const url = applyQueryParameters( + `${apiBaseUrl}/v2/users/${username}/bookmarks`, + { page, pageSize } + ); + + return axios.get<Page<TimelineBookmark>>(url).then(extractResponseData); + } + + post( + username: string, + timelineOwner: string, + timelineName: string + ): Promise<TimelineBookmark> { + const url = `${apiBaseUrl}/v2/users/${username}/bookmarks`; + return axios - .get<HttpTimelineInfo[]>(`${apiBaseUrl}/bookmarks`) + .post<TimelineBookmark>(url, { + timelineOwner, + timelineName, + }) .then(extractResponseData); } - put(timeline: string): Promise<void> { - return axios.put(`${apiBaseUrl}/bookmarks/${timeline}`).then(); - } + delete( + username: string, + timelineOwner: string, + timelineName: string + ): Promise<void> { + const url = `${apiBaseUrl}/v2/users/${username}/bookmarks/delete`; - delete(timeline: string): Promise<void> { - return axios.delete(`${apiBaseUrl}/bookmarks/${timeline}`).then(); + return axios.post(url, { + timelineOwner, + timelineName, + }); } - move(req: HttpHighlightMoveRequest): Promise<void> { - return axios.post(`${apiBaseUrl}/bookmarkop/move`, req).then(); + move( + username: string, + timelineOwner: string, + timelineName: string, + position: number + ): Promise<TimelineBookmark> { + const url = `${apiBaseUrl}/v2/users/${username}/bookmarks/move`; + + return axios + .post<TimelineBookmark>(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<Blob>): BlobWithEtag { export function extractEtag(res: AxiosResponse): string { return (res.headers as Record<"etag", string>)["etag"]; } + +export interface Page<T> { + 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<HttpTimelineInfo[]>; - put(timeline: string): Promise<void>; - delete(timeline: string): Promise<void>; - move(req: HttpHighlightMoveRequest): Promise<void>; -} - -export class HttpHighlightClient implements IHttpHighlightClient { - list(): Promise<HttpTimelineInfo[]> { - return axios - .get<HttpTimelineInfo[]>(`${apiBaseUrl}/highlights`) - .then(extractResponseData); - } - - put(timeline: string): Promise<void> { - return axios.put(`${apiBaseUrl}/highlights/${timeline}`).then(); - } - - delete(timeline: string): Promise<void> { - return axios.delete(`${apiBaseUrl}/highlights/${timeline}`).then(); - } - - move(req: HttpHighlightMoveRequest): Promise<void> { - 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<HttpTimelinePostInfo[]>; + ): Promise<Page<HttpTimelinePostInfo>>; generatePostDataUrl( ownerUsername: string, timelineName: string, @@ -217,9 +218,9 @@ export class HttpTimelineClient implements IHttpTimelineClient { listPost( ownerUsername: string, timelineName: string - ): Promise<HttpTimelinePostInfo[]> { + ): Promise<Page<HttpTimelinePostInfo>> { return axios - .get<HttpTimelinePostInfo[]>( + .get<Page<HttpTimelinePostInfo>>( `${apiBaseUrl}/v2/timelines/${ownerUsername}/${timelineName}/posts` ) .then(extractResponseData); |