42 lines
1.6 KiB
TypeScript
42 lines
1.6 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 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 | undefined, @Body() dto: any) {
|
||
|
|
return this.service.create(String(user?.id || 'anonymous'), dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get()
|
||
|
|
@ApiOperation({ summary: '获取知识库列表' })
|
||
|
|
async findAll(@CurrentUser() user: UserPayload | undefined, @Query() query: any) {
|
||
|
|
return this.service.findAll(String(user?.id || 'anonymous'), query);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get(':id')
|
||
|
|
@ApiOperation({ summary: '获取知识库详情' })
|
||
|
|
async findOne(@CurrentUser() user: UserPayload | undefined, @Param('id') id: string) {
|
||
|
|
return this.service.findOne(String(user?.id || 'anonymous'), id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Patch(':id')
|
||
|
|
@ApiOperation({ summary: '更新知识库' })
|
||
|
|
async update(@CurrentUser() user: UserPayload | undefined, @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 | undefined, @Param('id') id: string) {
|
||
|
|
return this.service.remove(String(user?.id || 'anonymous'), id);
|
||
|
|
}
|
||
|
|
}
|