parent
634077c7e9
commit
acb2e42f98
@ -1,24 +1,50 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const randomSelect = require('./services/randomSelect');
|
const randomSelect = require('./services/randomSelect');
|
||||||
const ranking = require('./services/ranking');
|
const ranking = require('./services/ranking');
|
||||||
const classManager = require('./services/classManager');
|
const classManager = require('./services/classManager');
|
||||||
const scoreManager = require('./services/scoreManager');
|
const scoreManager = require('./services/scoreManager');
|
||||||
|
const TableManager = require('./services/delete-table');
|
||||||
// 文件上传配置
|
const pool = require('./db');
|
||||||
const upload = multer({ dest: 'uploads/' });
|
// 文件上传配置
|
||||||
|
const upload = multer({ dest: 'uploads/' });
|
||||||
// 路由 - 添加班级
|
|
||||||
router.post('/upload', upload.single('file'), classManager.addClass);
|
// 路由 - 添加班级
|
||||||
|
router.post('/upload', upload.single('file'), classManager.addClass);
|
||||||
// 路由 - 随机点名
|
|
||||||
router.get('/random-call', randomSelect.selectStudent);
|
// 路由 - 随机点名
|
||||||
|
router.get('/random-call', randomSelect.selectStudent);
|
||||||
// 路由 - 获取排名
|
|
||||||
router.get('/ranking', ranking.getRanking);
|
// 路由 - 获取排名
|
||||||
|
router.get('/ascend_ranking', ranking.get_ascend_Ranking);
|
||||||
// 路由 - 更新分数
|
router.get('/descend_ranking', ranking.get_descend_Ranking);
|
||||||
router.post('/update-score', scoreManager.updateScore);
|
|
||||||
|
// 路由 - 更新分数
|
||||||
module.exports = router;
|
router.post('/update-score', scoreManager.updateScore);
|
||||||
|
|
||||||
|
//路由 - 获取某个id的分数
|
||||||
|
router.post('/get-score', scoreManager.getStudentScore);
|
||||||
|
|
||||||
|
//路由 - 删除班级
|
||||||
|
router.post('/delete-table', TableManager.deleteTable);
|
||||||
|
|
||||||
|
|
||||||
|
// 获取全部学生名单
|
||||||
|
router.get('/get-students', async (req, res) => {
|
||||||
|
let connection; // 声明连接变量
|
||||||
|
try {
|
||||||
|
connection = await pool.getConnection(); // 从连接池获取连接
|
||||||
|
const [students] = await connection.query('SELECT student_name FROM students'); // 执行查询
|
||||||
|
const studentNames = students.map(student => ({ student_name: student.student_name })); // 只保留 student_name 字段
|
||||||
|
res.json(studentNames); // 返回只包含 student_name 的结果
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching students:', error); // 记录错误信息
|
||||||
|
res.status(500).send({ error: 'Failed to fetch students' }); // 返回500错误响应
|
||||||
|
} finally {
|
||||||
|
if (connection) connection.release(); // 确保连接被释放
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
Loading…
Reference in new issue