fix
This commit is contained in:
@@ -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);
|
||||||
|
@@ -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()
|
||||||
|
Reference in New Issue
Block a user