import { Router, type Request, type Response } from 'express'; import { MockDataService } from '../services/mock-data-service'; const router = Router(); // GET /v2/guardrails - List all guardrails router.get('/', (req: Request, res: Response) => { try { const { limit = 100, page = 1 } = req.query; const guardrails = MockDataService.getGuardrails(); // Apply pagination const limitNum = parseInt(limit as string); const pageNum = parseInt(page as string); const offset = (pageNum - 1) * limitNum; const paginatedGuardrails = guardrails.slice(offset, offset + limitNum); const response = { data: paginatedGuardrails, total_count: guardrails.length }; res.json(response); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); // GET /v2/guardrails/:id - Get specific guardrails router.get('/:id', (req: Request, res: Response) => { try { const { id } = req.params; const guardrails = MockDataService.getGuardrails(); const guardrail = guardrails.find(g => g.uuid === id); if (!guardrail) { return res.status(404).json({ error: 'guardrails_not_found', message: `Guardrails with ID ${id} not found`, status_code: 404 }); } res.json(guardrail); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); // POST /v2/guardrails - Create new guardrails router.post('/', (req: Request, res: Response) => { try { const { name, data } = req.body; // Validate required fields if (!name) { return res.status(400).json({ error: 'validation_error', message: 'name is required', status_code: 400 }); } if (!data || !Array.isArray(data)) { return res.status(400).json({ error: 'validation_error', message: 'data must be an array of guardrails', status_code: 400 }); } // Create mock guardrails const guardrail = { uuid: `g${Math.random().toString(36).substr(2, 9)}`, owner_id: 12345, name, data, created_at: new Date().toISOString(), updated_at: new Date().toISOString(), is_deleted: false }; res.status(201).json(guardrail); } catch (_error) { res.status(500).json({ error: 'internal_server_error', message: 'An unexpected error occurred', status_code: 500 }); } }); export default router;