initial commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Thirdparty.PatientContact.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.PatientContact;
|
||||
|
||||
public static class PatientContactEndpoint
|
||||
{
|
||||
public static void MapPatientContactEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/patient-contact").WithTags("PatientContacts")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetPatientContactListQuery());
|
||||
|
||||
return result.ToApiResponse("Patient contact list retrieved successfully");
|
||||
})
|
||||
.WithName("GetPatientContactList")
|
||||
.WithTags("PatientContacts");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetPatientContactByIdQuery(id));
|
||||
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Patient contact detail retrieved successfully"
|
||||
: $"Patient contact with ID {id} not found");
|
||||
})
|
||||
.WithName("GetPatientContactById")
|
||||
.WithTags("PatientContacts");
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new LookupPatientContactQuery());
|
||||
|
||||
return result.ToApiResponse("Patient contact lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetPatientContactLookup")
|
||||
.WithTags("PatientContacts");
|
||||
|
||||
group.MapPost("/", async (CreatePatientContactRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreatePatientContactCommand(request));
|
||||
|
||||
return result.ToApiResponse("Patient contact has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreatePatientContact")
|
||||
.WithTags("PatientContacts");
|
||||
|
||||
group.MapPost("/update", async (UpdatePatientContactRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdatePatientContactCommand(request));
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The contact data could not be found.");
|
||||
}
|
||||
|
||||
return result.ToApiResponse("Patient contact has been updated successfully");
|
||||
})
|
||||
.WithName("UpdatePatientContact")
|
||||
.WithTags("PatientContacts");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeletePatientContactByIdCommand(new DeletePatientContactByIdRequest(id)));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The contact data could not be found.");
|
||||
}
|
||||
|
||||
return true.ToApiResponse("Patient contact has been deleted successfully");
|
||||
})
|
||||
.WithName("DeletePatientContactById")
|
||||
.WithTags("PatientContacts");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user