Mise à jour de la récupération des projets avec une requête SQL et ajout d'une route pour servir des images par nom de fichier
This commit is contained in:
@@ -94,13 +94,13 @@ router.get('/projects/:id', async (req, res) => {
|
|||||||
return res.status(400).json({ error: 'Invalid project ID' });
|
return res.status(400).json({ error: 'Invalid project ID' });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const project = await projectModel.getProjectById(db, projectId);
|
const project = await db.query('SELECT * FROM public.projects WHERE id = $1', [projectId]);
|
||||||
if (!project) {
|
if (project.rows.length === 0) {
|
||||||
return res.status(404).json({ error: 'Projet non trouvé' });
|
return res.status(404).json({ error: 'Project not found' });
|
||||||
}
|
}
|
||||||
res.json(project);
|
res.json(project.rows[0]);
|
||||||
} catch (error) {
|
} 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;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user