Ejemplo n.º 1
0
        public async Task <IActionResult> GetEstablishmentsInRadiusAsync(
            [FromBody] NearbyRequest nearbyRequest,
            CancellationToken cancellationToken = default)
        {
            if (nearbyRequest == null)
            {
                throw new ArgumentNullException(nameof(nearbyRequest));
            }

            if (nearbyRequest.Radius <= 0)
            {
                return(BadRequest("Radius must be greater than 0"));
            }

            var center = new Point(nearbyRequest.Longitude, nearbyRequest.Latitude);
            var radius = nearbyRequest.Radius;

            _logger.LogInformation($"Searching Establishments in a radius of {radius} FROM {center}");

            var establishments = await _establishmentRepository.GetAllWithinRadiusAsync(radius, center, cancellationToken);

            var mappedEstablishments = _domainMapper.MapEstablishmentResponses(establishments);

            return(Ok(mappedEstablishments.Any() ? mappedEstablishments : Enumerable.Empty <EstablishmentResponse>()));
        }