60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
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<IResult> GetSectionsAsync(Guid id, IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService, CancellationToken cancellationToken)
|
|
{
|
|
return TypedResults.Ok(await repositoryWrapper.SetRepository<Section>().TableNoTracking
|
|
.Where(s => s.HospitalId == id)
|
|
.Select(SectionMapper.ProjectToSDto).ToListAsync(cancellationToken));
|
|
}
|
|
|
|
// GET:Get All Entity
|
|
private async Task<IResult> 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<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
|
=> TypedResults.Ok(await mediator.Send(new GetHospitalQuery(id), cancellationToken));
|
|
|
|
// POST:Add New Entity
|
|
private async Task<IResult> Post([FromBody] CreateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
|
|
=> TypedResults.Ok(await service.Send(dto, cancellationToken));
|
|
|
|
// PUT:Update Entity
|
|
private async Task<IResult> Put([FromBody] UpdateHospitalCommand dto, IMediator service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
|
|
=> TypedResults.Ok(await service.Send(dto, cancellationToken));
|
|
|
|
// DELETE:Delete Entity
|
|
private async Task<IResult> Delete(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
|
=> TypedResults.Ok(await mediator.Send(new DeleteHospitalCommand(id), cancellationToken));
|
|
} |