50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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<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
|
|
.Where(x => x.Proof is not null)
|
|
.Select(x => new GetUserProofDto
|
|
{
|
|
Proof = x.Proof
|
|
})
|
|
);
|
|
|
|
if (user.UserGroups is not null)
|
|
proofs.AddRange(
|
|
user.UserGroups.Select(x => new GetUserProofDto
|
|
{
|
|
Proof = x.Proof
|
|
})
|
|
);
|
|
|
|
await Send.OkAsync(proofs, ct);
|
|
}
|
|
} |