fix error in all update endpoint

This commit is contained in:
2025-10-17 11:25:50 +02:00
parent a022ed2f38
commit 5448dcbf8f
2 changed files with 8 additions and 6 deletions

View File

@@ -30,7 +30,6 @@ public class UpdateCommentEndpoint(BlogPlatformDbContext database) : Endpoint<Up
comment.PostId = req.PostId;
comment.UserId = req.UserId;
database.Comments.Add(comment);
await database.SaveChangesAsync(ct);
GetCommentDto responseDto = new()

View File

@@ -15,7 +15,10 @@ public class UpdatePostEndpoint(BlogPlatformDbContext database) : Endpoint<Updat
public override async Task HandleAsync(UpdatePostDto 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);
var checkUser = await database.Users.SingleOrDefaultAsync(x => x.Id == req.UserId, ct);
if (checkUser == null || post == null)
@@ -24,11 +27,11 @@ public class UpdatePostEndpoint(BlogPlatformDbContext database) : Endpoint<Updat
return;
}
post.Title = post.Title;
post.Content = post.Content;
post.Likes = post.Likes;
post.Title = req.Title;
post.Content = req.Content;
post.Likes = req.Likes;
post.CreatedAt = DateOnly.FromDateTime(DateTime.Now);
post.UserId = post.UserId;
post.UserId = req.UserId;
await database.SaveChangesAsync(ct);
GetPostDto responseDto = new()