|
1 | 1 | const router = require('express').Router(); |
2 | 2 | const { queryOne } = require('../config/db'); |
3 | | -const { listProblems, getProblem, createProblem, updateProblem, deleteProblem, getProblemStats, getAdminStats, getTagsCloud } = require('../controllers/problemController'); |
| 3 | +const { listProblems, getProblem, createProblem, updateProblem, deleteProblem, getProblemStats, getAdminStats, getTagsCloud, exportProblems, importProblems } = require('../controllers/problemController'); |
4 | 4 | const { getTemplate } = require('../services/judgeService'); |
5 | 5 | const { optionalAuth, adminOnly } = require('../middleware/auth'); |
6 | 6 |
|
@@ -40,9 +40,45 @@ router.get('/random', (req, res) => { |
40 | 40 | res.json({ problem }); |
41 | 41 | }); |
42 | 42 | router.get('/admin/stats', adminOnly, getAdminStats); |
| 43 | +router.get('/export', adminOnly, exportProblems); |
| 44 | +router.post('/import', adminOnly, importProblems); |
43 | 45 | router.get('/:id', optionalAuth, getProblem); |
44 | 46 | router.post('/', adminOnly, createProblem); |
45 | 47 | router.put('/:id', adminOnly, updateProblem); |
46 | 48 | router.delete('/:id', adminOnly, deleteProblem); |
47 | 49 |
|
| 50 | +router.get('/docs', (req, res) => { |
| 51 | + res.json({ |
| 52 | + name: 'CodeJudge API', |
| 53 | + version: '1.0', |
| 54 | + baseUrl: '/api', |
| 55 | + endpoints: [ |
| 56 | + { method: 'POST', path: '/auth/register', auth: false, desc: '用户注册' }, |
| 57 | + { method: 'POST', path: '/auth/login', auth: false, desc: '用户登录' }, |
| 58 | + { method: 'GET', path: '/auth/profile', auth: true, desc: '获取用户信息' }, |
| 59 | + { method: 'PUT', path: '/auth/password', auth: true, desc: '修改密码' }, |
| 60 | + { method: 'GET', path: '/auth/leaderboard', auth: false, desc: '排行榜' }, |
| 61 | + { method: 'GET', path: '/auth/streak', auth: true, desc: '打卡连续天数' }, |
| 62 | + { method: 'GET', path: '/auth/solved-calendar', auth: true, desc: '解题日历' }, |
| 63 | + { method: 'GET', path: '/problems', auth: false, desc: '题目列表' }, |
| 64 | + { method: 'GET', path: '/problems/stats', auth: false, desc: '题目统计' }, |
| 65 | + { method: 'GET', path: '/problems/tags', auth: false, desc: '标签云' }, |
| 66 | + { method: 'GET', path: '/problems/daily', auth: false, desc: '每日一题' }, |
| 67 | + { method: 'GET', path: '/problems/random', auth: false, desc: '随机一题' }, |
| 68 | + { method: 'GET', path: '/problems/export', auth: 'admin', desc: '导出题目' }, |
| 69 | + { method: 'POST', path: '/problems/import', auth: 'admin', desc: '导入题目' }, |
| 70 | + { method: 'GET', path: '/problems/admin/stats', auth: 'admin', desc: '管理统计' }, |
| 71 | + { method: 'GET', path: '/problems/templates/:lang', auth: false, desc: '代码模板' }, |
| 72 | + { method: 'GET', path: '/problems/:id', auth: false, desc: '题目详情' }, |
| 73 | + { method: 'POST', path: '/problems', auth: 'admin', desc: '创建题目' }, |
| 74 | + { method: 'PUT', path: '/problems/:id', auth: 'admin', desc: '更新题目' }, |
| 75 | + { method: 'DELETE', path: '/problems/:id', auth: 'admin', desc: '删除题目' }, |
| 76 | + { method: 'POST', path: '/submissions', auth: true, desc: '提交答案' }, |
| 77 | + { method: 'GET', path: '/submissions', auth: true, desc: '提交记录' }, |
| 78 | + { method: 'GET', path: '/submissions/:id', auth: true, desc: '提交详情' }, |
| 79 | + { method: 'GET', path: '/health', auth: false, desc: '健康检查' }, |
| 80 | + ], |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
48 | 84 | module.exports = router; |
0 commit comments