Files
yes.blog/Yes.Blog/Endpoints/Admins/Configurations/UpdateConfigurationEndpoint.cs
2025-05-15 12:53:47 +08:00

62 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>();
}
}
}