- NestJS + TypeScript 后端 API - 用户认证 (auth) - 用户管理 (users) - 学习路径与课程 (learning) - AI 分析与对话 (ai) - 用户反馈 (feedback) - 等待名单 (waitlist) - 知识库 (knowledge) - Swagger API 文档(中文、访问控制) - Basic Auth 保护生产环境文档
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||
import { Controller, Get, Param } from '@nestjs/common';
|
||
|
||
@ApiTags('knowledge')
|
||
@Controller('knowledge')
|
||
export class KnowledgeController {
|
||
@Get('categories')
|
||
@ApiOperation({ summary: '获取知识分类', description: '获取所有知识库分类' })
|
||
@ApiResponse({ status: 200, description: '分类列表' })
|
||
async getCategories() {
|
||
return [
|
||
{ id: 'cat_1', name: '公考申论', icon: '📝', count: 48 },
|
||
{ id: 'cat_2', name: 'AI工具', icon: '🤖', count: 24 },
|
||
{ id: 'cat_3', name: '编程面试', icon: '💻', count: 72 },
|
||
];
|
||
}
|
||
|
||
@Get('articles')
|
||
@ApiOperation({ summary: '获取文章列表', description: '获取知识库文章列表' })
|
||
@ApiResponse({ status: 200, description: '文章列表' })
|
||
async getArticles() {
|
||
return [
|
||
{ id: 'art_1', title: '申论写作基础', category: 'cat_1', excerpt: '了解申论的基本结构和写作要点...' },
|
||
{ id: 'art_2', title: 'ChatGPT 入门指南', category: 'cat_2', excerpt: '快速上手 ChatGPT,提升工作效率...' },
|
||
];
|
||
}
|
||
|
||
@Get('articles/:id')
|
||
@ApiOperation({ summary: '获取文章详情', description: '获取文章详细内容' })
|
||
@ApiResponse({ status: 200, description: '文章详情' })
|
||
@ApiResponse({ status: 404, description: '文章不存在' })
|
||
async getArticle(@Param('id') id: string) {
|
||
return {
|
||
id,
|
||
title: '申论写作基础',
|
||
content: '申论是公务员考试的核心科目...',
|
||
category: '公考申论',
|
||
tags: ['申论', '写作', '备考'],
|
||
createdAt: new Date(),
|
||
};
|
||
}
|
||
} |