CSR-Pattern-Example/API/Controllers/WeatherForecastController.cs
/// <summary>
/// Gets weather forecasts for dates between a start date and an end date.
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
Gets weather forecasts for dates between a start date and an end date.
Gets weather forecasts for dates between a start date and an end date .
[HttpGet]
        [Route("forecasts")]
        [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<WeatherForecastApiResponse>))]
        [ProducesResponseType(StatusCodes.Status400BadRequest)]
        public IActionResult GetForecasts([FromQuery] GetForecastsApiRequest request)
        {
            _logger.LogInformation($"weather/forecasts API method called at {DateTime.UtcNow} (UTC).");
            try
            {
                var forecasts = _weatherService.GetForecasts(request.StartDate, request.EndDate);
                return Ok(forecasts.ToApiModels());
            }
            catch(ArgumentException)
            {
                return BadRequest("Start date should not be after the end date.");
            }
        }
[ HttpGet ] [ Route ( " " ) ] [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( IEnumerable < WeatherForecastApiResponse > ) ) ] [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ] public IActionResult GetForecasts ( [ FromQuery ] GetForecastsApiRequest request ) { _logger . LogInformation ( $" weather/forecasts API method called at  { DateTime . UtcNow }  (UTC). " ) ; try { var forecasts = _weatherService . GetForecasts ( request . StartDate , request . EndDate ) ; return Ok ( forecasts . ToApiModels ( ) ) ; } catch ( ArgumentException ) { return BadRequest ( " " ) ; } }
Gets weather forecasts for dates between a start date and an end date.
Gets weather forecasts for dates between a start date and an end date .
// Ideally should use custom validation attributes, but using try-catch here for simplicity
None
GetForecastsApiRequest
[FromQuery]
request
None