From f86fd80efc810ca49805c8eb496100814bd0f883 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 14 May 2026 11:38:41 +0100 Subject: [PATCH] refactor code of challenges and proofs in profil vue --- .../Users/GetAllUserChallengesEndpoint.cs | 11 ++++------- .../Users/GetAllUserProofsEndpoint.cs | 19 ++++++++----------- .../Users/GetProofOrChallengeByUserIdSpec.cs | 2 -- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/BeReadyBackend/Endpoints/Users/GetAllUserChallengesEndpoint.cs b/BeReadyBackend/Endpoints/Users/GetAllUserChallengesEndpoint.cs index fc39515..dd82479 100644 --- a/BeReadyBackend/Endpoints/Users/GetAllUserChallengesEndpoint.cs +++ b/BeReadyBackend/Endpoints/Users/GetAllUserChallengesEndpoint.cs @@ -26,13 +26,10 @@ public class GetAllUserChallengesEndpoint(UsersRepository usersRepository, UserS return; } - List challenges = []; - if (user.UserRandomChallenges is not null) - challenges.AddRange( - user.UserRandomChallenges - .Where(x => x.Proof is not null) - .Select(x => mapper.Map(x.RandomChallenge)) - ); + List challenges = user.UserRandomChallenges? + .Where(x => x.Proof is not null) + .Select(x => mapper.Map(x.RandomChallenge)) + .ToList() ?? []; await Send.OkAsync(challenges.OrderByDescending(x => x.ChallengeStartDate).ToList(), ct); } diff --git a/BeReadyBackend/Endpoints/Users/GetAllUserProofsEndpoint.cs b/BeReadyBackend/Endpoints/Users/GetAllUserProofsEndpoint.cs index 05da4a1..4a58065 100644 --- a/BeReadyBackend/Endpoints/Users/GetAllUserProofsEndpoint.cs +++ b/BeReadyBackend/Endpoints/Users/GetAllUserProofsEndpoint.cs @@ -25,17 +25,14 @@ public class GetAllUserProofsEndpoint(UsersRepository usersRepository, UserServi await Send.NotFoundAsync(ct); return; } - - List 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 - }) - ); + + List proofs = user.UserRandomChallenges? + .Where(x => x.Proof is not null) + .Select(x => new GetUserProofDto + { + Proof = x.Proof + }) + .ToList() ?? []; await Send.OkAsync(proofs, ct); } diff --git a/BeReadyBackend/Specifications/Users/GetProofOrChallengeByUserIdSpec.cs b/BeReadyBackend/Specifications/Users/GetProofOrChallengeByUserIdSpec.cs index 3a2ed43..e28b7ba 100644 --- a/BeReadyBackend/Specifications/Users/GetProofOrChallengeByUserIdSpec.cs +++ b/BeReadyBackend/Specifications/Users/GetProofOrChallengeByUserIdSpec.cs @@ -10,8 +10,6 @@ public class GetProofOrChallengeByUserIdSpec : SingleResultSpecification Query .Include(x => x.UserRandomChallenges!) .ThenInclude(x => x.RandomChallenge) - .Include(x => x.UserGroups!) - .ThenInclude(x => x.Group) .Where(x => x.Id == userId); } } \ No newline at end of file