Exemple #1
0
        public async Task <IActionResult> GetBirdsAsync(int pageIndex, int pageSize, BirderStatus speciesFilter)
        {
            try
            {
                var birds = await _birdRepository.GetBirdsAsync(pageIndex, pageSize, speciesFilter);

                if (birds is null)
                {
                    _logger.LogWarning(LoggingEvents.GetListNotFound, "Birds list is null");
                    return(StatusCode(500, $"bird repository returned null"));
                }

                var viewModel = _mapper.Map <QueryResult <Bird>, BirdsListDto>(birds);

                return(Ok(viewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError(LoggingEvents.GetListNotFound, ex, "An error occurred getting the birds list");
                return(StatusCode(500, "an unexpected error occurred"));
            }
        }