using BookHive.DTO.Member;
using BookHive.Models;
using BookHive.Repositories;
using FastEndpoints;

namespace BookHive.Endpoints.Members;

public class CreateMemberEndpoint(MemberRepository memberRepository, AutoMapper.IMapper mapper) : Endpoint<CreateMemberDto>
{
    public override void Configure()
    {
        Post("/members/");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CreateMemberDto req, CancellationToken ct)
    {
        await memberRepository.AddAsync(mapper.Map<Member>(req), ct);
        await Send.NoContentAsync(ct);
    }
}