Files
2026-07-21 13:52:43 +07:00

73 lines
2.9 KiB
C#

using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Thirdparty.PatientCategory.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Thirdparty.PatientCategory;
public static class PatientCategoryEndpoint
{
public static void MapPatientCategoryEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/patient-category").WithTags("PatientCategories")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
{
var result = await mediator.Send(new GetPatientCategoryListQuery());
return result.ToApiResponse("Patient category list retrieved successfully");
})
.WithName("GetPatientCategoryList")
.WithTags("PatientCategories");
group.MapGet("/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new GetPatientCategoryByIdQuery(id));
return result.ToApiResponse(result is not null
? "Patient category detail retrieved successfully"
: $"Patient category with ID {id} not found");
})
.WithName("GetPatientCategoryById")
.WithTags("PatientCategories");
group.MapPost("/", async (CreatePatientCategoryRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new CreatePatientCategoryCommand(request));
return result.ToApiResponse("Patient category has been created successfully", StatusCodes.Status201Created);
})
.WithName("CreatePatientCategory")
.WithTags("PatientCategories");
group.MapPost("/update", async (UpdatePatientCategoryRequest request, IMediator mediator) =>
{
var result = await mediator.Send(new UpdatePatientCategoryCommand(request));
if (!result.Success)
{
return ((object?)null).ToApiResponse("Update failed. The patient category data could not be found.");
}
return result.ToApiResponse("Patient category has been updated successfully");
})
.WithName("UpdatePatientCategory")
.WithTags("PatientCategories");
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
{
var result = await mediator.Send(new DeletePatientCategoryByIdCommand(new DeletePatientCategoryByIdRequest(id)));
if (!result)
{
return ((object?)null).ToApiResponse("Delete failed. The patient category data could not be found.");
}
return true.ToApiResponse("Patient category has been deleted successfully");
})
.WithName("DeletePatientCategoryById")
.WithTags("PatientCategories");
}
}