- Board: 매뉴얼 CRUD + 첨부파일 API (012_board_ext.sql) - HNS: 분석 CRUD 5개 API (013_hns_analysis.sql) - Prediction: 분석/역추적/오일펜스 7개 API (014_prediction.sql) - Aerial: 미디어/CCTV/위성 6개 API + PostGIS (015_aerial.sql) - Rescue: 구난 작전/시나리오 3개 API + JSONB (016_rescue.sql) - backtrackMockData.ts 삭제 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
128 lines
4.8 KiB
TypeScript
128 lines
4.8 KiB
TypeScript
import express from 'express';
|
|
import {
|
|
listAnalyses, getAnalysisDetail, getBacktrack, listBacktracksByAcdnt,
|
|
createBacktrack, saveBoomLine, listBoomLines,
|
|
} from './predictionService.js';
|
|
import { isValidNumber } from '../middleware/security.js';
|
|
import { requireAuth, requirePermission } from '../auth/authMiddleware.js';
|
|
|
|
const router = express.Router();
|
|
|
|
// GET /api/prediction/analyses — 분석 목록
|
|
router.get('/analyses', requireAuth, requirePermission('prediction', 'READ'), async (req, res) => {
|
|
try {
|
|
const { search } = req.query;
|
|
const items = await listAnalyses({ search: search as string | undefined });
|
|
res.json(items);
|
|
} catch (err) {
|
|
console.error('[prediction] 분석 목록 오류:', err);
|
|
res.status(500).json({ error: '분석 목록 조회 실패' });
|
|
}
|
|
});
|
|
|
|
// GET /api/prediction/analyses/:acdntSn — 분석 상세
|
|
router.get('/analyses/:acdntSn', requireAuth, requirePermission('prediction', 'READ'), async (req, res) => {
|
|
try {
|
|
const acdntSn = parseInt(req.params.acdntSn as string, 10);
|
|
if (!isValidNumber(acdntSn, 1, 999999)) {
|
|
res.status(400).json({ error: '유효하지 않은 사고 번호' });
|
|
return;
|
|
}
|
|
const detail = await getAnalysisDetail(acdntSn);
|
|
if (!detail) {
|
|
res.status(404).json({ error: '분석을 찾을 수 없습니다' });
|
|
return;
|
|
}
|
|
res.json(detail);
|
|
} catch (err) {
|
|
console.error('[prediction] 분석 상세 오류:', err);
|
|
res.status(500).json({ error: '분석 상세 조회 실패' });
|
|
}
|
|
});
|
|
|
|
// GET /api/prediction/backtrack — 사고별 역추적 목록
|
|
router.get('/backtrack', requireAuth, requirePermission('prediction', 'READ'), async (req, res) => {
|
|
try {
|
|
const acdntSn = parseInt(req.query.acdntSn as string, 10);
|
|
if (!isValidNumber(acdntSn, 1, 999999)) {
|
|
res.status(400).json({ error: '유효하지 않은 사고 번호' });
|
|
return;
|
|
}
|
|
const items = await listBacktracksByAcdnt(acdntSn);
|
|
res.json(items);
|
|
} catch (err) {
|
|
console.error('[prediction] 역추적 목록 오류:', err);
|
|
res.status(500).json({ error: '역추적 목록 조회 실패' });
|
|
}
|
|
});
|
|
|
|
// GET /api/prediction/backtrack/:sn — 역추적 상세
|
|
router.get('/backtrack/:sn', requireAuth, requirePermission('prediction', 'READ'), async (req, res) => {
|
|
try {
|
|
const sn = parseInt(req.params.sn as string, 10);
|
|
if (!isValidNumber(sn, 1, 999999)) {
|
|
res.status(400).json({ error: '유효하지 않은 역추적 번호' });
|
|
return;
|
|
}
|
|
const item = await getBacktrack(sn);
|
|
if (!item) {
|
|
res.status(404).json({ error: '역추적 결과를 찾을 수 없습니다' });
|
|
return;
|
|
}
|
|
res.json(item);
|
|
} catch (err) {
|
|
console.error('[prediction] 역추적 상세 오류:', err);
|
|
res.status(500).json({ error: '역추적 조회 실패' });
|
|
}
|
|
});
|
|
|
|
// POST /api/prediction/backtrack — 역추적 생성
|
|
router.post('/backtrack', requireAuth, requirePermission('prediction', 'CREATE'), async (req, res) => {
|
|
try {
|
|
const { acdntSn, lat, lon, estSpilDtm, anlysRange, srchRadiusNm } = req.body;
|
|
if (!acdntSn || !lat || !lon) {
|
|
res.status(400).json({ error: '사고번호, 위도, 경도는 필수입니다' });
|
|
return;
|
|
}
|
|
const result = await createBacktrack({ acdntSn, lat, lon, estSpilDtm, anlysRange, srchRadiusNm });
|
|
res.status(201).json(result);
|
|
} catch (err) {
|
|
console.error('[prediction] 역추적 생성 오류:', err);
|
|
res.status(500).json({ error: '역추적 생성 실패' });
|
|
}
|
|
});
|
|
|
|
// GET /api/prediction/boom/:acdntSn — 오일펜스 목록
|
|
router.get('/boom/:acdntSn', requireAuth, requirePermission('prediction', 'READ'), async (req, res) => {
|
|
try {
|
|
const acdntSn = parseInt(req.params.acdntSn as string, 10);
|
|
if (!isValidNumber(acdntSn, 1, 999999)) {
|
|
res.status(400).json({ error: '유효하지 않은 사고 번호' });
|
|
return;
|
|
}
|
|
const items = await listBoomLines(acdntSn);
|
|
res.json(items);
|
|
} catch (err) {
|
|
console.error('[prediction] 오일펜스 목록 오류:', err);
|
|
res.status(500).json({ error: '오일펜스 목록 조회 실패' });
|
|
}
|
|
});
|
|
|
|
// POST /api/prediction/boom — 오일펜스 저장
|
|
router.post('/boom', requireAuth, requirePermission('prediction', 'CREATE'), async (req, res) => {
|
|
try {
|
|
const { acdntSn, boomNm, priorityOrd, geojson, lengthM, efficiencyPct } = req.body;
|
|
if (!acdntSn || !boomNm || !geojson) {
|
|
res.status(400).json({ error: '사고번호, 이름, GeoJSON은 필수입니다' });
|
|
return;
|
|
}
|
|
const result = await saveBoomLine({ acdntSn, boomNm, priorityOrd, geojson, lengthM, efficiencyPct });
|
|
res.status(201).json(result);
|
|
} catch (err) {
|
|
console.error('[prediction] 오일펜스 저장 오류:', err);
|
|
res.status(500).json({ error: '오일펜스 저장 실패' });
|
|
}
|
|
});
|
|
|
|
export default router;
|