Added proof on endpoint to see all posts

This commit is contained in:
2026-05-14 11:17:19 +01:00
parent 747ad10090
commit 01b7675703
4 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ public class GetPostDto
public DateTime CreationDate { get; set; } public DateTime CreationDate { get; set; }
public int Likes { get; set; } public int Likes { get; set; }
public bool IsLiked { get; set; } public bool IsLiked { get; set; }
public string? Proof { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public string? Username { get; set; } public string? Username { get; set; }
} }
@@ -26,6 +26,10 @@ public class GetAllPostsEndpoint(PostsRepository postsRepository, UserService us
Libelle = x.Libelle, Libelle = x.Libelle,
CreationDate = x.CreationDate, CreationDate = x.CreationDate,
Likes = x.Likes, 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, UserId = x.UserId,
Username = x.User?.Username, Username = x.User?.Username,
IsLiked = x.UserPosts?.Count(y => y.UserId == userId) > 0 IsLiked = x.UserPosts?.Count(y => y.UserId == userId) > 0
@@ -10,7 +10,6 @@ namespace BeReadyBackend.Endpoints.RandomChallenges;
public class RandomChallengeProofRequest public class RandomChallengeProofRequest
{ {
public int RandomChallengeId { get; set; } public int RandomChallengeId { get; set; }
public string? Libelle { get; set; }
public IFormFile? Proof { get; set; } public IFormFile? Proof { get; set; }
} }
@@ -85,11 +84,11 @@ public class PatchProofEndpoint(
Post post = new() Post post = new()
{ {
Libelle = req.Libelle,
CreationDate = DateTime.Now, CreationDate = DateTime.Now,
Libelle = "test pour le moment",
UserId = userId UserId = userId
}; };
await postsRepository.AddAsync(post, ct); await postsRepository.AddAsync(post, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
@@ -9,7 +9,9 @@ public class GetPostNotMeSpec : Specification<Post>
{ {
Query Query
.Include(x => x.User) .Include(x => x.User)
.Include(x => x.UserPosts!) .ThenInclude(urc => urc.UserRandomChallenges)
.ThenInclude(r => r.RandomChallenge)
.Include(x => x.UserPosts)
.ThenInclude(up => up.User) .ThenInclude(up => up.User)
.Where(x => x.UserId != userId && .Where(x => x.UserId != userId &&
x.CreationDate >= DateTime.Today && x.CreationDate < DateTime.Today.AddDays(1)); x.CreationDate >= DateTime.Today && x.CreationDate < DateTime.Today.AddDays(1));