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