import { Router } from 'express'; import { requireAuth } from '../auth/authMiddleware.js'; import { listOffices, listJurisdictions, listZones, listSections, getSection } from './scatService.js'; const router = Router(); // ============================================================ // GET /api/scat/offices — 관할청 목록 // ============================================================ router.get('/offices', requireAuth, async (_req, res) => { try { const offices = await listOffices(); res.json(offices); } catch (err) { console.error('[scat] 관할청 목록 조회 오류:', err); res.status(500).json({ error: '관할청 목록 조회 중 오류가 발생했습니다.' }); } }); // ============================================================ // GET /api/scat/jurisdictions — 관할서 목록 // ============================================================ router.get('/jurisdictions', requireAuth, async (req, res) => { try { const { officeCd } = req.query as { officeCd?: string }; const jurisdictions = await listJurisdictions(officeCd); res.json(jurisdictions); } catch (err) { console.error('[scat] 관할서 목록 조회 오류:', err); res.status(500).json({ error: '관할서 목록 조회 중 오류가 발생했습니다.' }); } }); // ============================================================ // GET /api/scat/zones — 조사구역 목록 // ============================================================ router.get('/zones', requireAuth, async (req, res) => { try { const { jurisdiction, officeCd } = req.query as { jurisdiction?: string; officeCd?: string }; const zones = await listZones({ jurisdiction, officeCd }); res.json(zones); } catch (err) { console.error('[scat] 조사구역 목록 조회 오류:', err); res.status(500).json({ error: '조사구역 목록 조회 중 오류가 발생했습니다.' }); } }); // ============================================================ // GET /api/scat/sections — 해안구간 목록 (필터링) // ============================================================ router.get('/sections', requireAuth, async (req, res) => { try { const { zone, status, sensitivity, jurisdiction, search, officeCd } = req.query as { zone?: string; status?: string; sensitivity?: string; jurisdiction?: string; search?: string; officeCd?: string; }; const sections = await listSections({ zone, status, sensitivity, jurisdiction, search, officeCd }); res.json(sections); } catch (err) { console.error('[scat] 해안구간 목록 조회 오류:', err); res.status(500).json({ error: '해안구간 목록 조회 중 오류가 발생했습니다.' }); } }); // ============================================================ // GET /api/scat/sections/:sn — 해안구간 상세 // ============================================================ router.get('/sections/:sn', requireAuth, async (req, res) => { try { const sn = parseInt(req.params.sn as string, 10); if (isNaN(sn)) { res.status(400).json({ error: '유효하지 않은 구간 번호입니다.' }); return; } const section = await getSection(sn); if (!section) { res.status(404).json({ error: '해안구간을 찾을 수 없습니다.' }); return; } res.json(section); } catch (err) { console.error('[scat] 해안구간 상세 조회 오류:', err); res.status(500).json({ error: '해안구간 상세 조회 중 오류가 발생했습니다.' }); } }); export default router;