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()