add of short_description in longProjects.py
This commit is contained in:
1 parent
15dce53e86
commit
510eb13d8c
1 file changed
+17
-15
+17
-15
@@ -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()
|
||||
conn.close()
|
||||
Reference in new issue
Block a user