diff --git a/routes/api.js b/routes/api.js index 399d25b..71c2834 100644 --- a/routes/api.js +++ b/routes/api.js @@ -94,13 +94,13 @@ router.get('/projects/:id', async (req, res) => { return res.status(400).json({ error: 'Invalid project ID' }); } try { - const project = await projectModel.getProjectById(db, projectId); - if (!project) { - return res.status(404).json({ error: 'Projet non trouvé' }); + const project = await db.query('SELECT * FROM public.projects WHERE id = $1', [projectId]); + if (project.rows.length === 0) { + return res.status(404).json({ error: 'Project not found' }); } - res.json(project); + res.json(project.rows[0]); } catch (error) { - serverError.sendError('Erreur lors de la récupération du projet:', res, error); + serverError.sendError('Error getting project:', res, error); } }); @@ -542,4 +542,27 @@ router.get('/smile', (req, res) => { }); }); +/** + * @swagger + * /image/{filename}: + * get: + * description: Use to request a specific image by filename + * responses: + * 200: + * description : A successful response + * 404: + * description: Image not found + * + */ +router.get('/image/:filename', (req, res) => { + const imagePath = path.join('/storage/image', req.params.filename); + fs.access(imagePath, fs.constants.F_OK, (err) => { + if (err) { + console.error('Image not found:', err); + return res.status(404).json({ error: 'Image not found' }); + } + res.sendFile(imagePath); + }); +}); + module.exports = router;