2026-05-09 18:25:04 +08:00
|
|
|
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';
|
2026-05-17 19:08:07 +08:00
|
|
|
import { PaginationDto } from '../../common/dto/pagination.dto';
|
2026-05-09 18:25:04 +08:00
|
|
|
import type { UserPayload } from '../../common/types';
|
|
|
|
|
|
|
|
|
|
@ApiTags('knowledge-base')
|
|
|
|
|
@Controller('knowledge-bases')
|
|
|
|
|
export class KnowledgeBaseController {
|
|
|
|
|
constructor(private readonly service: KnowledgeBaseService) {}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@ApiOperation({ summary: '创建知识库' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async create(@CurrentUser() user: UserPayload, @Body() dto: any) {
|
2026-05-09 18:25:04 +08:00
|
|
|
return this.service.create(String(user?.id || 'anonymous'), dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@ApiOperation({ summary: '获取知识库列表' })
|
2026-05-17 19:08:07 +08:00
|
|
|
async findAll(@CurrentUser() user: UserPayload, @Query() pagination: PaginationDto) {
|
|
|
|
|
return this.service.findAll(String(user?.id || 'anonymous'), pagination);
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
|
|
|
|
@ApiOperation({ summary: '获取知识库详情' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async findOne(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
2026-05-09 18:25:04 +08:00
|
|
|
return this.service.findOne(String(user?.id || 'anonymous'), id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch(':id')
|
|
|
|
|
@ApiOperation({ summary: '更新知识库' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async update(@CurrentUser() user: UserPayload, @Param('id') id: string, @Body() dto: any) {
|
2026-05-09 18:25:04 +08:00
|
|
|
return this.service.update(String(user?.id || 'anonymous'), id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
|
|
|
|
@ApiOperation({ summary: '删除知识库' })
|
2026-05-17 00:39:46 +08:00
|
|
|
async remove(@CurrentUser() user: UserPayload, @Param('id') id: string) {
|
2026-05-09 18:25:04 +08:00
|
|
|
return this.service.remove(String(user?.id || 'anonymous'), id);
|
|
|
|
|
}
|
2026-05-24 11:23:58 +08:00
|
|
|
|
|
|
|
|
// ── 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);
|
|
|
|
|
}
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|