1
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Admins.Categories
|
||||
{
|
||||
public class CreateCategoryEndpoint : AdminEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapPost("/categories", Handle).WithRequestValidation<Request>();
|
||||
|
||||
public record Request(
|
||||
string Name,
|
||||
string? Slug,
|
||||
string? CoverUrl,
|
||||
string? Description,
|
||||
int Sort
|
||||
);
|
||||
|
||||
public class RequestValidator : AbstractValidator<Request>
|
||||
{
|
||||
public RequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().WithMessage("分类名不能为空!");
|
||||
RuleFor(x => x.Slug).NotEmpty().WithMessage("缩略名不能为空!");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IResult> Handle([FromBody] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||||
{
|
||||
var command = mapper.Map<CreateCategoryCommand>(request);
|
||||
var response = await mediator.Send(command, cancellationToken);
|
||||
|
||||
|
||||
return Result.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
internal class CreateArticleMappingProfile : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<CreateCategoryEndpoint.Request, CreateCategoryCommand>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Yes.Blog.Endpoints.Admins.Categories
|
||||
{
|
||||
public class DeleteCategoryEndpoint : AdminEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapDelete("/categories", Handle);
|
||||
|
||||
public record Request(int Id);
|
||||
|
||||
|
||||
private async Task<IResult> Handle([AsParameters] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||||
{
|
||||
var command = mapper.Map<DeleteCategoryCommand>(request);
|
||||
var response = await mediator.Send(command, cancellationToken);
|
||||
|
||||
|
||||
return Result.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Admins.Categories
|
||||
{
|
||||
public class GetCategoriesEndpoint : AdminEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapGet("/categories", Handle);
|
||||
|
||||
public record Request();
|
||||
|
||||
|
||||
private async Task<IResult> Handle([AsParameters] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = new GetCategoriesQuery();
|
||||
var response = await mediator.Send(query, cancellationToken);
|
||||
|
||||
|
||||
return Result.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs
Normal file
22
Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Admins.Categories
|
||||
{
|
||||
public class GetCategoryEndpoint : AdminEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapGet("/categories/{id}", Handle);
|
||||
|
||||
public record Request([FromRoute(Name = "id")] int Id);
|
||||
|
||||
|
||||
private async Task<IResult> Handle([AsParameters] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = new GetCategoryQuery(request.Id);
|
||||
var response = await mediator.Send(query, cancellationToken);
|
||||
|
||||
|
||||
return Result.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
namespace Yes.Blog.Endpoints.Admins.Categories
|
||||
{
|
||||
public class UpdateCategoryEndpoint : AdminEndpointScheme, IEndpoint
|
||||
{
|
||||
public void Map(IEndpointRouteBuilder app) => app.MapPut("/categories", Handle).WithRequestValidation<Request>();
|
||||
|
||||
public record Request(
|
||||
int Id,
|
||||
string Name,
|
||||
string? Slug,
|
||||
string? CoverUrl,
|
||||
string? Description,
|
||||
int Sort
|
||||
);
|
||||
|
||||
public class RequestValidator : AbstractValidator<Request>
|
||||
{
|
||||
public RequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().WithMessage("分类名不能为空!");
|
||||
RuleFor(x => x.Slug).NotEmpty().WithMessage("缩略名不能为空!");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IResult> Handle([FromBody] Request request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken)
|
||||
{
|
||||
var command = mapper.Map<UpdateCategoryCommand>(request);
|
||||
var response = await mediator.Send(command, cancellationToken);
|
||||
|
||||
|
||||
return Result.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
internal class UpdateCategoryMappingProfile : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<UpdateCategoryEndpoint.Request, UpdateCategoryCommand>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user