initial commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Leave.LeaveBalance.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Leave.LeaveBalance;
|
||||
|
||||
public static class LeaveBalanceEndpoint
|
||||
{
|
||||
public static void MapLeaveBalanceEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/leave-balance").WithTags("Leave Balances")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeaveBalanceListQuery());
|
||||
return result.ToApiResponse("Data leave balance retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeaveBalanceList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeaveBalanceByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Leave balance detail retrieved successfully"
|
||||
: $"Leave balance with ID {id} not found");
|
||||
})
|
||||
.WithName("GetLeaveBalanceById");
|
||||
|
||||
group.MapPost("/", async (CreateLeaveBalanceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateLeaveBalanceCommand(request));
|
||||
return result.ToApiResponse("Leave balance has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateLeaveBalance");
|
||||
|
||||
group.MapPost("/update", async (UpdateLeaveBalanceRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateLeaveBalanceCommand(request));
|
||||
if (!result.Success) return ((object?)null).ToApiResponse("Update failed.");
|
||||
return result.ToApiResponse("Leave balance has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateLeaveBalance");
|
||||
|
||||
group.MapPost("/sync", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new SyncLeaveBalanceCommand());
|
||||
return result.ToApiResponse("All leave balances recalculated successfully");
|
||||
})
|
||||
.WithName("SyncLeaveBalance");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteLeaveBalanceByIdCommand(new DeleteLeaveBalanceByIdRequest(id)));
|
||||
if (!result) return ((object?)null).ToApiResponse("Delete failed.");
|
||||
return true.ToApiResponse("Leave balance has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteLeaveBalanceById");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user