74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Features.Medical.MedicalRecordGroup.Cqrs;
|
|
using Indotalent.Features.Organization.EmployeeGroup.Cqrs;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
namespace Indotalent.Features.Organization.EmployeeGroup;
|
|
|
|
public static class EmployeeGroupEndpoint
|
|
{
|
|
public static void MapEmployeeGroupEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var group = app.MapGroup("/employee-group").WithTags("EmployeeGroups")
|
|
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
|
.RequireAuthenticatedUser());
|
|
|
|
group.MapGet("/", async (IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new GetEmployeeGroupListQuery());
|
|
|
|
return result.ToApiResponse("Employee group list retrieved successfully");
|
|
})
|
|
.WithName("GetEmployeeGroupList")
|
|
.WithTags("EmployeeGroups");
|
|
|
|
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new GetEmployeeGroupByIdQuery(id));
|
|
|
|
return result.ToApiResponse(result is not null
|
|
? "Employee group detail retrieved successfully"
|
|
: $"Employee group with ID {id} not found");
|
|
})
|
|
.WithName("GetEmployeeGroupById")
|
|
.WithTags("EmployeeGroups");
|
|
|
|
group.MapPost("/", async (CreateEmployeeGroupRequest request, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new CreateEmployeeGroupCommand(request));
|
|
|
|
return result.ToApiResponse("Employee group has been created successfully", StatusCodes.Status201Created);
|
|
})
|
|
.WithName("CreateEmployeeGroup")
|
|
.WithTags("EmployeeGroups");
|
|
|
|
group.MapPost("/update", async (UpdateEmployeeGroupRequest request, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new UpdateEmployeeGroupCommand(request));
|
|
|
|
if (!result.Success)
|
|
{
|
|
return ((object?)null).ToApiResponse("Update failed. The employee group data could not be found.");
|
|
}
|
|
|
|
return result.ToApiResponse("Employee group has been updated successfully");
|
|
})
|
|
.WithName("UpdateEmployeeGroup")
|
|
.WithTags("EmployeeGroups");
|
|
|
|
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
|
{
|
|
var result = await mediator.Send(new DeleteEmployeeGroupByIdCommand(new DeleteEmployeeGroupByIdRequest(id)));
|
|
|
|
if (!result)
|
|
{
|
|
return ((object?)null).ToApiResponse("Delete failed. The employee group data could not be found.");
|
|
}
|
|
|
|
return true.ToApiResponse("Employee group has been deleted successfully");
|
|
})
|
|
.WithName("DeleteEmployeeGroupById")
|
|
.WithTags("EmployeeGroups");
|
|
}
|
|
} |