initial commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Payroll.Grade.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Payroll.Grade;
|
||||
|
||||
public static class GradeEndpoint
|
||||
{
|
||||
public static void MapGradeEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/grade").WithTags("Grades")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetGradeListQuery());
|
||||
return result.ToApiResponse("Salary grades retrieved successfully");
|
||||
})
|
||||
.WithName("GetGradeList")
|
||||
.WithTags("Grades");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetGradeByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Salary grade detail retrieved successfully"
|
||||
: $"Salary grade with ID {id} not found");
|
||||
})
|
||||
.WithName("GetGradeById")
|
||||
.WithTags("Grades");
|
||||
|
||||
group.MapPost("/", async (CreateGradeRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateGradeCommand(request));
|
||||
return result.ToApiResponse("Salary grade has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateGrade")
|
||||
.WithTags("Grades");
|
||||
|
||||
group.MapPost("/update", async (UpdateGradeRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateGradeCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The grade data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Salary grade has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateGrade")
|
||||
.WithTags("Grades");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteGradeByIdCommand(new DeleteGradeByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The grade data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Salary grade has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteGradeById")
|
||||
.WithTags("Grades");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user