From be192348ae0c6aced52ff095eafaef9eb9d48bc2 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Fri, 17 Oct 2025 12:06:03 +0200 Subject: [PATCH] fix --- .../Endpoints/Post/PatchPostDecrementLikeEndpoint.cs | 6 ++++-- .../Endpoints/Post/PatchPostIncrementLikeEndpoint.cs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BlogPlatform/Endpoints/Post/PatchPostDecrementLikeEndpoint.cs b/BlogPlatform/Endpoints/Post/PatchPostDecrementLikeEndpoint.cs index 6a1b552..51803fe 100644 --- a/BlogPlatform/Endpoints/Post/PatchPostDecrementLikeEndpoint.cs +++ b/BlogPlatform/Endpoints/Post/PatchPostDecrementLikeEndpoint.cs @@ -15,7 +15,9 @@ public class PatchPostDecrementLikeEndpoint(BlogPlatformDbContext database) : En public override async Task HandleAsync(PatchPostDecrementLikeDto req, CancellationToken ct) { - var post = await database.Posts.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + var post = await database.Posts + .Include(p => p.Comments) + .SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (post == null) { @@ -25,7 +27,7 @@ public class PatchPostDecrementLikeEndpoint(BlogPlatformDbContext database) : En if (post.Likes > 0) { - post.Likes = post.Likes--; + post.Likes--; } else post.Likes = 0; await database.SaveChangesAsync(ct); diff --git a/BlogPlatform/Endpoints/Post/PatchPostIncrementLikeEndpoint.cs b/BlogPlatform/Endpoints/Post/PatchPostIncrementLikeEndpoint.cs index b0ef649..f7e3287 100644 --- a/BlogPlatform/Endpoints/Post/PatchPostIncrementLikeEndpoint.cs +++ b/BlogPlatform/Endpoints/Post/PatchPostIncrementLikeEndpoint.cs @@ -15,7 +15,9 @@ public class PatchPostIncrementLikeEndpoint(BlogPlatformDbContext database) : En public override async Task HandleAsync(PatchPostIncrementLikeDto req, CancellationToken ct) { - var post = await database.Posts.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + var post = await database.Posts + .Include(p => p.Comments) + .SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (post == null) { @@ -23,7 +25,7 @@ public class PatchPostIncrementLikeEndpoint(BlogPlatformDbContext database) : En return; } - post.Likes = post.Likes++; + post.Likes++; await database.SaveChangesAsync(ct); GetPostDto responseDto = new()