This commit is contained in:
2025-04-30 09:51:36 +08:00
parent 561881c9aa
commit 09afa239a6
848 changed files with 385870 additions and 205 deletions

View File

@@ -0,0 +1,34 @@
namespace Yes.Application.Admins.Comments
{
public record GetLatestCommentsQuery() : IRequest<List<GetLatestCommentsQueryResponse>>;
public record GetLatestCommentsQueryResponse(
int Id,
int ArticleId,
string Content,
DateTime CreateDate,
bool HasVerified
);
public class GetLatestCommentsQueryHandler(BlogDbContext db) : IRequestHandler<GetLatestCommentsQuery, List<GetLatestCommentsQueryResponse>>
{
private readonly BlogDbContext _db = db;
public async Task<List<GetLatestCommentsQueryResponse>> Handle(GetLatestCommentsQuery request, CancellationToken cancellationToken)
{
var query = _db.Comments.AsNoTracking().OrderByDescending(x => x.Id).Select(comment =>
new GetLatestCommentsQueryResponse(
comment.Id,
comment.ArticleId,
comment.Content,
comment.CreateDate,
comment.Status== CommentStatusEnum.审核通过
)
).Take(10);
var comments = await query.ToListAsync(cancellationToken);
return comments;
}
}
}