import { Controller, Get, Post, Patch, Body, Param, Query } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; import { KnowledgeItemsService } from './knowledge-items.service'; import { CurrentUser } from '../../common/decorators/current-user.decorator'; import type { UserPayload } from '../../common/types'; @ApiTags('knowledge-items') @Controller('knowledge-items') export class KnowledgeItemsController { constructor(private readonly service: KnowledgeItemsService) {} @Post() @ApiOperation({ summary: '创建知识点' }) async create(@CurrentUser() user: UserPayload | undefined, @Body() body: any) { return this.service.create(String(user?.id || 'anonymous'), body.knowledgeBaseId, body); } @Get(':id') @ApiOperation({ summary: '获取知识点详情' }) async findOne(@Param('id') id: string) { return this.service.findById(id); } @Get() @ApiOperation({ summary: '获取知识库下的知识点列表' }) async findByKnowledgeBase(@Query('knowledgeBaseId') knowledgeBaseId: string) { return this.service.findByKnowledgeBaseId(knowledgeBaseId); } @Patch(':id') @ApiOperation({ summary: '更新知识点' }) async update(@Param('id') id: string, @Body() body: any) { return this.service.update(id, body); } }