using BeReadyBackend.DTO.Users; using BeReadyBackend.Models; using BeReadyBackend.Repositories; using BeReadyBackend.Services; using BeReadyBackend.Specifications.Users; using FastEndpoints; namespace BeReadyBackend.Endpoints.Users; public class GetAllUserProofsEndpoint(UsersRepository usersRepository, UserService userService) : EndpointWithoutRequest> { public override void Configure() { Get("/Users/Proofs/"); } public override async Task HandleAsync(CancellationToken ct) { int userId = userService.GetUserIdFromToken(); User? user = await usersRepository.SingleOrDefaultAsync(new GetProofOrChallengeByUserIdSpec(userId), ct); if (user is null) { await Send.NotFoundAsync(ct); return; } List proofs = user.UserRandomChallenges? .Where(x => x.Proof is not null) .Select(x => new GetUserProofDto { Proof = x.Proof }) .ToList() ?? []; await Send.OkAsync(proofs, ct); } }