using PostFundManagement.Application.Extensions; using PostFundManagement.Application.Projects; using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Api; using PostFundManagement.Domain.Extensions; namespace PostFundManagement.Api.Endpoints.Projects; [ApiVersionTarget(1)] public class CreateProjectEndpoint : IEndpoint { public void Map(IEndpointRouteBuilder builder) { builder.MapPost("api/projects", async (CreateProjectRequest request, HttpContext context, ProjectService service, CancellationToken cancellationToken = default) => { var result = await service.CreateProjectAsync(request, context.GetUserId(), cancellationToken); return result.IsSuccess ? Results.Ok() : Results.BadRequest(result.Errors.ToProblems()); }) .WithDescription("Create a new project (M04)") .WithName(typeof(CreateProjectEndpoint).ToEndpointName()) .MapToApiVersion(new ApiVersion(1)) .Produces(StatusCodes.Status200OK) .Produces(StatusCodes.Status400BadRequest) .Produces(StatusCodes.Status401Unauthorized) .WithTags(EndpointTags.Projects); } }