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);
|
|
|
|
|
}
|
|
|
|
|
}
|