73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
namespace Indotalent.Features.Thirdparty.PatientGroup;
|
|
|
|
public static class PatientGroupEndpoint
|
|
{
|
|
public static void MapPatientGroupEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var group = app.MapGroup("/patient-group").WithTags("PatientGroups")
|
|
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
|
.RequireAuthenticatedUser());
|
|
|
|
group.MapGet("/", async (IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new GetPatientGroupListQuery());
|
|
|
|
return result.ToApiResponse("Patient group list retrieved successfully");
|
|
})
|
|
.WithName("GetPatientGroupList")
|
|
.WithTags("PatientGroups");
|
|
|
|
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new GetPatientGroupByIdQuery(id));
|
|
|
|
return result.ToApiResponse(result is not null
|
|
? "Patient group detail retrieved successfully"
|
|
: $"Patient group with ID {id} not found");
|
|
})
|
|
.WithName("GetPatientGroupById")
|
|
.WithTags("PatientGroups");
|
|
|
|
group.MapPost("/", async (CreatePatientGroupRequest request, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new CreatePatientGroupCommand(request));
|
|
|
|
return result.ToApiResponse("Patient group has been created successfully", StatusCodes.Status201Created);
|
|
})
|
|
.WithName("CreatePatientGroup")
|
|
.WithTags("PatientGroups");
|
|
|
|
group.MapPost("/update", async (UpdatePatientGroupRequest request, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new UpdatePatientGroupCommand(request));
|
|
|
|
if (!result.Success)
|
|
{
|
|
return ((object?)null).ToApiResponse("Update failed. The patient group data could not be found.");
|
|
}
|
|
|
|
return result.ToApiResponse("Patient group has been updated successfully");
|
|
})
|
|
.WithName("UpdatePatientGroup")
|
|
.WithTags("PatientGroups");
|
|
|
|
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new DeletePatientGroupByIdCommand(new DeletePatientGroupByIdRequest(id)));
|
|
|
|
if (!result)
|
|
{
|
|
return ((object?)null).ToApiResponse("Delete failed. The patient group data could not be found.");
|
|
}
|
|
|
|
return true.ToApiResponse("Patient group has been deleted successfully");
|
|
})
|
|
.WithName("DeletePatientGroupById")
|
|
.WithTags("PatientGroups");
|
|
}
|
|
} |