Пример #1
0
        public static IEndpointConventionBuilder Map(IEndpointRouteBuilder endpoints)
        {
            var builder =
                endpoints
                .MapMethods(
                    "/api/projects/{id:int}",
                    new [] { HttpMethod.Patch.Method },
                    async(int id, UpdateProjectRouteInput input, IMediator mediator) =>
            {
                var response = await mediator.Send(new PatchProjectRequest {
                    Id = input.Id, Name = input.Name, ProjectTypeId = input.TypeId
                });

                if (response.Context.Status != ProcessingStatus.Ok)
                {
                    return(HttpResponseHandler.HandleUnscusseful(response.Context));
                }

                return(Results.Ok(new UpdateProjectRouteOutput(response.Project.Id, response.Project.Name, response.Project.TypeId)));
            })
                .RequireAuthorization()
                .WithName("UpdateProject")
                .Produces(StatusCodes.Status200OK, typeof(UpdateProjectRouteOutput), "application/json")
                .ProducesValidationProblem()
                .ProducesProblem(StatusCodes.Status403Forbidden)
                .ProducesProblem(StatusCodes.Status404NotFound);

            return(builder);
        }
Пример #2
0
        public static IEndpointConventionBuilder Map(IEndpointRouteBuilder endpoints)
        {
            var builder =
                endpoints
                .MapPost(
                    "/api/projects",
                    async(CreateProjectRouteInput model, IMediator mediator, IUserProvider userProvider) =>
            {
                var userId = userProvider.GetUserId();

                if (string.IsNullOrWhiteSpace(userId))
                {
                    return(Results.Forbid());
                }

                var response = await mediator.Send(new CreateProjectRequest {
                    Name = model.Name, ProjectTypeId = model.TypeId, UserId = userId
                });

                if (response.Context.Status != ProcessingStatus.Ok)
                {
                    return(HttpResponseHandler.HandleUnscusseful(response.Context));
                }

                return(Results.CreatedAtRoute("CreateProject", null, new CreateProjectRouteOutput(response.Project.Id, response.Project.Name, response.Project.TypeId)));
            })
                .RequireAuthorization()
                .WithName("CreateProject")
                .Produces(StatusCodes.Status201Created, typeof(CreateProjectRouteOutput), "application/json")
                .Accepts <CreateProjectRouteInput>("application/json")
                .ProducesValidationProblem()
                .ProducesProblem(StatusCodes.Status403Forbidden);

            return(builder);
        }
Пример #3
0
        public static IEndpointConventionBuilder Map(IEndpointRouteBuilder endpoints)
        {
            var builder =
                endpoints
                .MapDelete(
                    "/api/projects/{id:int}",
                    async(int id, IMediator mediator) =>
            {
                var response = await mediator.Send(new DeleteProjectRequest {
                    Id = id
                });

                if (response.Context.Status != ProcessingStatus.Ok)
                {
                    return(HttpResponseHandler.HandleUnscusseful(response.Context));
                }

                return(Results.NoContent());
            })
                .RequireAuthorization()
                .WithName("DeleteProject")
                .Produces(StatusCodes.Status204NoContent)
                .ProducesValidationProblem()
                .ProducesProblem(StatusCodes.Status403Forbidden)
                .ProducesProblem(StatusCodes.Status404NotFound);

            return(builder);
        }
Пример #4
0
        public static IEndpointConventionBuilder Map(IEndpointRouteBuilder endpoints)
        {
            var builder =
                endpoints
                .MapGet(
                    "/api/projects",
                    async(IMediator mediator, IUserProvider userProvider) =>
            {
                var userId = userProvider.GetUserId();

                if (string.IsNullOrWhiteSpace(userId))
                {
                    return(Results.Forbid());
                }

                var response = await mediator.Send(new GetProjectsForUserRequest {
                    UserId = userId
                });

                if (response.Context.Status != ProcessingStatus.Ok)
                {
                    return(HttpResponseHandler.HandleUnscusseful(response.Context));
                }

                var projectStats = response.UserProjectStats.ProjectStats.Select(x => new ProjectStats(x.Id, x.Name, x.TotalConfigurationCount, x.TotalEntryCount));

                return(Results.Ok(new GetProjectForUserRouteOutput(response.UserProjectStats.UserId, projectStats)));
            })
                .RequireAuthorization()
                .WithName("GetProjectsForUser")
                .ProducesValidationProblem()
                .Produces(StatusCodes.Status200OK, typeof(GetProjectForUserRouteOutput), "application/json")
                .ProducesProblem(StatusCodes.Status403Forbidden);

            return(builder);
        }