diff options
author | crupest <crupest@outlook.com> | 2020-07-12 17:19:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-12 17:19:04 +0800 |
commit | 5b95c1f32db4daa91f70b8e586f7d4ce3b9956d2 (patch) | |
tree | 9aa60f83185e84a5ab5fb07d9957f2ea539ecd63 /Timeline/Controllers | |
parent | 15e7467e6089537f0f3e2290f14a99b8a1fc2d76 (diff) | |
parent | 8b1d160af7ae206690bbda12ec4c862e40f67287 (diff) | |
download | timeline-5b95c1f32db4daa91f70b8e586f7d4ce3b9956d2.tar.gz timeline-5b95c1f32db4daa91f70b8e586f7d4ce3b9956d2.tar.bz2 timeline-5b95c1f32db4daa91f70b8e586f7d4ce3b9956d2.zip |
Merge pull request #116 from crupest/fix-114
Back-end: Timleine If-Modified-Since and checkUniqueId.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r-- | Timeline/Controllers/TimelineController.cs | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 2330698f..72404ea3 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -94,11 +94,50 @@ namespace Timeline.Controllers }
[HttpGet("timelines/{name}")]
- public async Task<ActionResult<TimelineInfo>> TimelineGet([FromRoute][GeneralTimelineName] string name)
+ public async Task<ActionResult<TimelineInfo>> TimelineGet([FromRoute][GeneralTimelineName] string name, [FromQuery] string? checkUniqueId, [FromQuery(Name = "ifModifiedSince")] DateTime? queryIfModifiedSince, [FromHeader(Name = "If-Modified-Since")] DateTime? headerIfModifiedSince)
{
- var timeline = await _service.GetTimeline(name);
- var result = _mapper.Map<TimelineInfo>(timeline);
- return result;
+ DateTime? ifModifiedSince = null;
+ if (queryIfModifiedSince.HasValue)
+ {
+ ifModifiedSince = queryIfModifiedSince.Value;
+ }
+ else if (headerIfModifiedSince != null)
+ {
+ ifModifiedSince = headerIfModifiedSince.Value;
+ }
+
+ bool returnNotModified = false;
+
+ if (ifModifiedSince.HasValue)
+ {
+ var lastModified = await _service.GetTimelineLastModifiedTime(name);
+ if (lastModified < ifModifiedSince.Value)
+ {
+ if (checkUniqueId != null)
+ {
+ var uniqueId = await _service.GetTimelineUniqueId(name);
+ if (uniqueId == checkUniqueId)
+ {
+ returnNotModified = true;
+ }
+ }
+ else
+ {
+ returnNotModified = true;
+ }
+ }
+ }
+
+ if (returnNotModified)
+ {
+ return StatusCode(StatusCodes.Status304NotModified);
+ }
+ else
+ {
+ var timeline = await _service.GetTimeline(name);
+ var result = _mapper.Map<TimelineInfo>(timeline);
+ return result;
+ }
}
[HttpGet("timelines/{name}/posts")]
|