From 810e4cb23f37809252e7767a988a68a146aca7bc Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 5 Feb 2020 18:24:10 +0800 Subject: Improve relate filter. --- Timeline/Controllers/TimelineController.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Timeline/Controllers') 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>> TimelineList([FromQuery][Username] string? relate) + public async Task>> 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); } -- cgit v1.2.3