aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Controllers
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-12 17:12:47 +0800
committercrupest <crupest@outlook.com>2020-07-12 17:12:47 +0800
commit8b1d160af7ae206690bbda12ec4c862e40f67287 (patch)
tree9aa60f83185e84a5ab5fb07d9957f2ea539ecd63 /Timeline/Controllers
parentb5ea38b6606fea50ac4bc42dc4109dcff258b44b (diff)
downloadtimeline-8b1d160af7ae206690bbda12ec4c862e40f67287.tar.gz
timeline-8b1d160af7ae206690bbda12ec4c862e40f67287.tar.bz2
timeline-8b1d160af7ae206690bbda12ec4c862e40f67287.zip
Add http api and integrated tests.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r--Timeline/Controllers/TimelineController.cs47
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")]