This commit is contained in:
2025-05-16 23:14:52 +08:00
parent 5080850523
commit c6d62a68ca
25 changed files with 543 additions and 60 deletions

View File

@@ -1,6 +1,4 @@
using Yes.Infrastructure.Authorizations;
namespace Yes.Blog.Endpoints.Admins.Auths
namespace Yes.Blog.Endpoints.Admins.Auths
{
public class UserLoginEndpoint : AuthEndpointScheme, IEndpoint
{

View File

@@ -1,6 +1,4 @@
using Yes.Infrastructure.Authorizations;
namespace Yes.Blog.Endpoints.Admins.Auths
namespace Yes.Blog.Endpoints.Admins.Auths
{
public class ValidateEndpoint : AuthEndpointScheme, IEndpoint
{

View File

@@ -0,0 +1,22 @@
namespace Yes.Blog.Endpoints.Admins.Themes
{
public class DeleteThemeEndpoint : ThemeEndpointScheme, IEndpoint
{
public void Map(IEndpointRouteBuilder app) => app.MapDelete("/themes", Handle);
public record Request([FromQuery(Name = "theme")] string ThemeName);
private async Task<IResult> Handle(
[AsParameters] Request request,
IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
{
var command = new DeleteThemeCommand(request.ThemeName);
var response = await mediator.Send(command, cancellationToken);
return Result.Ok();
}
}
}

View File

@@ -0,0 +1,25 @@
namespace Yes.Blog.Endpoints.Admins.Themes
{
public class DownloadThemeEndpoint : ThemeEndpointScheme, IEndpoint
{
public void Map(IEndpointRouteBuilder app) => app.MapGet("/themes/{themeName}/download", Handle);
public record Request([FromRoute(Name = "themeName")] string ThemeName);
private async Task<Microsoft.AspNetCore.Http.IResult> Handle(
[AsParameters] Request request,
IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
{
var command = new DownloadThemeCommand(request.ThemeName);
var response = await mediator.Send(command, cancellationToken);
string contentType = "application/zip";
string fileDownloadName = Path.GetFileName(response.Filepath);
return Results.File(response.Filepath, contentType, fileDownloadName);
}
}
}

View File

@@ -4,11 +4,11 @@
{
public void Map(IEndpointRouteBuilder app) => app.MapPut("/themes", Handle).WithRequestValidation<Request>();
internal record Request(
public record Request(
string Theme
);
internal class RequestValidator : AbstractValidator<Request>
public class RequestValidator : AbstractValidator<Request>
{
public RequestValidator()
{
@@ -27,7 +27,7 @@
}
}
internal class UpdateThemeMappingProfile : IRegister
public class UpdateThemeMappingProfile : IRegister
{
public void Register(TypeAdapterConfig config)
{

View File

@@ -4,10 +4,12 @@
{
public void Map(IEndpointRouteBuilder app) => app.MapPost("/themes/upload", Handle).DisableAntiforgery();
private async Task<IResult> Handle(IFormFile File, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
internal record Request(
string? Theme
);
private async Task<IResult> Handle([AsParameters] Request request, IFormFile File, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
{
var command = new UploadThemeCommand(File);
var command = new UploadThemeCommand(File, request.Theme??"");
var response = await mediator.Send(command, cancellationToken);