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/mock/timeline.ts | 62 +++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'Timeline/ClientApp/src/app/http/mock') diff --git a/Timeline/ClientApp/src/app/http/mock/timeline.ts b/Timeline/ClientApp/src/app/http/mock/timeline.ts index 2a34ef10..911da2f2 100644 --- a/Timeline/ClientApp/src/app/http/mock/timeline.ts +++ b/Timeline/ClientApp/src/app/http/mock/timeline.ts @@ -31,6 +31,7 @@ async function setTimelineNameList(newOne: string[]): Promise { type TimelinePropertyKey = | 'uniqueId' + | 'lastModified' | 'owner' | 'description' | 'visibility' @@ -61,6 +62,14 @@ function setTimelinePropertyValue( .then(); } +function updateTimelineLastModified(name: string): Promise { + return setTimelinePropertyValue( + name, + 'lastModified', + new Date().toISOString() + ); +} + interface HttpTimelineInfoEx extends HttpTimelineInfo { memberUsernames: string[]; } @@ -98,6 +107,7 @@ async function getTimelineInfo(name: string): Promise { if (optionalUniqueId == null) { await setTimelineNameList([...(await getTimelineNameList()), name]); await setTimelinePropertyValue(name, 'uniqueId', createUniqueId()); + await updateTimelineLastModified(name); } } else { const optionalOwnerUsername = await getTimelinePropertyValue( @@ -131,6 +141,9 @@ async function getTimelineInfo(name: string): Promise { name, 'visibility' )) ?? 'Register', + lastModified: new Date( + await getTimelinePropertyValue(name, 'lastModified') + ), members, memberUsernames, }; @@ -148,6 +161,7 @@ async function createTimeline(name: string, owner: string): Promise { await setTimelineNameList([...(await getTimelineNameList()), name]); await setTimelinePropertyValue(name, 'uniqueId', createUniqueId()); await setTimelinePropertyValue(name, 'owner', owner); + await updateTimelineLastModified(name); } type TimelinePostPropertyKey = @@ -304,10 +318,46 @@ export class MockHttpTimelineClient implements IHttpTimelineClient { }); } - async getTimeline(timelineName: string): Promise { + getTimeline(timelineName: string): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + } + ): Promise; + getTimeline( + timelineName: string, + query: { + checkUniqueId?: string; + ifModifiedSince: Date; + } + ): Promise; + async getTimeline( + timelineName: string, + query?: { + checkUniqueId?: string; + ifModifiedSince?: Date; + } + ): Promise { await mockPrepare(); try { - return await getTimelineInfo(timelineName); + const timeline = await getTimelineInfo(timelineName); + if (query != null && query.ifModifiedSince != null) { + if (timeline.lastModified >= query.ifModifiedSince) { + return timeline; + } else { + if ( + query.checkUniqueId != null && + timeline.uniqueId != query.checkUniqueId + ) { + return timeline; + } else { + return new NotModified(); + } + } + } + + return timeline; } catch (e) { if ( e instanceof MockTimelineNotExistError || @@ -342,7 +392,9 @@ export class MockHttpTimelineClient implements IHttpTimelineClient { _token: string ): Promise { await mockPrepare(); + let modified = false; if (req.description != null) { + modified = true; await setTimelinePropertyValue( timelineName, 'description', @@ -350,12 +402,16 @@ export class MockHttpTimelineClient implements IHttpTimelineClient { ); } if (req.visibility != null) { + modified = true; await setTimelinePropertyValue( timelineName, 'visibility', req.visibility ); } + if (modified) { + await updateTimelineLastModified(timelineName); + } return await getTimelineInfo(timelineName); } @@ -387,6 +443,7 @@ export class MockHttpTimelineClient implements IHttpTimelineClient { ...oldMembers, username, ]); + await updateTimelineLastModified(timelineName); } } @@ -407,6 +464,7 @@ export class MockHttpTimelineClient implements IHttpTimelineClient { 'members', without(oldMembers, username) ); + await updateTimelineLastModified(timelineName); } } -- cgit v1.2.3