1
This commit is contained in:
46
Yes.Application/Admins/Pages/GetPageQueryHandler.cs
Normal file
46
Yes.Application/Admins/Pages/GetPageQueryHandler.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace Yes.Application.Admins.Pages
|
||||
{
|
||||
|
||||
public record GetPageQuery(int Id) : IRequest<GetPageQueryResponse>;
|
||||
|
||||
public record GetPageQueryResponse(
|
||||
int Id,
|
||||
string Title,
|
||||
int CategoryId,
|
||||
string Content,
|
||||
string Slug,
|
||||
string CoverUrl,
|
||||
string? Summary,
|
||||
string[] Tags,
|
||||
int Sort
|
||||
);
|
||||
|
||||
public class GetPageQueryHandler(BlogDbContext db,IMapper mapper) : IRequestHandler<GetPageQuery, GetPageQueryResponse>
|
||||
{
|
||||
private readonly BlogDbContext _db = db;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
public async Task<GetPageQueryResponse> Handle(GetPageQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var page = await _db.Articles.FindAsync(request.Id);
|
||||
if (page == null)
|
||||
{
|
||||
throw new PageNotExistsException(request.Id);
|
||||
}
|
||||
|
||||
var response = _mapper.Map<GetPageQueryResponse>(page);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
internal class CreatePageMappingProfile : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.ForType<ArticleEntity, GetPageQueryResponse>()
|
||||
.Map(dest => dest.Tags, src => src.Tag.ToTags()); ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user