initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Organization.EmployeeCategory.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Organization.EmployeeCategory;
|
||||
|
||||
public static class EmployeeCategoryEndpoint
|
||||
{
|
||||
public static void MapEmployeeCategoryEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/employee-category").WithTags("EmployeeCategories")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetEmployeeCategoryListQuery());
|
||||
|
||||
return result.ToApiResponse("Employee category list retrieved successfully");
|
||||
})
|
||||
.WithName("GetEmployeeCategoryList")
|
||||
.WithTags("EmployeeCategories");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetEmployeeCategoryByIdQuery(id));
|
||||
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Employee category detail retrieved successfully"
|
||||
: $"Employee category with ID {id} not found");
|
||||
})
|
||||
.WithName("GetEmployeeCategoryById")
|
||||
.WithTags("EmployeeCategories");
|
||||
|
||||
group.MapPost("/", async (CreateEmployeeCategoryRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateEmployeeCategoryCommand(request));
|
||||
|
||||
return result.ToApiResponse("Employee category has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateEmployeeCategory")
|
||||
.WithTags("EmployeeCategories");
|
||||
|
||||
group.MapPost("/update", async (UpdateEmployeeCategoryRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateEmployeeCategoryCommand(request));
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The employee category data could not be found.");
|
||||
}
|
||||
|
||||
return result.ToApiResponse("Employee category has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateEmployeeCategory")
|
||||
.WithTags("EmployeeCategories");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteEmployeeCategoryByIdCommand(new DeleteEmployeeCategoryByIdRequest(id)));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The employee category data could not be found.");
|
||||
}
|
||||
|
||||
return true.ToApiResponse("Employee category has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteEmployeeCategoryById")
|
||||
.WithTags("EmployeeCategories");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user