Created endpoints to see all challenges and proofs of the user in her personnal page

This commit is contained in:
2026-02-21 21:58:43 +01:00
parent 115f4de993
commit a701909d9d
8 changed files with 170 additions and 4 deletions
@@ -0,0 +1,37 @@
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, AutoMapper.IMapper mapper) : EndpointWithoutRequest<List<GetUserProofDto>>
{
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<GetUserProofDto> proofs = [];
if (user.UserRandomChallenges is not null)
proofs.AddRange(user.UserRandomChallenges.Select(x => mapper.Map<GetUserProofDto>(x.RandomChallenge)));
if (user.UserGroups is not null)
proofs.AddRange(user.UserGroups.Select(x => mapper.Map<GetUserProofDto>(x.Group)));
await Send.OkAsync(proofs, ct);
}
}