using Knots.DTO.Group;
using FastEndpoints;

namespace Knots.Endpoints.Group;

public class CreateGroupEndpoint(KnotsDbContext db, AutoMapper.IMapper mapper) : Endpoint<CreateGroupDto>
{
    public override void Configure()
    {
        Post("/groups");
        AllowAnonymous();
    }
    
    public override async Task HandleAsync(CreateGroupDto req, CancellationToken ct)
    {
        Models.Group? group = mapper.Map<Models.Group>(req);
        db.Groups.Add(group);
        await db.SaveChangesAsync(ct);
        await Send.NoContentAsync(ct);
    }
}