This commit is contained in:
2020-02-13 16:13:56 +00:00
parent 2d56814455
commit 8d2c57e702
3 changed files with 22 additions and 7 deletions

View File

@@ -10,12 +10,10 @@ namespace AyaNova.Api.ControllerHelpers
public const int DefaultOffset = 0;
public const int DefaultLimit = 25;
[FromBody]
[Range(0, int.MaxValue)]
[FromBody]
public int? Offset { get; set; }
[FromBody]
[Range(1, MaxPageSize, ErrorMessage = "Limit must be greater than 0 and less than 1000.")]
[FromBody]
public int? Limit { get; set; }
// //Data filter id to use with this list query

View File

@@ -48,13 +48,30 @@ namespace AyaNova.Api.Controllers
/// </summary>
/// <param name="listOptions">List key, Paging, filtering and sorting options</param>
/// <returns>Collection with paging data</returns>
// [HttpPost("List", Name = nameof(List))]
[HttpPost]
// [HttpPost("List", Name = nameof(List))]
[HttpPost]
public async Task<IActionResult> List([FromBody] ListOptions listOptions)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
if (listOptions.Limit == null || listOptions.Limit < 1)
{
listOptions.Limit = ListOptions.DefaultLimit;
}
if (listOptions.Offset == null)
{
listOptions.Offset = 0;
}
//this is to workaround a quirk in the api explorer with default values
if(listOptions.SortJson=="string"){
listOptions.SortJson=string.Empty;
}
if(listOptions.FilterJson=="string"){
listOptions.FilterJson=string.Empty;
}
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));