const express = require('express'); const router = express.Router(); const SiteModel = require('../models/SiteModel'); const siteModel = new SiteModel(); /** * GET sites listing. * * Returns a list of all sites in JSON format. */ router.get('/', async function(req, res, next) { const sites = await siteModel.getAll(); res.json(sites); }); /** * GET site by ID. * * Returns a specific site by its ID in JSON format. */ router.get('/:id', async function(req, res, next) { const siteId = req.params.id; const site = await siteModel.getById(siteId); if (!site) { return res.status(404).send('Site not found'); } else { res.json(site); } }); /** * POST create a new site. * * Creates a new site with the provided domain name. * * // TODO: Implement validation for domain name format * // TODO: Implement error handling for duplicate domains * // TODO: Ability to add additional site properties (e.g., name, description) */ router.post('/add/:domain', function(req, res, next) { const domain = req.params.domain; const newSite = siteModel.insert(domain); if (!newSite) { return res.status(400).send('Error creating site'); } else { res.status(201).json(newSite); } }); /** * PUT update an existing site. * * Updates an existing site with the provided ID and new data. */ // TODO: Implement update functionality /** * DELETE remove a site by ID. */ // TODO: Implement delete functionality module.exports = router;