feat(server): 添加节目配置文件管理
- 新增 programs.json 配置文件 - 新增 ProgramConfigService 服务 - 新增节目配置 API 接口 (GET/PUT /api/admin/programs) - 修改 AdminService 使用配置服务替代硬编码 - 添加单元测试
This commit is contained in:
@@ -2,6 +2,7 @@ import { Router, IRouter } from 'express';
|
||||
import multer from 'multer';
|
||||
import { participantService } from '../services/participant.service';
|
||||
import { prizeConfigService } from '../services/prize-config.service';
|
||||
import { programConfigService } from '../services/program-config.service';
|
||||
|
||||
const router: IRouter = Router();
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
@@ -73,6 +74,53 @@ router.put('/prizes', async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/admin/programs
|
||||
* Get program configuration
|
||||
*/
|
||||
router.get('/programs', async (_req, res, next) => {
|
||||
try {
|
||||
const config = programConfigService.getFullConfig();
|
||||
return res.json({
|
||||
success: true,
|
||||
data: config,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT /api/admin/programs
|
||||
* Update program configuration
|
||||
*/
|
||||
router.put('/programs', async (req, res, next) => {
|
||||
try {
|
||||
const { programs, settings } = req.body;
|
||||
|
||||
if (programs) {
|
||||
const result = await programConfigService.updatePrograms(programs);
|
||||
if (!result.success) {
|
||||
return res.status(400).json({ success: false, error: result.error });
|
||||
}
|
||||
}
|
||||
|
||||
if (settings) {
|
||||
const result = await programConfigService.updateSettings(settings);
|
||||
if (!result.success) {
|
||||
return res.status(400).json({ success: false, error: result.error });
|
||||
}
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
data: programConfigService.getFullConfig(),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/admin/draw/start
|
||||
* Start a lucky draw
|
||||
|
||||
Reference in New Issue
Block a user