зеркало из https://github.com/Azure/Sia-Root.git
Started integrating filters into linksheader
This commit is contained in:
Родитель
2d04611e9a
Коммит
c7fe26ddcd
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -24,5 +26,12 @@ namespace Sia.Shared.Data
|
|||
}
|
||||
return working;
|
||||
}
|
||||
public abstract StringValues NonDataFilterValues();
|
||||
public override StringValues FilterValues() => StringValues.Concat(NonDataFilterValues(), _dataFilterValues());
|
||||
private StringValues _dataFilterValues() => JsonConvert.SerializeObject(new
|
||||
{
|
||||
DataKey = DataKey,
|
||||
DataValue = DataValue
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Sia.Shared.Data;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Sia.Shared.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -9,6 +10,7 @@ namespace Sia.Shared.Data
|
|||
public abstract class Filters<T>
|
||||
{
|
||||
public abstract IQueryable<T> Filter(IQueryable<T> source);
|
||||
public abstract StringValues FilterValues();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Sia.Shared.Data;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Sia.Shared.Protocol
|
||||
{
|
||||
public class FilteredLinksHeader<T> : LinksHeader
|
||||
{
|
||||
public FilteredLinksHeader(Filters<T> filterMetadata, PaginationMetadata metadata, IUrlHelper urlHelper, string routeName)
|
||||
: base(metadata, urlHelper, routeName)
|
||||
{
|
||||
_filterMetadata = filterMetadata;
|
||||
}
|
||||
|
||||
private Filters<T> _filterMetadata;
|
||||
|
||||
public override StringValues HeaderValues
|
||||
=> StringValues.Concat(base.HeaderValues, _filterMetadata.FilterValues());
|
||||
}
|
||||
}
|
|
@ -18,7 +18,10 @@ namespace Sia.Shared.Protocol
|
|||
}
|
||||
|
||||
public const string HeaderName = "links";
|
||||
public StringValues HeaderValues => JsonConvert.SerializeObject(new
|
||||
public virtual StringValues HeaderValues =>
|
||||
_baseHeaderValues;
|
||||
|
||||
private StringValues _baseHeaderValues => JsonConvert.SerializeObject(new
|
||||
{
|
||||
PageNumber = _metadata.PageNumber,
|
||||
PageSize = _metadata.PageSize,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using Sia.Shared.Protocol;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Newtonsoft.Json;
|
||||
using Sia.Shared.Protocol;
|
||||
|
||||
namespace Sia.Shared.Protocol
|
||||
{
|
||||
|
@ -8,17 +10,17 @@ namespace Sia.Shared.Protocol
|
|||
public int PageSize { get; set; } = 50;
|
||||
public long TotalRecords { get; set; }
|
||||
public long TotalPages => (TotalRecords / PageSize) + (TotalRecords % PageSize > 0 ? 1 : 0);
|
||||
public object PreviousPageLinkInfo => PreviousPageExists ? new
|
||||
public StringValues PreviousPageLinkInfo => PreviousPageExists ? JsonConvert.SerializeObject(new
|
||||
{
|
||||
PageNumber = PageNumber - 1,
|
||||
PageSize = PageSize
|
||||
} : null;
|
||||
}) : null;
|
||||
|
||||
public object NextPageLinkInfo => NextPageExists ? new
|
||||
public StringValues NextPageLinkInfo => NextPageExists ? JsonConvert.SerializeObject(new
|
||||
{
|
||||
PageNumber = PageNumber + 1,
|
||||
PageSize = PageSize
|
||||
} : null;
|
||||
}) : null;
|
||||
|
||||
public bool PreviousPageExists => PageNumber > 1;
|
||||
public bool NextPageExists => PageNumber < TotalPages;
|
||||
|
|
Загрузка…
Ссылка в новой задаче