namespace Brizco.Api.Controllers; public class TaskController : ICarterModule { public virtual void AddRoutes(IEndpointRouteBuilder app) { var group = app.NewVersionedApi("Task") .MapGroup($"api/task") .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()); group.MapGet("", GetAllAsync) .WithDisplayName("Get Tasks") .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageTasks, ApplicationPermission.ViewTasks)) .HasApiVersion(1.0); group.MapGet("{id}", GetAsync) .WithDisplayName("Get Task") .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageTasks, ApplicationPermission.ViewTasks)) .HasApiVersion(1.0); group.MapPost("", Post) .WithDisplayName("Create Task") .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageTasks)) .HasApiVersion(1.0); group.MapPut("", Put) .WithDisplayName("Update Task") .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageTasks)) .HasApiVersion(1.0); group.MapDelete("{id}", Delete) .WithDisplayName("Delete Task") .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageTasks)) .HasApiVersion(1.0); } // GET:Get All Entity public async Task GetAllAsync([FromQuery] int page, [FromQuery] int? count, [FromQuery] Guid? shiftId, ISender sender, CancellationToken cancellationToken) => TypedResults.Ok(await sender.Send(new GetTasksQuery(page, ShiftId: shiftId, Count: count), cancellationToken)); // GET:Get An Entity By Id public async Task GetAsync(Guid id, ISender sender, CancellationToken cancellationToken) => TypedResults.Ok(await sender.Send(new GetTaskQuery(id), cancellationToken)); // POST:Create Entity public async Task Post([FromBody] CreateTaskCommand ent, ISender mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(ent, cancellationToken)); // PUT:Update Entity public async Task Put([FromBody] UpdateTaskCommand ent, ISender mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(ent, cancellationToken)); // DELETE:Delete Entity public async Task Delete(Guid id, ISender mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(new DeleteTaskCommand(id), cancellationToken)); }