add of longProjects and update of projects table
This commit is contained in:
1 parent
2c68620c66
commit
0d2e1374ed
3 files changed
+60
-7
No files matched your search
@@ -0,0 +1,49 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import MySQLdb
|
||||
from database import get_db_connection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_longProjects():
|
||||
conn = get_db_connection()
|
||||
if not conn:
|
||||
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
||||
|
||||
try:
|
||||
with conn.cursor(MySQLdb.cursors.DictCursor) as cursor:
|
||||
sql = """
|
||||
SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
p.long_description,
|
||||
p.school,
|
||||
p.date,
|
||||
p.repo_link,
|
||||
p.nb_image,
|
||||
p.image_name,
|
||||
GROUP_CONCAT(DISTINCT s.name ORDER BY s.name SEPARATOR ', ') AS skills
|
||||
FROM
|
||||
projects p
|
||||
LEFT JOIN
|
||||
project_skills ps ON p.id = ps.project_id
|
||||
LEFT JOIN
|
||||
skills s ON ps.skill_id = s.id
|
||||
GROUP BY
|
||||
p.id;
|
||||
"""
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
|
||||
for project in result:
|
||||
if project['skills']:
|
||||
project['skills'] = project['skills'].split(', ')
|
||||
else:
|
||||
project['skills'] = []
|
||||
|
||||
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()
|
||||
@@ -1,4 +1,3 @@
|
||||
# routers/skills.py (sans générateur)
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import MySQLdb
|
||||
from database import get_db_connection
|
||||
@@ -7,7 +6,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_projects():
|
||||
def read_shortProjects():
|
||||
conn = get_db_connection()
|
||||
if not conn:
|
||||
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
||||
@@ -18,7 +17,7 @@ def read_projects():
|
||||
SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
p.description,
|
||||
p.short_description,
|
||||
p.school,
|
||||
p.nb_image,
|
||||
p.image_name,
|
||||
Reference in new issue
Block a user