This commit is contained in:
2025-05-11 00:09:36 +08:00
parent ea926fe7d2
commit ef9227cc01
15 changed files with 243 additions and 19 deletions

View File

@@ -4,12 +4,26 @@
public record DeleteCommentCommandResponse(int Id);
public class DeleteCommentCommandHandler(BlogDbContext db) : IRequestHandler<DeleteCommentCommand, DeleteCommentCommandResponse>
public class DeleteCommentCommandHandler(
BlogDbContext db,
IIdentityContext identity) : IRequestHandler<DeleteCommentCommand, DeleteCommentCommandResponse>
{
private readonly BlogDbContext _db = db;
private readonly IIdentityContext _identity = identity;
public async Task<DeleteCommentCommandResponse> Handle(DeleteCommentCommand request, CancellationToken cancellationToken)
{
var identityUser = await _db.Users.FindAsync(_identity.Id);
if (identityUser == null)
{
throw new UserNotExistsException(_identity.Id);
}
if (!identityUser.IsSystemUser())
{
throw new AccessDeniedException();
}
var comment = await _db.Comments.FindAsync(request.Id);
if (comment != null)
{