1
This commit is contained in:
@@ -9,12 +9,23 @@
|
||||
) : IRequest<Unit>;
|
||||
|
||||
|
||||
public class UpdateUserCommandHandler(BlogDbContext db) : IRequestHandler<UpdateUserCommand, Unit>
|
||||
public class UpdateUserCommandHandler(BlogDbContext db, IIdentityContext identity) : IRequestHandler<UpdateUserCommand, Unit>
|
||||
{
|
||||
private readonly BlogDbContext _db = db;
|
||||
|
||||
private readonly IIdentityContext _identity = identity;
|
||||
public async Task<Unit> Handle(UpdateUserCommand 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 user = await _db.Users.FindAsync(request.Id);
|
||||
if (user == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user