Skip to content

Commit

Permalink
feat: topic comment (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd authored Nov 24, 2023
1 parent 144de12 commit 598c0fc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
9 changes: 5 additions & 4 deletions next/api/src/controller/article-topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { dynamicContentService } from '@/dynamic-content';

const createArticleTopicSchema = z.object({
name: z.string(),
articleIds: z.array(z.string()),
comment: z.string().optional(),
articleIds: z.array(z.string()).default([]),
meta: z.record(z.any()).optional(),
});

Expand Down Expand Up @@ -90,12 +91,12 @@ export class ArticleTopicController {
}

@Patch(':id')
async update(
@ResponseBody(ArticleTopicResponse)
update(
@Param('id', new FindModelWithoutDeleteFlagPipe(ArticleTopic)) topic: ArticleTopic,
@Body(new ZodValidationPipe(updateArticleTopicSchema)) data: UpdateArticleTopicData
) {
await topic.update(data, { useMasterKey: true });
return {};
return topic.update(data, { useMasterKey: true });
}

@Delete(':id')
Expand Down
4 changes: 4 additions & 0 deletions next/api/src/model/ArticleTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class ArticleTopic extends Model {
@serialize()
name!: string;

@field()
@serialize()
comment?: string;

@field('FAQIds')
@serialize()
articleIds!: string[];
Expand Down
1 change: 1 addition & 0 deletions next/api/src/response/article-topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class ArticleTopicResponse {
id: this.topic.id,
meta: this.topic.meta,
name: this.topic.name,
comment: this.topic.comment,
articleIds: this.topic.articleIds,
createdAt: this.topic.createdAt.toISOString(),
updatedAt: this.topic.updatedAt.toISOString(),
Expand Down
14 changes: 12 additions & 2 deletions next/web/src/App/Admin/Settings/Topics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ export function TopicList() {
title="名称"
render={(name, topic) => <Link to={`${topic.id}`}>{name}</Link>}
/>
<Column dataIndex="comment" title="备注" />
<Column<Topic>
dataIndex="articleIds"
title="数量"
title="文章数量"
render={(articleIds) => articleIds.length}
/>
<Column<Topic>
Expand All @@ -109,7 +110,6 @@ function EditTopic({ initData, loading, onSave }: EditTopicProps) {
});

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

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

<Controller
control={control}
name="comment"
render={({ field }) => (
<Form.Item label="备注" htmlFor="comment">
<Input {...field} id="comment" />
</Form.Item>
)}
/>

<Controller
control={control}
name="articleIds"
Expand Down
10 changes: 5 additions & 5 deletions next/web/src/api/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { http } from '@/leancloud';
export interface Topic {
id: string;
name: string;
comment?: string;
articleIds: string[];
meta?: object;
meta?: Record<string, any>;
createdAt: string;
updatedAt: string;
}
Expand Down Expand Up @@ -72,17 +73,16 @@ export function useTopic(id: string, { raw, queryOptions }: UseTopicOptions = {}

export interface UpsertTopicData {
name: string;
comment?: string;
articleIds: string[];
meta?: object;
meta?: Record<string, any>;
}

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

export interface UpdateTopicData extends Partial<UpsertTopicData> {
comment?: string;
}
export interface UpdateTopicData extends Partial<UpsertTopicData> {}

export async function updateTopic(id: string, data: UpdateTopicData) {
await http.patch(`/api/2/topics/${id}`, data);
Expand Down
3 changes: 3 additions & 0 deletions resources/schema/FAQTopic.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"type": "String",
"required": true
},
"comment": {
"type": "String"
},
"meta": {
"type": "Object"
},
Expand Down

0 comments on commit 598c0fc

Please sign in to comment.