Web.Api: added id, withRelated for feed filter

This commit is contained in:
Maksim Chegulov 2022-09-01 20:22:59 +03:00
parent 7c3af54718
commit 50175aad40
3 changed files with 25 additions and 4 deletions

View File

@ -28,6 +28,7 @@ namespace ASC.Feed;
public class FeedApiFilter
{
public string Id { get; set; }
public string Product { get; set; }
public DateTime From { get; set; }
public DateTime To { get; set; }
@ -36,4 +37,6 @@ public class FeedApiFilter
public Guid Author { get; set; }
public string[] SearchKeys { get; set; }
public bool OnlyNew { get; set; }
}
public bool WithoutMe { get; set; }
public bool WithRelated { get; set; }
}

View File

@ -205,13 +205,26 @@ public class FeedAggregateDataProvider
using var feedDbContext = _dbContextFactory.CreateDbContext();
var q = feedDbContext.FeedAggregates
.Where(r => r.Tenant == _tenantManager.GetCurrentTenant().Id)
.Where(r => r.ModifiedBy != _authContext.CurrentAccount.ID)
.Join(feedDbContext.FeedUsers, a => a.Id, b => b.FeedId, (aggregates, users) => new { aggregates, users })
.Where(r => r.users.UserId == _authContext.CurrentAccount.ID)
.OrderByDescending(r => r.aggregates.ModifiedDate)
.Skip(filter.Offset)
.Take(filter.Max);
if (filter.WithoutMe)
{
q = q.Where(r => r.aggregates.ModifiedBy != _authContext.CurrentAccount.ID);
}
if (filter.WithRelated && !string.IsNullOrEmpty(filter.Id))
{
q = q.Where(r => r.aggregates.Id == filter.Id || r.aggregates.ContextId == filter.Id);
}
else if (!string.IsNullOrEmpty(filter.Id))
{
q = q.Where(r => r.aggregates.Id == filter.Id);
}
if (filter.OnlyNew)
{
q = q.Where(r => r.aggregates.AggregateDate >= filter.From);

View File

@ -29,7 +29,6 @@ namespace ASC.Web.Api.Controllers;
[Scope]
[DefaultRoute]
[ApiController]
[ControllerName("feeds")]
public class FeedController : ControllerBase
{
private readonly FeedReadedDataProvider _feedReadedDataProvider;
@ -87,21 +86,27 @@ public class FeedController : ControllerBase
///<returns>List of filtered feeds</returns>
[HttpGet("filter")]
public object GetFeed(
string id,
string product,
ApiDateTime from,
ApiDateTime to,
Guid? author,
bool? onlyNew,
bool? withoutMe,
bool? withRelated,
ApiDateTime timeReaded)
{
var filter = new FeedApiFilter
{
Id = id,
Product = product,
Offset = Convert.ToInt32(_apiContext.StartIndex),
Max = Convert.ToInt32(_apiContext.Count) - 1,
Author = author ?? Guid.Empty,
SearchKeys = _apiContext.FilterValues,
OnlyNew = onlyNew.HasValue && onlyNew.Value
OnlyNew = onlyNew.HasValue && onlyNew.Value,
WithoutMe = withoutMe.HasValue && withoutMe.Value,
WithRelated = withRelated.HasValue && withRelated.Value,
};
if (from != null && to != null)