Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 11s
- Workspace + KnowledgeFolder Prisma models - Folder CRUD: create/list/update/delete (soft-delete with children) - Content Safety integration for KB title on create/update - E2E: KB create, folder CRUD, admin KB list Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { Controller, Get, Post, Patch, Delete, Body, Param, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
|
import { KnowledgeBaseService } from './knowledge-base.service';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import { PaginationDto } from '../../common/dto/pagination.dto';
|
|
import type { UserPayload } from '../../common/types';
|
|
|
|
@ApiTags('knowledge-base')
|
|
@Controller('knowledge-bases')
|
|
export class KnowledgeBaseController {
|
|
constructor(private readonly service: KnowledgeBaseService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '创建知识库' })
|
|
async create(@CurrentUser() user: UserPayload, @Body() dto: any) {
|
|
return this.service.create(String(user?.id || 'anonymous'), dto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '获取知识库列表' })
|
|
async findAll(@CurrentUser() user: UserPayload, @Query() pagination: PaginationDto) {
|
|
return this.service.findAll(String(user?.id || 'anonymous'), pagination);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '获取知识库详情' })
|
|
async findOne(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
|
return this.service.findOne(String(user?.id || 'anonymous'), id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: '更新知识库' })
|
|
async update(@CurrentUser() user: UserPayload, @Param('id') id: string, @Body() dto: any) {
|
|
return this.service.update(String(user?.id || 'anonymous'), id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除知识库' })
|
|
async remove(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
|
return this.service.remove(String(user?.id || 'anonymous'), id);
|
|
}
|
|
|
|
// ── Folder CRUD ──
|
|
|
|
@Get(':id/folders')
|
|
@ApiOperation({ summary: '获取知识库文件夹列表' })
|
|
async folders(@Param('id') id: string) {
|
|
return this.service.getFolders(id);
|
|
}
|
|
|
|
@Post(':id/folders')
|
|
@ApiOperation({ summary: '创建文件夹' })
|
|
async createFolder(@Param('id') id: string, @Body() dto: { name: string; parentId?: string }) {
|
|
return this.service.createFolder(id, dto);
|
|
}
|
|
|
|
@Patch(':id/folders/:folderId')
|
|
@ApiOperation({ summary: '更新文件夹' })
|
|
async updateFolder(@Param('folderId') folderId: string, @Body() dto: { name?: string; parentId?: string }) {
|
|
return this.service.updateFolder(folderId, dto);
|
|
}
|
|
|
|
@Delete(':id/folders/:folderId')
|
|
@ApiOperation({ summary: '删除文件夹(含子文件夹)' })
|
|
async deleteFolder(@Param('folderId') folderId: string) {
|
|
return this.service.deleteFolder(folderId);
|
|
}
|
|
}
|