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