Skip to content

Commit 598c0fc

Browse files
authored
feat: topic comment (#950)
1 parent 144de12 commit 598c0fc

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

next/api/src/controller/article-topic.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import { dynamicContentService } from '@/dynamic-content';
2626

2727
const createArticleTopicSchema = z.object({
2828
name: z.string(),
29-
articleIds: z.array(z.string()),
29+
comment: z.string().optional(),
30+
articleIds: z.array(z.string()).default([]),
3031
meta: z.record(z.any()).optional(),
3132
});
3233

@@ -90,12 +91,12 @@ export class ArticleTopicController {
9091
}
9192

9293
@Patch(':id')
93-
async update(
94+
@ResponseBody(ArticleTopicResponse)
95+
update(
9496
@Param('id', new FindModelWithoutDeleteFlagPipe(ArticleTopic)) topic: ArticleTopic,
9597
@Body(new ZodValidationPipe(updateArticleTopicSchema)) data: UpdateArticleTopicData
9698
) {
97-
await topic.update(data, { useMasterKey: true });
98-
return {};
99+
return topic.update(data, { useMasterKey: true });
99100
}
100101

101102
@Delete(':id')

next/api/src/model/ArticleTopic.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export class ArticleTopic extends Model {
1212
@serialize()
1313
name!: string;
1414

15+
@field()
16+
@serialize()
17+
comment?: string;
18+
1519
@field('FAQIds')
1620
@serialize()
1721
articleIds!: string[];

next/api/src/response/article-topic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ArticleTopicResponse {
99
id: this.topic.id,
1010
meta: this.topic.meta,
1111
name: this.topic.name,
12+
comment: this.topic.comment,
1213
articleIds: this.topic.articleIds,
1314
createdAt: this.topic.createdAt.toISOString(),
1415
updatedAt: this.topic.updatedAt.toISOString(),

next/web/src/App/Admin/Settings/Topics/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ export function TopicList() {
8181
title="名称"
8282
render={(name, topic) => <Link to={`${topic.id}`}>{name}</Link>}
8383
/>
84+
<Column dataIndex="comment" title="备注" />
8485
<Column<Topic>
8586
dataIndex="articleIds"
86-
title="数量"
87+
title="文章数量"
8788
render={(articleIds) => articleIds.length}
8889
/>
8990
<Column<Topic>
@@ -109,7 +110,6 @@ function EditTopic({ initData, loading, onSave }: EditTopicProps) {
109110
});
110111

111112
const { data: articles, isLoading: loadingArticles } = useArticles();
112-
const articleMap = useMemo(() => _.keyBy(articles, 'id'), [articles]);
113113

114114
return (
115115
<Form layout="vertical" onFinish={handleSubmit(onSave)}>
@@ -129,6 +129,16 @@ function EditTopic({ initData, loading, onSave }: EditTopicProps) {
129129
)}
130130
/>
131131

132+
<Controller
133+
control={control}
134+
name="comment"
135+
render={({ field }) => (
136+
<Form.Item label="备注" htmlFor="comment">
137+
<Input {...field} id="comment" />
138+
</Form.Item>
139+
)}
140+
/>
141+
132142
<Controller
133143
control={control}
134144
name="articleIds"

next/web/src/api/topic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { http } from '@/leancloud';
55
export interface Topic {
66
id: string;
77
name: string;
8+
comment?: string;
89
articleIds: string[];
9-
meta?: object;
10+
meta?: Record<string, any>;
1011
createdAt: string;
1112
updatedAt: string;
1213
}
@@ -72,17 +73,16 @@ export function useTopic(id: string, { raw, queryOptions }: UseTopicOptions = {}
7273

7374
export interface UpsertTopicData {
7475
name: string;
76+
comment?: string;
7577
articleIds: string[];
76-
meta?: object;
78+
meta?: Record<string, any>;
7779
}
7880

7981
export async function createTopic(data: UpsertTopicData) {
8082
await http.post('/api/2/topics', data);
8183
}
8284

83-
export interface UpdateTopicData extends Partial<UpsertTopicData> {
84-
comment?: string;
85-
}
85+
export interface UpdateTopicData extends Partial<UpsertTopicData> {}
8686

8787
export async function updateTopic(id: string, data: UpdateTopicData) {
8888
await http.patch(`/api/2/topics/${id}`, data);

resources/schema/FAQTopic.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"type": "String",
2727
"required": true
2828
},
29+
"comment": {
30+
"type": "String"
31+
},
2932
"meta": {
3033
"type": "Object"
3134
},

0 commit comments

Comments
 (0)