Merge pull request 'add of short_description in longProjects.py' (#5) from dev into main
Reviewed-on: Giovanni-Josserand/Portfolio-API#5
This commit is contained in:
commit
5d724e37ab
1 file changed
+16
-14
+16
-14
@@ -4,9 +4,8 @@ from database import get_db_connection
|
|||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/{project_id}")
|
||||||
@router.get("/")
|
def read_long_project(project_id: int):
|
||||||
def read_longProjects():
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
if not conn:
|
if not conn:
|
||||||
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
||||||
@@ -18,8 +17,8 @@ def read_longProjects():
|
|||||||
p.id,
|
p.id,
|
||||||
p.title,
|
p.title,
|
||||||
p.long_description,
|
p.long_description,
|
||||||
|
p.short_description,
|
||||||
p.school,
|
p.school,
|
||||||
p.date,
|
|
||||||
p.repo_link,
|
p.repo_link,
|
||||||
p.nb_image,
|
p.nb_image,
|
||||||
p.image_name,
|
p.image_name,
|
||||||
@@ -32,19 +31,22 @@ def read_longProjects():
|
|||||||
project_skills ps ON p.id = ps.project_id
|
project_skills ps ON p.id = ps.project_id
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
skills s ON ps.skill_id = s.id
|
skills s ON ps.skill_id = s.id
|
||||||
GROUP BY
|
WHERE p.id = %s
|
||||||
p.id;
|
GROUP BY p.id;
|
||||||
"""
|
"""
|
||||||
cursor.execute(sql)
|
cursor.execute(sql, (project_id,))
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
for project in result:
|
if not result:
|
||||||
if project['skills']:
|
raise HTTPException(status_code=404, detail="Projet non trouvé.")
|
||||||
project['skills'] = project['skills'].split(', ')
|
|
||||||
else:
|
if result['skills']:
|
||||||
project['skills'] = []
|
result['skills'] = result['skills'].split(', ')
|
||||||
|
else:
|
||||||
|
result['skills'] = []
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
return {"data": result}
|
|
||||||
except MySQLdb.Error as e:
|
except MySQLdb.Error as e:
|
||||||
raise HTTPException(status_code=500, detail=f"Erreur lors de la requête: {e}")
|
raise HTTPException(status_code=500, detail=f"Erreur lors de la requête: {e}")
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in new issue
Block a user