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

@@ -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);