mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-24 22:42:30 +01:00
Document & test multiple values for 2.2.0. Closes #46
This commit is contained in:
parent
2d5fc0d232
commit
c818267526
11
README.md
11
README.md
@ -90,7 +90,7 @@ And `SieveCustomFilterMethods`:
|
||||
```C#
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value) // The method is given the {Operator} & {Value}
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values) // The method is given the {Operator} & {Value}
|
||||
{
|
||||
var result = source.Where(p => p.LikeCount < 100 &&
|
||||
p.CommentCount < 5);
|
||||
@ -181,6 +181,15 @@ It is recommended that you write exception-handling middleware to globally handl
|
||||
### Example project
|
||||
You can find an example project incorporating most Sieve concepts in [SieveTests](https://github.com/Biarity/Sieve/tree/master/SieveTests).
|
||||
|
||||
|
||||
## Upgrading to v2.2.0
|
||||
|
||||
2.2.0 introduced OR logic for filter values. This means your custom filters will need to accept multiple values rather than just the one.
|
||||
|
||||
* In all your custom filter methods, change the last argument to be a `string[] values` instead of `string value`
|
||||
* The first value can then be found to be `values[0]` rather than `value`
|
||||
* Multiple values will be present if the client uses OR logic
|
||||
|
||||
## Upgrading from v1.* to v2.*
|
||||
|
||||
* Changes to the `SieveProcessor` API:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>2.1.5</Version>
|
||||
<Version>2.2</Version>
|
||||
<Description>Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries. Documentation available on GitHub: https://github.com/Biarity/Sieve/
|
||||
</Description>
|
||||
<Copyright>Copyright 2018</Copyright>
|
||||
@ -10,7 +10,7 @@
|
||||
<PackageProjectUrl>https://github.com/Biarity/Sieve</PackageProjectUrl>
|
||||
<PackageIconUrl>https://emojipedia-us.s3.amazonaws.com/thumbs/240/twitter/120/alembic_2697.png</PackageIconUrl>
|
||||
<RepositoryUrl></RepositoryUrl>
|
||||
<PackageReleaseNotes>Fix custom sort methods not working after 2.1</PackageReleaseNotes>
|
||||
<PackageReleaseNotes>Added OR logic for value fields, allowed escaping special characters</PackageReleaseNotes>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<Authors>Biarity</Authors>
|
||||
|
@ -6,7 +6,7 @@ namespace SieveTests.Services
|
||||
{
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values)
|
||||
=> source.Where(p => p.LikeCount < 100 && p.CommentCount < 5);
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +172,20 @@ namespace SieveUnitTests
|
||||
Assert.IsTrue(result.Count() == 3);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomFiltersWithOperatorsWork()
|
||||
{
|
||||
var model = new SieveModel()
|
||||
{
|
||||
Filters = "HasInTitle==A",
|
||||
};
|
||||
|
||||
var result = _processor.Apply(model, _posts);
|
||||
|
||||
Assert.IsTrue(result.Any(p => p.Id == 0));
|
||||
Assert.IsTrue(result.Count() == 1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomFiltersMixedWithUsualWork1()
|
||||
{
|
||||
|
@ -7,21 +7,28 @@ namespace SieveUnitTests.Services
|
||||
{
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values)
|
||||
{
|
||||
var result = source.Where(p => p.LikeCount < 100);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<Comment> IsNew(IQueryable<Comment> source, string op, string value)
|
||||
public IQueryable<Post> HasInTitle(IQueryable<Post> source, string op, string[] values)
|
||||
{
|
||||
var result = source.Where(p => p.Title.Contains(values[0]));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<Comment> IsNew(IQueryable<Comment> source, string op, string[] values)
|
||||
{
|
||||
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string value)
|
||||
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string[] values)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user