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