This commit is contained in:
2025-05-04 22:11:28 +08:00
parent 09afa239a6
commit b7eb0f9a68
69 changed files with 344 additions and 178 deletions

View File

@@ -3,6 +3,10 @@
public class BlogEndpointScheme
{
public int Priority { get; set; } = 0;
public string SchemeName { get; set; } = "";
}
public string Prefix { get; set; } = "";
public string[] Tags { get; set; } = new[] { "Blog" };
}
}

View File

@@ -0,0 +1,53 @@
using Yes.Blog.Endpoints.Admins;
namespace Yes.Blog.Endpoints.Blogs
{
public class InstallEndpoint : BlogEndpointScheme, IEndpoint
{
public void Map(IEndpointRouteBuilder app) => app.MapPost("install", Handle).WithRequestValidation<Request>();
public record Request(
string DatabaseType,
string DatabaseServer,
string DatabaseVersion,
string DatabaseUser,
string DatabasePassword,
string DatabaseName,
bool UseDefaultAdmin
);
public class RequestValidator : AbstractValidator<Request>
{
public RequestValidator()
{
RuleFor(x => x.DatabaseName).NotEmpty().WithMessage("数据库名不能为空!");
RuleFor(x => x.DatabaseServer).NotEmpty().WithMessage("数据库地址不能为空!");
RuleFor(x => x.DatabaseUser).NotEmpty().WithMessage("数据库用户不能为空!");
RuleFor(x => x.DatabasePassword).NotEmpty().WithMessage("数据库密码不能为空!");
}
}
private async Task<IResult> Handle(
[FromBody] Request request,
IMediator mediator,
IMapper mapper,
CancellationToken cancellationToken)
{
var command = mapper.Map<InstallCommand>(request);
var response = await mediator.Send(command, cancellationToken);
if (response.Success)
{
return Result.Ok();
}
else
{
return Result.Error(response.ErrorMessage);
}
}
}
}