From 01b76757037d23194e883262ad51c442c6327c7a Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 14 May 2026 11:17:19 +0100 Subject: [PATCH] Added proof on endpoint to see all posts --- BeReadyBackend/DTO/Posts/GetPostDto.cs | 2 +- BeReadyBackend/Endpoints/Posts/GetAllPostsEndpoint.cs | 4 ++++ .../Endpoints/RandomChallenges/PatchProofEndpoint.cs | 5 ++--- BeReadyBackend/Specifications/Posts/GetPostNotMeSpec.cs | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/BeReadyBackend/DTO/Posts/GetPostDto.cs b/BeReadyBackend/DTO/Posts/GetPostDto.cs index 74f3f73..76e7a80 100644 --- a/BeReadyBackend/DTO/Posts/GetPostDto.cs +++ b/BeReadyBackend/DTO/Posts/GetPostDto.cs @@ -7,7 +7,7 @@ public class GetPostDto public DateTime CreationDate { get; set; } public int Likes { get; set; } public bool IsLiked { get; set; } - + public string? Proof { get; set; } public int UserId { get; set; } public string? Username { get; set; } } \ No newline at end of file diff --git a/BeReadyBackend/Endpoints/Posts/GetAllPostsEndpoint.cs b/BeReadyBackend/Endpoints/Posts/GetAllPostsEndpoint.cs index 006c0f9..859f032 100644 --- a/BeReadyBackend/Endpoints/Posts/GetAllPostsEndpoint.cs +++ b/BeReadyBackend/Endpoints/Posts/GetAllPostsEndpoint.cs @@ -26,6 +26,10 @@ public class GetAllPostsEndpoint(PostsRepository postsRepository, UserService us Libelle = x.Libelle, CreationDate = x.CreationDate, Likes = x.Likes, + Proof = x.User?.UserRandomChallenges? + .SingleOrDefault(u => + u.RandomChallenge?.GeneratedAt is not null && DateOnly.FromDateTime(u.RandomChallenge.GeneratedAt.Value) == DateOnly.FromDateTime(x.CreationDate)) + ?.Proof, UserId = x.UserId, Username = x.User?.Username, IsLiked = x.UserPosts?.Count(y => y.UserId == userId) > 0 diff --git a/BeReadyBackend/Endpoints/RandomChallenges/PatchProofEndpoint.cs b/BeReadyBackend/Endpoints/RandomChallenges/PatchProofEndpoint.cs index b068106..92498af 100644 --- a/BeReadyBackend/Endpoints/RandomChallenges/PatchProofEndpoint.cs +++ b/BeReadyBackend/Endpoints/RandomChallenges/PatchProofEndpoint.cs @@ -10,7 +10,6 @@ namespace BeReadyBackend.Endpoints.RandomChallenges; public class RandomChallengeProofRequest { public int RandomChallengeId { get; set; } - public string? Libelle { get; set; } public IFormFile? Proof { get; set; } } @@ -85,11 +84,11 @@ public class PatchProofEndpoint( Post post = new() { - Libelle = req.Libelle, CreationDate = DateTime.Now, + Libelle = "test pour le moment", UserId = userId }; - + await postsRepository.AddAsync(post, ct); await Send.NoContentAsync(ct); } diff --git a/BeReadyBackend/Specifications/Posts/GetPostNotMeSpec.cs b/BeReadyBackend/Specifications/Posts/GetPostNotMeSpec.cs index e55742e..14276c8 100644 --- a/BeReadyBackend/Specifications/Posts/GetPostNotMeSpec.cs +++ b/BeReadyBackend/Specifications/Posts/GetPostNotMeSpec.cs @@ -9,7 +9,9 @@ public class GetPostNotMeSpec : Specification { Query .Include(x => x.User) - .Include(x => x.UserPosts!) + .ThenInclude(urc => urc.UserRandomChallenges) + .ThenInclude(r => r.RandomChallenge) + .Include(x => x.UserPosts) .ThenInclude(up => up.User) .Where(x => x.UserId != userId && x.CreationDate >= DateTime.Today && x.CreationDate < DateTime.Today.AddDays(1));