mirror of
https://github.com/Biarity/Sieve.git
synced 2024-12-04 19:16:24 +01:00
* Throw exceptions by default (#133)
* Doc strings for SieveOptions.cs * Simplify MaxPageSize calculation Co-authored-by: ITDancer139 <kevinitdancersommer@gmail.com>
This commit is contained in:
parent
8bd9ce85d9
commit
2c9d907764
@ -2,12 +2,26 @@
|
|||||||
{
|
{
|
||||||
public class SieveOptions
|
public class SieveOptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If flag is set, property names have to match including case sensitivity.
|
||||||
|
/// </summary>
|
||||||
public bool CaseSensitive { get; set; } = false;
|
public bool CaseSensitive { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fallback value of no page size is specified in the request.
|
||||||
|
/// </summary>
|
||||||
public int DefaultPageSize { get; set; } = 0;
|
public int DefaultPageSize { get; set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies the upper limit of a page size to be requested.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Values less or equal to 0 are ignored.</remarks>
|
||||||
public int MaxPageSize { get; set; } = 0;
|
public int MaxPageSize { get; set; } = 0;
|
||||||
|
|
||||||
public bool ThrowExceptions { get; set; } = false;
|
/// <summary>
|
||||||
|
/// If flag is set, Sieve throws exception otherwise exceptions are caught and the already processed
|
||||||
|
/// result is returned.
|
||||||
|
/// </summary>
|
||||||
|
public bool ThrowExceptions { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,11 @@ namespace Sieve.Services
|
|||||||
{
|
{
|
||||||
var page = model?.Page ?? 1;
|
var page = model?.Page ?? 1;
|
||||||
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
|
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
|
||||||
var maxPageSize = _options.Value.MaxPageSize > 0 ? _options.Value.MaxPageSize : pageSize;
|
|
||||||
|
if (_options.Value.MaxPageSize > 0)
|
||||||
|
{
|
||||||
|
pageSize = Math.Min(pageSize, _options.Value.MaxPageSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (pageSize <= 0)
|
if (pageSize <= 0)
|
||||||
{
|
{
|
||||||
@ -385,7 +389,7 @@ namespace Sieve.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = result.Skip((page - 1) * pageSize);
|
result = result.Skip((page - 1) * pageSize);
|
||||||
result = result.Take(Math.Min(pageSize, maxPageSize));
|
result = result.Take(page);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user