- 按 BACKEND-PLAN.md 将项目重构为 4 层架构: config/ -> common/ -> infrastructure/ -> modules/ - 15 个业务模块,遵循 Controller → Service → Repository 分层 - infrastructure: PrismaService / RedisService / QueueService / AiService / StorageService - common: guards / interceptors / filters / pipes / decorators / dto / types / utils - Prisma schema 含 27 张表,MySQL 8.0 服务器 db push 成功 - Redis 7 接入: 限流/任务状态/分布式锁/队列预留 - ai-analysis 模块: 每日 50 次限流 + 重复提交锁 + 异步任务状态追踪 - document-import 模块: 异步导入流程 + 进度追踪 - notifications 模块: BullMQ notification 队列预留 - /health 端点实时返回 database + redis 连接状态 - Swagger 注册 15 个 tag,67 个路由全部映射
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
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);
|
|
}
|
|
}
|