39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using BeReadyBackend.DTO.Groups;
|
|
using BeReadyBackend.Repositories;
|
|
using BeReadyBackend.Specifications.Groups;
|
|
using FastEndpoints;
|
|
using Group = BeReadyBackend.Models.Group;
|
|
|
|
namespace BeReadyBackend.Endpoints.Groups;
|
|
|
|
public class GroupProofRequest
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
public class GetAllProofsEndpoint(UserGroupsRepository userGroupsRepository, GroupsRepository groupsRepository) : Endpoint<GroupProofRequest, List<GetProofDto>>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/Groups/{@Id}/Proofs/", x => new { x.Id });
|
|
}
|
|
|
|
public override async Task HandleAsync(GroupProofRequest req, CancellationToken ct)
|
|
{
|
|
Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.Id), ct);
|
|
if (group is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
if (group.StartedVote != null && group.StartedVote.Value.AddHours(group.VoteDuration) < DateTime.Now)
|
|
{
|
|
await Send.StringAsync("Les votes ne sont pas fini", 400, cancellation: ct);
|
|
return;
|
|
}
|
|
|
|
List<GetProofDto> usersGroup = await userGroupsRepository.ProjectToListAsync<GetProofDto>(new GetUserGroupDetailsByIdSpec(req.Id), ct);
|
|
await Send.OkAsync(usersGroup, ct);
|
|
}
|
|
} |