const express = require('express'); const router = express.Router(); const { getConfigurations, getConfigurationById, createConfiguration, updateConfiguration, deleteConfiguration } = require('../utils/configuration-utils'); // 获取所有配置列表 router.get('/configurations', (req, res) => { try { const planeName = req.query.plane; const configs = getConfigurations(planeName); res.json(configs); } catch (error) { console.error('获取配置列表失败:', error); res.status(500).json({ error: '获取配置列表失败', details: error.message }); } }); // 根据ID获取配置 router.get('/configurations/:id', (req, res) => { try { const config = getConfigurationById(req.params.id); if (!config) { return res.status(404).json({ error: '配置不存在' }); } res.json(config); } catch (error) { console.error('获取配置详情失败:', error); res.status(500).json({ error: '获取配置详情失败', details: error.message }); } }); // 创建新配置 router.post('/configurations', (req, res) => { try { const result = createConfiguration(req.body); res.status(201).json(result); } catch (error) { console.error('创建配置失败:', error); res.status(500).json({ error: '创建配置失败', details: error.message }); } }); // 更新配置 router.put('/configurations/:id', (req, res) => { try { const configData = { ...req.body, ConfID: req.params.id }; const result = updateConfiguration(configData); res.json(result); } catch (error) { console.error('更新配置失败:', error); res.status(500).json({ error: '更新配置失败', details: error.message }); } }); // 删除配置 router.delete('/configurations/:id', (req, res) => { try { const result = deleteConfiguration(req.params.id); res.json(result); } catch (error) { console.error('删除配置失败:', error); res.status(500).json({ error: '删除配置失败', details: error.message }); } }); module.exports = router;