public async Task <ActionResult> Index([FromQuery(Name = "limit")] int limit, [FromQuery(Name = "offset")] int offset) { _logger.LogInformation("GET /api/launchpads"); try { var result = await _launchpadService.Get(limit : limit, offset : offset); return(new JsonResult(result)); } catch (Exception ex) { _logger.LogError(ex, "Error GET /api/launchpads"); return(BadRequest()); } }
public async Task <IActionResult> Get([FromQuery] LaunchpadFilterModel filterRequest) { try { var launchpads = await _launchPadService.Get(filterRequest.Status, filterRequest.NameContains); var launchpadModels = launchpads.Select(x => new LaunchpadModel(x.Id, x.Name, x.Status)).ToList(); return(Ok(launchpadModels)); } //These 500 catches are redundant, but just an example exception handling, logging, and hopefully enhance readability //There are two logs created: one catchs all app info connected to Core's ILogger, and one captures only Api and explicit message concerns catch (Exception ex) { _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <IEnumerable <Launchpad> > > Get() { string query_limit = HttpContext.Request.Query["limit"].ToString(); string query_offset = HttpContext.Request.Query["offset"].ToString(); int?limit = null; int?offset = null; if (!string.IsNullOrWhiteSpace(query_limit)) { limit = int.Parse(query_limit); } if (!string.IsNullOrWhiteSpace(query_offset)) { offset = int.Parse(query_offset); } _logger.Log(LogLevel.Information, "get called with query values: limit::{@Limit} offset::{@Offset}", limit, offset); var launchpads = await _launchpadService.Get(limit, offset); return(Ok(launchpads)); }