22 lines
569 B
C#
22 lines
569 B
C#
using FastEndpoints;
|
|
using Knots.DTO.Role;
|
|
using Knots.DTO.User;
|
|
|
|
namespace Knots.Endpoints.Role;
|
|
|
|
public class CreateRoleEndpoint(KnotsDbContext db, AutoMapper.IMapper mapper) : Endpoint<CreateRoleDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/roles");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateRoleDto req, CancellationToken ct)
|
|
{
|
|
Models.Role? role = mapper.Map<Models.Role>(req);
|
|
db.Roles.Add(role);
|
|
await db.SaveChangesAsync(ct);
|
|
await SendNoContentAsync(ct);
|
|
}
|
|
} |