Suppression des modèles et contrôleurs de projet, refonte de la création et suppression de projet dans les routes API
This commit is contained in:
@@ -8,6 +8,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const ffmpeg = require('../ffmpeg'); // Assurez-vous d'importer le fichier ffmpeg.js
|
||||
const file_watcher = require('../file_watcher'); // Assurez-vous d'importer le fichier file_watcher.js
|
||||
const fileUtils = require('../fileUtils');
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -188,7 +189,36 @@ router.get('/projects/:id/measurements', (req, res) => {
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
*/
|
||||
router.post('/projects', projectController.createProject);
|
||||
router.post('/projects', async (req, res) => {
|
||||
const { name, description } = req.body;
|
||||
if (!name || !description) {
|
||||
return res.status(400).json({ error: 'Name and description are required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const query = 'INSERT INTO public.projects (name, description) VALUES ($1, $2) RETURNING id';
|
||||
const result = await db.query(query, [name, description]);
|
||||
const projectId = result.rows[0].id;
|
||||
|
||||
fileUtils.createProjectDirectory(projectId);
|
||||
res.status(201).json({ message: 'Project created successfully', projectId });
|
||||
} catch (error) {
|
||||
console.error('Error creating project:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
const { projectId } = req.body;
|
||||
if (!projectId) {
|
||||
return res.status(400).json({ error: 'Project ID is required' });
|
||||
}
|
||||
|
||||
try {
|
||||
fileUtils.createProjectDirectory(projectId);
|
||||
res.status(201).json({ message: 'Project directory created successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error creating project directory:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -210,7 +240,23 @@ router.post('/projects', projectController.createProject);
|
||||
* 500:
|
||||
* description: Internal server error
|
||||
*/
|
||||
router.delete('/projects/:id', projectController.deleteProject);
|
||||
router.delete('/projects/:id', async (req, res) => {
|
||||
const projectId = req.params.id;
|
||||
const projectDir = path.join(__dirname, `../storage/${projectId}`);
|
||||
|
||||
try {
|
||||
const result = await db.query('DELETE FROM public.projects WHERE id = $1 RETURNING id', [projectId]);
|
||||
if (result.rowCount === 0) {
|
||||
return res.status(404).json({ error: 'No project found with this ID' });
|
||||
}
|
||||
|
||||
fs.rmdirSync(projectDir, { recursive: true });
|
||||
res.status(200).json({ message: 'Project deleted successfully', id: projectId });
|
||||
} catch (error) {
|
||||
console.error('Error deleting project:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
Reference in New Issue
Block a user