Exemple #1
0
        public async Task <IActionResult> GetObservationAsync(int id)
        {
            try
            {
                var observation = await _observationRepository.GetObservationAsync(id, true);

                if (observation is null)
                {
                    string message = $"Observation with id '{id}' was not found.";
                    _logger.LogWarning(LoggingEvents.GetItemNotFound, message);
                    return(StatusCode(500, message));
                }

                return(Ok(_mapper.Map <Observation, ObservationDto>(observation)));
            }
            catch (Exception ex)
            {
                string message = $"An error occurred getting observation with id '{id}'.";
                _logger.LogError(LoggingEvents.GetItemNotFound, ex, message);
                return(StatusCode(500, "an unexpected error occurred"));
            }
        }