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

@@ -245,7 +245,7 @@ MISC FUTURE ITEMS NOT SURE ABOUT THAT CAME UP DURING CODING / TESTING
- Should server show uptime somewhere? - Should server show uptime somewhere?
- Log route: Add a route to download *all* log files as a single zip archive which will make life much easier for analysis - Log route: Add a route to download *all* log files as a single zip archive which will make life much easier for analysis
- how to set default values in api explorer example json for post routes (e.g. dataList defaults wouldn't work unless changed, auth wb nice if set to default manager account)

View File

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

View File

@@ -48,13 +48,30 @@ namespace AyaNova.Api.Controllers
/// </summary> /// </summary>
/// <param name="listOptions">List key, Paging, filtering and sorting options</param> /// <param name="listOptions">List key, Paging, filtering and sorting options</param>
/// <returns>Collection with paging data</returns> /// <returns>Collection with paging data</returns>
// [HttpPost("List", Name = nameof(List))] // [HttpPost("List", Name = nameof(List))]
[HttpPost] [HttpPost]
public async Task<IActionResult> List([FromBody] ListOptions listOptions) public async Task<IActionResult> List([FromBody] ListOptions listOptions)
{ {
if (serverState.IsClosed) if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); 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) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));