using FastEndpoints;
using Knots.DTO.Group;

namespace Knots.Endpoints.Group;

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