1
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace Yes.Application.Admins.Configurations
|
||||
using static Dapper.SqlMapper;
|
||||
|
||||
namespace Yes.Application.Admins.Configurations
|
||||
{
|
||||
public record UpdateConfigurationCommand(
|
||||
string Name,
|
||||
@@ -19,14 +21,33 @@
|
||||
|
||||
public record UpdateConfigurationCommandResponse(int Id);
|
||||
|
||||
public class UpdateConfigurationCommandHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IConfigurationService configurationService) : IRequestHandler<UpdateConfigurationCommand, Unit>
|
||||
public class UpdateConfigurationCommandHandler(
|
||||
IOptionsMonitor<BlogSettings> options,
|
||||
IMapper mapper,
|
||||
IConfigurationService configurationService,
|
||||
BlogDbContext db,
|
||||
IIdentityContext identity) : IRequestHandler<UpdateConfigurationCommand, Unit>
|
||||
{
|
||||
private readonly BlogSettings _settings = options.CurrentValue;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
private readonly IConfigurationService _configurationService = configurationService;
|
||||
private readonly BlogDbContext _db = db;
|
||||
private readonly IIdentityContext _identity = identity;
|
||||
|
||||
public async Task<Unit> Handle(UpdateConfigurationCommand 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();
|
||||
}
|
||||
|
||||
_mapper.Map(request, _settings);
|
||||
|
||||
await _configurationService.SaveConfiguration(_settings);
|
||||
|
||||
Reference in New Issue
Block a user