From 510eb13d8ca5aaede0653b7506b162881bd368db Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sun, 14 Sep 2025 12:39:39 +0200 Subject: [PATCH] add of short_description in longProjects.py --- routers/longProjects.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/routers/longProjects.py b/routers/longProjects.py index 80bb5d7..718f271 100644 --- a/routers/longProjects.py +++ b/routers/longProjects.py @@ -4,9 +4,8 @@ from database import get_db_connection router = APIRouter() - -@router.get("/") -def read_longProjects(): +@router.get("/{project_id}") +def read_long_project(project_id: int): conn = get_db_connection() if not conn: raise HTTPException(status_code=503, detail="Service de base de données indisponible.") @@ -18,8 +17,8 @@ def read_longProjects(): p.id, p.title, p.long_description, + p.short_description, p.school, - p.date, p.repo_link, p.nb_image, p.image_name, @@ -32,20 +31,23 @@ def read_longProjects(): project_skills ps ON p.id = ps.project_id LEFT JOIN skills s ON ps.skill_id = s.id - GROUP BY - p.id; + WHERE p.id = %s + GROUP BY p.id; """ - cursor.execute(sql) - result = cursor.fetchall() + cursor.execute(sql, (project_id,)) + result = cursor.fetchone() - for project in result: - if project['skills']: - project['skills'] = project['skills'].split(', ') - else: - project['skills'] = [] + if not result: + raise HTTPException(status_code=404, detail="Projet non trouvé.") + + if result['skills']: + result['skills'] = result['skills'].split(', ') + else: + result['skills'] = [] + + return result - return {"data": result} except MySQLdb.Error as e: raise HTTPException(status_code=500, detail=f"Erreur lors de la requête: {e}") finally: - conn.close() \ No newline at end of file + conn.close()