From 9014a5b52e9810eb71bc88b3645b0e716a8576ca Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 31 Jul 2020 23:13:03 +0800 Subject: Add http get timeline api query params. --- Timeline/ClientApp/src/app/http/timeline.ts | 74 ++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 6 deletions(-) (limited to 'Timeline/ClientApp/src/app/http/timeline.ts') diff --git a/Timeline/ClientApp/src/app/http/timeline.ts b/Timeline/ClientApp/src/app/http/timeline.ts index 458ea6e6..bfe0d1ad 100644 --- a/Timeline/ClientApp/src/app/http/timeline.ts +++ b/Timeline/ClientApp/src/app/http/timeline.ts @@ -24,6 +24,7 @@ export interface HttpTimelineInfo { description: string; owner: HttpUser; visibility: TimelineVisibility; + lastModified: Date; members: HttpUser[]; } @@ -115,6 +116,16 @@ export class HttpTimelineNameConflictError extends Error { //-------------------- begin: internal model -------------------- +interface RawTimelineInfo { + uniqueId: string; + name: string; + description: string; + owner: HttpUser; + visibility: TimelineVisibility; + lastModified: string; + members: HttpUser[]; +} + interface RawTimelinePostTextContent { type: 'text'; text: string; @@ -171,6 +182,13 @@ interface RawTimelinePostPostRequest { //-------------------- end: internal model -------------------- +function processRawTimelineInfo(raw: RawTimelineInfo): HttpTimelineInfo { + return { + ...raw, + lastModified: new Date(raw.lastModified), + }; +} + function processRawTimelinePostInfo( raw: RawTimelinePostInfo ): HttpTimelinePostInfo; @@ -190,6 +208,19 @@ function processRawTimelinePostInfo( export interface IHttpTimelineClient { listTimeline(query: HttpTimelineListQuery): Promise; getTimeline(timelineName: string): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + } + ): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + ifModifiedSince: Date; + } + ): Promise; postTimeline( req: HttpTimelinePostRequest, token: string @@ -256,17 +287,46 @@ export interface IHttpTimelineClient { export class HttpTimelineClient implements IHttpTimelineClient { listTimeline(query: HttpTimelineListQuery): Promise { return axios - .get( + .get( applyQueryParameters(`${apiBaseUrl}/timelines`, query) ) .then(extractResponseData) + .then((list) => list.map(processRawTimelineInfo)) .catch(convertToNetworkError); } - getTimeline(timelineName: string): Promise { + getTimeline(timelineName: string): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + } + ): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + ifModifiedSince: Date; + } + ): Promise; + getTimeline( + timelineName: string, + query?: { + checkUniqueId?: string; + ifModifiedSince?: Date; + } + ): Promise { return axios - .get(`${apiBaseUrl}/timelines/${timelineName}`) - .then(extractResponseData) + .get( + applyQueryParameters(`${apiBaseUrl}/timelines/${timelineName}`, query) + ) + .then((res) => { + if (res.status === 304) { + return new NotModified(); + } else { + return processRawTimelineInfo(res.data); + } + }) .catch(convertToIfStatusCodeIs(404, HttpTimelineNotExistError)) .catch(convertToNetworkError); } @@ -276,8 +336,9 @@ export class HttpTimelineClient implements IHttpTimelineClient { token: string ): Promise { return axios - .post(`${apiBaseUrl}/timelines?token=${token}`, req) + .post(`${apiBaseUrl}/timelines?token=${token}`, req) .then(extractResponseData) + .then(processRawTimelineInfo) .catch(convertToIfErrorCodeIs(11040101, HttpTimelineNameConflictError)) .catch(convertToNetworkError); } @@ -288,11 +349,12 @@ export class HttpTimelineClient implements IHttpTimelineClient { token: string ): Promise { return axios - .patch( + .patch( `${apiBaseUrl}/timelines/${timelineName}?token=${token}`, req ) .then(extractResponseData) + .then(processRawTimelineInfo) .catch(convertToNetworkError); } -- cgit v1.2.3