aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-22 21:33:42 +0800
committerGitHub <noreply@github.com>2020-02-22 21:33:42 +0800
commit4475246be00d0f9d1a5df6c181589ed0b2a7009b (patch)
tree1897dc26074fb5b8aba2e2493b4c393279f6d4b4 /Timeline/Services
parent77c28a63bdd742a46bcf780ae3819c18b7fbf9d2 (diff)
parent98dabdd9462384353389a6834b9e71a3e40330a2 (diff)
downloadtimeline-4475246be00d0f9d1a5df6c181589ed0b2a7009b.tar.gz
timeline-4475246be00d0f9d1a5df6c181589ed0b2a7009b.tar.bz2
timeline-4475246be00d0f9d1a5df6c181589ed0b2a7009b.zip
Merge pull request #60 from crupest/dev
Add visibility query filter in get timelines api.
Diffstat (limited to 'Timeline/Services')
-rw-r--r--Timeline/Services/TimelineService.cs22
-rw-r--r--Timeline/Services/UserTokenManager.cs3
2 files changed, 18 insertions, 7 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs
index 7afc0512..76acc7d7 100644
--- a/Timeline/Services/TimelineService.cs
+++ b/Timeline/Services/TimelineService.cs
@@ -251,11 +251,12 @@ namespace Timeline.Services
/// Get all timelines including personal timelines.
/// </summary>
/// <param name="relate">Filter timelines related (own or is a member) to specific user.</param>
+ /// <param name="visibility">Filter timelines with given visibility. If null or empty, all visibilities are returned. Duplicate value are ignored.</param>
/// <returns>The list of timelines.</returns>
/// <remarks>
/// If user with related user id does not exist, empty list will be returned.
/// </remarks>
- Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null);
+ Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null);
/// <summary>
/// Create a timeline.
@@ -647,13 +648,24 @@ namespace Timeline.Services
}
}
- public async Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null)
+ public async Task<List<TimelineInfo>> GetTimelines(TimelineUserRelationship? relate = null, List<TimelineVisibility>? visibility = null)
{
List<TimelineEntity> entities;
+ IQueryable<TimelineEntity> ApplyTimelineVisibilityFilter(IQueryable<TimelineEntity> query)
+ {
+ if (visibility != null && visibility.Count != 0)
+ {
+ return query.Where(t => visibility.Contains(t.Visibility));
+ }
+ return query;
+ }
+
+ bool allVisibilities = visibility == null || visibility.Count == 0;
+
if (relate == null)
{
- entities = await Database.Timelines.Include(t => t.Members).ToListAsync();
+ entities = await ApplyTimelineVisibilityFilter(Database.Timelines).Include(t => t.Members).ToListAsync();
}
else
{
@@ -661,12 +673,12 @@ namespace Timeline.Services
if ((relate.Type & TimelineUserRelationshipType.Own) != 0)
{
- entities.AddRange(await Database.Timelines.Where(t => t.OwnerId == relate.UserId && t.Name != null).Include(t => t.Members).ToListAsync());
+ entities.AddRange(await ApplyTimelineVisibilityFilter(Database.Timelines.Where(t => t.OwnerId == relate.UserId)).Include(t => t.Members).ToListAsync());
}
if ((relate.Type & TimelineUserRelationshipType.Join) != 0)
{
- entities.AddRange(await Database.TimelineMembers.Where(m => m.UserId == relate.UserId).Include(m => m.Timeline).ThenInclude(t => t.Members).Select(m => m.Timeline).ToListAsync());
+ entities.AddRange(await ApplyTimelineVisibilityFilter(Database.TimelineMembers.Where(m => m.UserId == relate.UserId).Include(m => m.Timeline).ThenInclude(t => t.Members).Select(m => m.Timeline)).ToListAsync());
}
}
diff --git a/Timeline/Services/UserTokenManager.cs b/Timeline/Services/UserTokenManager.cs
index 3e9ef3d4..4e54c4cd 100644
--- a/Timeline/Services/UserTokenManager.cs
+++ b/Timeline/Services/UserTokenManager.cs
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
-using Timeline.Models;
namespace Timeline.Services
{
@@ -21,7 +20,7 @@ namespace Timeline.Services
/// <param name="expireAt">The expire time of the token.</param>
/// <returns>The created token and the user info.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="username"/> or <paramref name="password"/> is null.</exception>
- /// <exception cref="UsernameBadFormatException">Thrown when <paramref name="username"/> is of bad format.</exception>
+ /// <exception cref="ArgumentException">Thrown when <paramref name="username"/> is of bad format.</exception>
/// <exception cref="UserNotExistException">Thrown when the user with <paramref name="username"/> does not exist.</exception>
/// <exception cref="BadPasswordException">Thrown when <paramref name="password"/> is wrong.</exception>
public Task<UserTokenCreateResult> CreateToken(string username, string password, DateTime? expireAt = null);