Files
blazor-hrm/Features/Organization/Department/DepartmentEndpoint.cs
T
2026-07-21 14:08:10 +07:00

30 lines
1.5 KiB
C#

using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Organization.Department.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Indotalent.Features.Organization.Department;
public static class DepartmentEndpoint
{
public static void MapDepartmentEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/department").WithTags("Departments")
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser());
group.MapGet("/", async (IMediator mediator) =>
(await mediator.Send(new GetDepartmentListQuery())).ToApiResponse("Data retrieved"));
group.MapGet("/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new GetDepartmentByIdQuery(id))).ToApiResponse("Detail retrieved"));
group.MapPost("/", async (CreateDepartmentRequest request, IMediator mediator) =>
(await mediator.Send(new CreateDepartmentCommand(request))).ToApiResponse("Created", StatusCodes.Status201Created));
group.MapPost("/update", async (UpdateDepartmentRequest request, IMediator mediator) =>
(await mediator.Send(new UpdateDepartmentCommand(request))).ToApiResponse("Updated"));
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
(await mediator.Send(new DeleteDepartmentByIdCommand(new DeleteDepartmentByIdRequest(id)))).ToApiResponse("Deleted"));
}
}