initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Medical.MedicalRecord.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Medical.MedicalRecord;
|
||||
|
||||
public static class MedicalRecordEndpoint
|
||||
{
|
||||
public static void MapMedicalRecordEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/medical-record").WithTags("MedicalRecords")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetMedicalRecordListQuery());
|
||||
return result.ToApiResponse("Medical record list retrieved successfully");
|
||||
})
|
||||
.WithName("GetMedicalRecordList")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetMedicalRecordByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Medical record detail retrieved successfully"
|
||||
: $"Medical record with ID {id} not found");
|
||||
})
|
||||
.WithName("GetMedicalRecordById")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new LookupMedicalRecordQuery());
|
||||
return result.ToApiResponse("Medical record lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetMedicalRecordLookup")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
group.MapPost("/", async (CreateMedicalRecordRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateMedicalRecordCommand(request));
|
||||
return result.ToApiResponse("Medical record has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateMedicalRecord")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
group.MapPost("/update", async (UpdateMedicalRecordRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateMedicalRecordCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The medical record data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Medical record has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateMedicalRecord")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteMedicalRecordByIdCommand(new DeleteMedicalRecordByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The medical record data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Medical record has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteMedicalRecordById")
|
||||
.WithTags("MedicalRecords");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user