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 Send.NoContentAsync(ct);
    }
}