62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
namespace Yes.Blog.Endpoints.Admins.Configurations
|
||
{
|
||
public class UpdateConfigurationEndpoint : ConfigurationEndpointScheme, IEndpoint
|
||
{
|
||
public void Map(IEndpointRouteBuilder app) => app.MapPut("/configuration", Handle).WithRequestValidation<Request>();
|
||
|
||
public record Request(
|
||
string Name,
|
||
string Url,
|
||
string Logo,
|
||
string Keywords,
|
||
string Description,
|
||
string BeiAn,
|
||
string Script,
|
||
int PageSizeOfHomepage,
|
||
int PageSizeOfListpage,
|
||
int RssGenerationIntervalHours,
|
||
string ArticleRoute,
|
||
string PageRoute,
|
||
string CategoryRoute,
|
||
string SearchRoute,
|
||
string TagRoute,
|
||
StorageSettings Storage
|
||
);
|
||
|
||
public class RequestValidator : AbstractValidator<Request>
|
||
{
|
||
public RequestValidator()
|
||
{
|
||
RuleFor(x => x.Name).NotEmpty().WithMessage("站点名不能为空!");
|
||
|
||
RuleFor(x => x.ArticleRoute).NotEmpty().WithMessage("文章路径不能为空!");
|
||
RuleFor(x => x.PageRoute).NotEmpty().WithMessage("独立页面路径不能为空!");
|
||
RuleFor(x => x.CategoryRoute).NotEmpty().WithMessage("分类页路径不能为空!");
|
||
RuleFor(x => x.SearchRoute).NotEmpty().WithMessage("搜索页路径不能为空!");
|
||
RuleFor(x => x.TagRoute).NotEmpty().WithMessage("标签页路径不能为空!");
|
||
|
||
RuleFor(x => x.PageSizeOfHomepage).GreaterThan(0).WithMessage("主页每页文章数必须大于0!");
|
||
RuleFor(x => x.PageSizeOfListpage).GreaterThan(0).WithMessage("列表页每页文章数必须大于0!");
|
||
RuleFor(x => x.RssGenerationIntervalHours).GreaterThan(0).WithMessage("RSS生成频率必须大于0!");
|
||
}
|
||
}
|
||
|
||
private async Task<IResult> Handle([FromBody] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||
{
|
||
var command = mapper.Map<UpdateConfigurationCommand>(request);
|
||
var response = await mediator.Send(command, cancellationToken);
|
||
|
||
|
||
return Result.Ok(response);
|
||
}
|
||
}
|
||
|
||
internal class UpdateConfigurationMappingProfile : IRegister
|
||
{
|
||
public void Register(TypeAdapterConfig config)
|
||
{
|
||
config.ForType<UpdateConfigurationEndpoint.Request, UpdateConfigurationCommand>();
|
||
}
|
||
}
|
||
}
|