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