feat: 文章列表
This commit is contained in:
1 parent
7406fffdfa
commit
089cacee78
6 files changed
+35
-7
No files matched your search
@@ -18,4 +18,14 @@ export class CreateArticleRequest {
|
||||
})
|
||||
@MaxLength(10000, { message: '文章内容长度不能超过10000字符' })
|
||||
content: string;
|
||||
|
||||
@ApiProperty({})
|
||||
@IsNotEmpty({ message: '文章缩略图不能为空' })
|
||||
thumbnail: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: '测试文章描述',
|
||||
})
|
||||
@MaxLength(500, { message: '文章描述长度不能超过500字符' })
|
||||
description: string;
|
||||
}
|
||||
@@ -35,6 +35,13 @@ export class SearchArticleFilter extends BaseFilter {
|
||||
conditions.status = this.status;
|
||||
}
|
||||
|
||||
if (this.categoryId) {
|
||||
conditions.category = {
|
||||
id: this.categoryId,
|
||||
};
|
||||
this.categoryId = undefined;
|
||||
}
|
||||
|
||||
return conditions;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ export class Article extends TraceableEntity {
|
||||
@Column()
|
||||
title: string;
|
||||
|
||||
@Column()
|
||||
description: string;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true,
|
||||
@@ -20,6 +23,9 @@ export class Article extends TraceableEntity {
|
||||
})
|
||||
category: Category;
|
||||
|
||||
@Column()
|
||||
thumbnail: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: ArticleStatus,
|
||||
|
||||
@@ -12,6 +12,8 @@ export class ArticleMapper {
|
||||
content: entity.content,
|
||||
category: CategoryMapper.toVo(entity.category),
|
||||
status: entity.status,
|
||||
thumbnail: entity.thumbnail,
|
||||
description: entity.description,
|
||||
createdTime: DateUtil.format(entity.createdTime),
|
||||
updatedTime: DateUtil.format(entity.updatedTime),
|
||||
createBy: UserMapper.toVo(entity.createBy),
|
||||
|
||||
@@ -36,17 +36,12 @@ export class ArticleService {
|
||||
article.title = createArticleRequest.title;
|
||||
article.content = createArticleRequest.content;
|
||||
article.category = category;
|
||||
article.thumbnail = createArticleRequest.thumbnail;
|
||||
article.description = createArticleRequest.description;
|
||||
return this.articleRepository.save(article);
|
||||
}
|
||||
|
||||
async search(searchArticleFilter: SearchArticleFilter) {
|
||||
const conditions = searchArticleFilter.getConditions();
|
||||
if (searchArticleFilter.categoryId) {
|
||||
conditions.category = await this.categoryService.get(
|
||||
searchArticleFilter.categoryId,
|
||||
);
|
||||
}
|
||||
|
||||
if (searchArticleFilter.title) {
|
||||
await this.traceSearchRecord(searchArticleFilter.title);
|
||||
}
|
||||
@@ -92,6 +87,8 @@ export class ArticleService {
|
||||
}
|
||||
article.title = updateArticle.title;
|
||||
article.content = updateArticle.content;
|
||||
article.thumbnail = updateArticle.thumbnail;
|
||||
article.description = updateArticle.description;
|
||||
return this.articleRepository.save(article);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,4 +18,10 @@ export class ArticleVo extends TraceableVo {
|
||||
|
||||
@ApiProperty()
|
||||
status: ArticleStatus;
|
||||
|
||||
@ApiProperty()
|
||||
thumbnail: string;
|
||||
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
}
|
||||
Reference in new issue
Block a user