diff options
author | crupest <crupest@outlook.com> | 2020-02-05 18:24:10 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-02-05 18:24:10 +0800 |
commit | 810e4cb23f37809252e7767a988a68a146aca7bc (patch) | |
tree | af98ca8a7a1c9072789ba5de7ea6dc2c07f5e5b9 /Timeline/Controllers | |
parent | 03c9d4edc4e321db8c1b70ae621f77fa89664dfc (diff) | |
download | timeline-810e4cb23f37809252e7767a988a68a146aca7bc.tar.gz timeline-810e4cb23f37809252e7767a988a68a146aca7bc.tar.bz2 timeline-810e4cb23f37809252e7767a988a68a146aca7bc.zip |
Improve relate filter.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r-- | Timeline/Controllers/TimelineController.cs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 811b0426..47b3696c 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Timeline.Filters;
using Timeline.Models.Http;
@@ -28,14 +29,21 @@ namespace Timeline.Controllers }
[HttpGet("timelines")]
- public async Task<ActionResult<List<TimelineInfo>>> TimelineList([FromQuery][Username] string? relate)
+ public async Task<ActionResult<List<TimelineInfo>>> TimelineList([FromQuery][Username] string? relate, [FromQuery][RegularExpression("(own)|(join)")] string? relateType)
{
- long? relatedUserId = null;
+ TimelineUserRelationship? relationship = null;
if (relate != null)
{
try
{
- relatedUserId = await _userService.GetUserIdByUsername(relate);
+ var relatedUserId = await _userService.GetUserIdByUsername(relate);
+
+ relationship = new TimelineUserRelationship(relateType switch
+ {
+ "own" => TimelineUserRelationshipType.Own,
+ "join" => TimelineUserRelationshipType.Join,
+ _ => TimelineUserRelationshipType.Default
+ }, relatedUserId);
}
catch (UserNotExistException)
{
@@ -43,7 +51,7 @@ namespace Timeline.Controllers }
}
- var result = await _service.GetTimelines(relatedUserId);
+ var result = await _service.GetTimelines(relationship);
result.ForEach(t => t.FillLinks(Url));
return Ok(result);
}
|