新增文章模块封面图片功能,包括在数据传输对象、模型和服务中添加封面图片字段,并在推荐服务中更新文章卡片以显示封面图片。
This commit is contained in:
@@ -18,6 +18,7 @@ export class ArticlesService {
|
||||
title: dto.title,
|
||||
publishedDate: dto.publishedDate as any,
|
||||
htmlContent: dto.htmlContent,
|
||||
coverImage: dto.coverImage,
|
||||
});
|
||||
return { code: ResponseCode.SUCCESS, message: 'success', data: article.toJSON() as ArticleVo };
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ export class CreateArticleDto {
|
||||
|
||||
@ApiProperty({ description: 'HTML 富文本内容' })
|
||||
htmlContent!: string;
|
||||
|
||||
@ApiProperty({ description: '封面图片' })
|
||||
coverImage!: string;
|
||||
}
|
||||
|
||||
export class QueryArticlesDto {
|
||||
@@ -35,6 +38,7 @@ export interface ArticleVo {
|
||||
publishedDate: string;
|
||||
readCount: number;
|
||||
htmlContent: string;
|
||||
coverImage: string;
|
||||
}
|
||||
|
||||
export type CreateArticleResponseDto = BaseResponseDto<ArticleVo>;
|
||||
|
||||
@@ -19,6 +19,13 @@ export class Article extends Model {
|
||||
})
|
||||
declare title: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.TEXT,
|
||||
allowNull: false,
|
||||
comment: '封面图片',
|
||||
})
|
||||
declare coverImage: string;
|
||||
|
||||
@Column({
|
||||
type: DataType.DATEONLY,
|
||||
allowNull: false,
|
||||
|
||||
@@ -14,11 +14,13 @@ export class RecommendationsService {
|
||||
const limit = 10
|
||||
|
||||
// 取最新文章若干
|
||||
const articlesRes = await this.articlesService.query({ page: 1, pageSize: limit } as any);
|
||||
const articlesRes = await this.articlesService.query({ page: 1, pageSize: limit });
|
||||
const articleCards: RecommendationCard[] = (articlesRes.data.list || []).map(a => ({
|
||||
id: `article-${a.id}`,
|
||||
type: RecommendationType.Article,
|
||||
title: a.title,
|
||||
coverUrl: a.coverImage,
|
||||
html: a.htmlContent,
|
||||
articleId: a.id,
|
||||
extra: { publishedDate: a.publishedDate, readCount: a.readCount },
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user