This commit is contained in:
2025-10-17 12:06:03 +02:00
parent 5448dcbf8f
commit be192348ae
2 changed files with 8 additions and 4 deletions

View File

@@ -15,7 +15,9 @@ public class PatchPostDecrementLikeEndpoint(BlogPlatformDbContext database) : En
public override async Task HandleAsync(PatchPostDecrementLikeDto req, CancellationToken ct) 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) if (post == null)
{ {
@@ -25,7 +27,7 @@ public class PatchPostDecrementLikeEndpoint(BlogPlatformDbContext database) : En
if (post.Likes > 0) if (post.Likes > 0)
{ {
post.Likes = post.Likes--; post.Likes--;
} }
else post.Likes = 0; else post.Likes = 0;
await database.SaveChangesAsync(ct); await database.SaveChangesAsync(ct);

View File

@@ -15,7 +15,9 @@ public class PatchPostIncrementLikeEndpoint(BlogPlatformDbContext database) : En
public override async Task HandleAsync(PatchPostIncrementLikeDto req, CancellationToken ct) 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) if (post == null)
{ {
@@ -23,7 +25,7 @@ public class PatchPostIncrementLikeEndpoint(BlogPlatformDbContext database) : En
return; return;
} }
post.Likes = post.Likes++; post.Likes++;
await database.SaveChangesAsync(ct); await database.SaveChangesAsync(ct);
GetPostDto responseDto = new() GetPostDto responseDto = new()