1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
|
||||
namespace Yes.Application.Admins.Configurations
|
||||
{
|
||||
public class ConfigurationService(IWebHostEnvironment env) : IConfigurationService
|
||||
{
|
||||
private readonly IWebHostEnvironment _env = env;
|
||||
|
||||
public async Task SaveConfiguration(BlogSettings settings)
|
||||
{
|
||||
var filePath = Path.Combine(_env.ContentRootPath, "files", "config", "appsettings.blog.json");
|
||||
JObject jsonObject = JObject.FromObject(settings);
|
||||
|
||||
using (var writer = new StreamWriter(filePath))
|
||||
using (JsonTextWriter jsonwriter = new JsonTextWriter(writer))
|
||||
{
|
||||
jsonwriter.Formatting = Formatting.Indented;
|
||||
await jsonObject.WriteToAsync(jsonwriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace Yes.Application.Admins.Configurations
|
||||
{
|
||||
|
||||
public record GetConfigurationQuery() : IRequest<GetConfigurationQueryResponse>;
|
||||
|
||||
public record GetConfigurationQueryResponse(
|
||||
string Name,
|
||||
string Url,
|
||||
string Logo,
|
||||
string Keywords,
|
||||
string Description,
|
||||
string BeiAn,
|
||||
string Script,
|
||||
int PageSizeOfHomepage,
|
||||
int PageSizeOfListpage,
|
||||
string ArticleRoute,
|
||||
string PageRoute,
|
||||
string CategoryRoute,
|
||||
string SearchRoute,
|
||||
string TagRoute,
|
||||
StorageSettingsResponse Storage
|
||||
);
|
||||
|
||||
public record StorageSettingsResponse(string StorageType, QiniuSettingsResponse Qiniu);
|
||||
|
||||
public record QiniuSettingsResponse(string AccessKey, string MaskedAccessKey, string SecretKey, string MaskedSecretKey, string Domain, string Bucket);
|
||||
|
||||
public class GetConfigurationQueryHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper) : IRequestHandler<GetConfigurationQuery, GetConfigurationQueryResponse>
|
||||
{
|
||||
private readonly BlogSettings _settings = options.CurrentValue;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
public async Task<GetConfigurationQueryResponse> Handle(GetConfigurationQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var response = _mapper.Map<GetConfigurationQueryResponse>(_settings);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
internal class GetConfigurationMappingProfile : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<BlogSettings, GetConfigurationQueryResponse>()
|
||||
.Map(dest => dest.Storage.Qiniu.MaskedAccessKey, src => string.IsNullOrEmpty(src.Storage.Qiniu.AccessKey) ? "" : "****************")
|
||||
.Map(dest => dest.Storage.Qiniu.MaskedSecretKey, src => string.IsNullOrEmpty(src.Storage.Qiniu.SecretKey) ? "" : "****************")
|
||||
.Map(dest => dest.Storage.Qiniu.AccessKey, src => "")
|
||||
.Map(dest => dest.Storage.Qiniu.SecretKey, src => "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Yes.Application.Admins.Configurations
|
||||
{
|
||||
public record UpdateConfigurationCommand(
|
||||
string Name,
|
||||
string Url,
|
||||
string Logo,
|
||||
string Keywords,
|
||||
string Description,
|
||||
string BeiAn,
|
||||
string Script,
|
||||
int PageSizeOfHomepage,
|
||||
int PageSizeOfListpage,
|
||||
string ArticleRoute,
|
||||
string PageRoute,
|
||||
string CategoryRoute,
|
||||
string SearchRoute,
|
||||
StorageSettings Storage
|
||||
) : IRequest<Unit>;
|
||||
|
||||
public record UpdateConfigurationCommandResponse(int Id);
|
||||
|
||||
public class UpdateConfigurationCommandHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IConfigurationService configurationService) : IRequestHandler<UpdateConfigurationCommand, Unit>
|
||||
{
|
||||
private readonly BlogSettings _settings = options.CurrentValue;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
private readonly IConfigurationService _configurationService = configurationService;
|
||||
|
||||
public async Task<Unit> Handle(UpdateConfigurationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
_mapper.Map(request, _settings);
|
||||
|
||||
await _configurationService.SaveConfiguration(_settings);
|
||||
|
||||
return new Unit();
|
||||
}
|
||||
}
|
||||
|
||||
internal class UpdateConfigurationMappingProfile : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<UpdateConfigurationCommand, BlogSettings>()
|
||||
.IgnoreIf((src, dest) => !string.IsNullOrEmpty(dest.Storage.Qiniu.AccessKey), dest => dest.Storage.Qiniu.AccessKey)
|
||||
.IgnoreIf((src, dest) => !string.IsNullOrEmpty(dest.Storage.Qiniu.SecretKey), dest => dest.Storage.Qiniu.SecretKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user