namespace DocuMed.Api.Controllers; public class HospitalController : ICarterModule { public void AddRoutes(IEndpointRouteBuilder app) { var group = app.NewVersionedApi("Hospital") .MapGroup("api/hospital") .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()); group.MapGet("{id}/section", GetSectionsAsync) .WithDisplayName("Get All Sections") .HasApiVersion(1.0); group.MapGet("", GetAllAsync) .WithDisplayName("GetAll") .HasApiVersion(1.0); group.MapGet("{id}", GetAsync) .WithDisplayName("GetOne") .HasApiVersion(1.0); group.MapPost("", Post) .HasApiVersion(1.0); group.MapPut("", Put) .HasApiVersion(1.0); group.MapDelete("", Delete) .HasApiVersion(1.0); } // GET:Get All Sections public virtual async Task GetSectionsAsync(Guid id, IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService, CancellationToken cancellationToken) { return TypedResults.Ok(await repositoryWrapper.SetRepository
().TableNoTracking .Where(s => s.HospitalId == id) .Select(SectionMapper.ProjectToSDto).ToListAsync(cancellationToken)); } // GET:Get All Entity private async Task GetAllAsync([FromQuery] int page, IMediator mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(new GetHospitalsQuery(page), cancellationToken)); // GET:Get An Entity By Id private async Task GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(new GetHospitalQuery(id), cancellationToken)); // POST:Add New Entity private async Task Post([FromBody] CreateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken) => TypedResults.Ok(await service.Send(dto, cancellationToken)); // PUT:Update Entity private async Task Put([FromBody] UpdateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken) => TypedResults.Ok(await service.Send(dto, cancellationToken)); // DELETE:Delete Entity private async Task Delete(Guid id, IMediator mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(new DeleteHospitalCommand(id), cancellationToken)); }