feat(status): Refactor project and video status management with centralized configuration and update related controllers and routes
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 9s
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 9s
This commit is contained in:
@@ -153,12 +153,18 @@ module.exports = {
|
||||
samples: path.join(process.cwd(), 'sample')
|
||||
},
|
||||
|
||||
// Statuts pour les projets et vidéos
|
||||
status: {
|
||||
waiting: 0,
|
||||
// Statuts pour les projets
|
||||
projectStatus: {
|
||||
brouillon: 0,
|
||||
capturing: 1,
|
||||
idle: 2,
|
||||
},
|
||||
|
||||
// Statuts pour les vidéos
|
||||
videoStatus: {
|
||||
rendering: 0,
|
||||
completed: 1,
|
||||
failed: 2,
|
||||
inProgress: 3
|
||||
error: 2
|
||||
},
|
||||
|
||||
// Paramètres par défaut pour la caméra
|
||||
|
||||
@@ -56,7 +56,7 @@ class CameraController {
|
||||
await Camera.updateCamera(1, newSettings);
|
||||
|
||||
// Met à jour le statut du projet
|
||||
await Project.updateProject(project_id, { status: config.status.inProgress });
|
||||
await Project.updateProject(project_id, { status: config.projectStatus.capturing });
|
||||
|
||||
console.log(`[CAMERA] Procédure démarrée pour le projet : ${project_id}`);
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class ProjectController {
|
||||
}
|
||||
|
||||
const date = new Date();
|
||||
const defaultStatus = config.status.waiting;
|
||||
const defaultStatus = config.projectStatus.brouillon;
|
||||
|
||||
const project = await Project.createProject(name, description, date, defaultStatus);
|
||||
await StorageService.project.createProjectDirectory(project.id);
|
||||
|
||||
@@ -156,7 +156,7 @@ class VideoController {
|
||||
return sendError('Vidéo non trouvée', res, null, 404);
|
||||
}
|
||||
|
||||
if (video.status === config.status.waiting || video.status === config.status.inProgress) {
|
||||
if (video.status === config.videoStatus.rendering || video.status === config.videoStatus.rendering) {
|
||||
return sendError('Vidéo pas encore produite', res, null, 400);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,18 @@ class Project {
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
|
||||
/**
|
||||
* Met à jour le statut d'un projet
|
||||
* @param {number} id - ID du projet
|
||||
* @param {number} status - Nouveau statut du projet
|
||||
* @returns {Promise<Object|null>} Projet mis à jour ou null si non trouvé
|
||||
*/
|
||||
static updateProjectStatus = wrapDatabaseOperation(async (id, status) => {
|
||||
const query = `UPDATE projects SET status = $1 WHERE id = $2 RETURNING *;`;
|
||||
const result = await db.query(query, [status, id]);
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
|
||||
/**
|
||||
* Supprime un projet par son ID
|
||||
* @param {number} id - ID du projet
|
||||
@@ -70,11 +82,11 @@ class Project {
|
||||
});
|
||||
|
||||
/**
|
||||
* Trouve le projet en cours de rendu (status = 1)
|
||||
* Trouve le projet en cours de rendu (status = capturing)
|
||||
* @returns {Promise<Object|null>} Projet en cours de rendu ou null
|
||||
*/
|
||||
static findCurrentRenderingProject = wrapDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM projects WHERE status = ${config.status.inProgress};`;
|
||||
const query = `SELECT * FROM projects WHERE status = ${config.projectStatus.capturing};`;
|
||||
const result = await db.query(query);
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ class Video {
|
||||
* @returns {Promise<Object>} Vidéo créée
|
||||
*/
|
||||
static createVideo = wrapDatabaseOperation(async (
|
||||
projectId, measurementIds, name, resolution, duration, status = config.status.waiting
|
||||
projectId, measurementIds, name, resolution, duration, status = config.videoStatus.rendering
|
||||
) => {
|
||||
const query = `
|
||||
INSERT INTO videos (project_id, measurement_ids, name, resolution, duration, status)
|
||||
@@ -87,6 +87,18 @@ class Video {
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
|
||||
/**
|
||||
* Met à jour le statut d'une vidéo
|
||||
* @param {number} id - ID de la vidéo
|
||||
* @param {number} status - Nouveau statut de la vidéo
|
||||
* @returns {Promise<Object|null>} Vidéo mise à jour ou null si non trouvée
|
||||
*/
|
||||
static async updateVideoStatus(id, status) {
|
||||
const query = `UPDATE videos SET status = $1 WHERE id = $2 RETURNING *;`;
|
||||
const result = await db.query(query, [status, id]);
|
||||
return result.rows[0] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une vidéo par son ID
|
||||
* @param {number} id - ID de la vidéo
|
||||
|
||||
@@ -145,6 +145,9 @@ router.get('/projects/:id/measurements', ProjectController.getProjectMeasurement
|
||||
* description:
|
||||
* type: string
|
||||
* description: Description détaillée du projet
|
||||
* status:
|
||||
* type: integer
|
||||
* description: Statut du projet (0: new, 1: configured, 2: capturing, 3: paused, 4: completed, 5: active_with_videos)
|
||||
* required:
|
||||
* - name
|
||||
* - description
|
||||
|
||||
@@ -223,6 +223,9 @@ router.get('/videos/file/:video_id', VideoController.getVideoFile);
|
||||
* type: string
|
||||
* description: État actuel du rendu
|
||||
* example: En cours
|
||||
* status:
|
||||
* type: integer
|
||||
* description: Statut de la vidéo (0: waiting, 1: in_progress, 2: completed, 3: failed)
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 500:
|
||||
|
||||
Reference in New Issue
Block a user