Exemplo n.º 1
0
        public async Task <IActionResult> GetPointByIdAsync(Guid pointId, CancellationToken ct)
        {
            if (pointId == Guid.Empty)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.IdFieldRequired)));
            }

            var point = await _pointsService.GetPointByIdAsync(pointId, ct);

            if (point == null)
            {
                return(NotFound());
            }

            return(Ok(point));
        }
        public async Task <IActionResult> SearchPathRouteAsync(Guid originPointId, Guid destinationPointId,
                                                               SearchAlgorithmParameters searchParameters, CancellationToken ct)
        {
            if (originPointId == Guid.Empty)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.InvalidOriginPointId)));
            }
            if (destinationPointId == Guid.Empty)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.InvalidDestinationPointId)));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiError(ModelState)));
            }

            var originPoint = await _pointsService.GetPointByIdAsync(originPointId, ct);

            if (originPoint == null)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.InvalidOriginPointId)));
            }

            var destinationPoint = await _pointsService.GetPointByIdAsync(destinationPointId, ct);

            if (destinationPoint == null)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.InvalidDestinationPointId)));
            }

            var points = await _routesService.SearchRoutePointsAsync(originPointId, destinationPointId, searchParameters, ct);

            if (points?.Items == null || !points.Items.Any())
            {
                return(NotFound());
            }

            var collection = Collection <Point> .Create <PointsResponse>(Link.ToCollection(nameof(PointsController.GetPointsAsync)),
                                                                         points.Items.ToArray(), points.TotalSize);

            return(Ok(collection));
        }