refactor code of challenges and proofs in profil vue

This commit is contained in:
2026-05-14 11:38:41 +01:00
parent 01b7675703
commit f86fd80efc
3 changed files with 12 additions and 20 deletions
@@ -26,13 +26,10 @@ public class GetAllUserChallengesEndpoint(UsersRepository usersRepository, UserS
return; return;
} }
List<GetUserChallengeDto> challenges = []; List<GetUserChallengeDto> challenges = user.UserRandomChallenges?
if (user.UserRandomChallenges is not null) .Where(x => x.Proof is not null)
challenges.AddRange( .Select(x => mapper.Map<GetUserChallengeDto>(x.RandomChallenge))
user.UserRandomChallenges .ToList() ?? [];
.Where(x => x.Proof is not null)
.Select(x => mapper.Map<GetUserChallengeDto>(x.RandomChallenge))
);
await Send.OkAsync(challenges.OrderByDescending(x => x.ChallengeStartDate).ToList(), ct); await Send.OkAsync(challenges.OrderByDescending(x => x.ChallengeStartDate).ToList(), ct);
} }
@@ -25,17 +25,14 @@ public class GetAllUserProofsEndpoint(UsersRepository usersRepository, UserServi
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
List<GetUserProofDto> proofs = []; List<GetUserProofDto> proofs = user.UserRandomChallenges?
if (user.UserRandomChallenges is not null) .Where(x => x.Proof is not null)
proofs.AddRange( .Select(x => new GetUserProofDto
user.UserRandomChallenges {
.Where(x => x.Proof is not null) Proof = x.Proof
.Select(x => new GetUserProofDto })
{ .ToList() ?? [];
Proof = x.Proof
})
);
await Send.OkAsync(proofs, ct); await Send.OkAsync(proofs, ct);
} }
@@ -10,8 +10,6 @@ public class GetProofOrChallengeByUserIdSpec : SingleResultSpecification<User>
Query Query
.Include(x => x.UserRandomChallenges!) .Include(x => x.UserRandomChallenges!)
.ThenInclude(x => x.RandomChallenge) .ThenInclude(x => x.RandomChallenge)
.Include(x => x.UserGroups!)
.ThenInclude(x => x.Group)
.Where(x => x.Id == userId); .Where(x => x.Id == userId);
} }
} }