Merge pull request 'dev' (#4) from dev into main
Reviewed-on: Giovanni-Josserand/Portfolio-API#4
This commit is contained in:
commit
fa4dbde0b8
3 files changed
+65
-9
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from routers import skills, experiences, experienceTasks, projects
|
||||
from routers import skills, experiences, experienceTasks, shortProjects, longProjects
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -37,7 +37,12 @@ app.include_router(
|
||||
tags=["ExperienceTasks"]
|
||||
)
|
||||
app.include_router(
|
||||
projects.router,
|
||||
prefix="/api/projects",
|
||||
tags=["Projects"]
|
||||
shortProjects.router,
|
||||
prefix="/api/shortProjects",
|
||||
tags=["ShortProjects"]
|
||||
)
|
||||
app.include_router(
|
||||
longProjects.router,
|
||||
prefix="/api/longProjects",
|
||||
tags=["LongProjects"]
|
||||
)
|
||||
@@ -0,0 +1,51 @@
|
||||
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,
|
||||
p.beginning_year,
|
||||
p.end_year,
|
||||
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,10 +17,11 @@ def read_projects():
|
||||
SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
p.description,
|
||||
p.color,
|
||||
p.nb_image,
|
||||
p.short_description,
|
||||
p.school,
|
||||
p.image_name,
|
||||
p.beginning_year,
|
||||
p.end_year,
|
||||
GROUP_CONCAT(DISTINCT s.name ORDER BY s.name SEPARATOR ', ') AS skills
|
||||
FROM
|
||||
projects p
|
||||
Reference in new issue
Block a user