Merge pull request 'dev' (#1) from dev into main
Reviewed-on: Giovanni-Josserand/Portfolio-API#1
This commit is contained in:
commit
840de088aa
4 files changed
+113
-2
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
|
||||
from routers import skills, experiences, experienceTasks, projects
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -24,5 +24,20 @@ def read_root():
|
||||
app.include_router(
|
||||
skills.router,
|
||||
prefix="/api/skills",
|
||||
tags=["Skills"]
|
||||
tags=["Skills"],
|
||||
)
|
||||
app.include_router(
|
||||
experiences.router,
|
||||
prefix="/api/experiences",
|
||||
tags=["Experiences"]
|
||||
)
|
||||
app.include_router(
|
||||
experienceTasks.router,
|
||||
prefix="/api/experienceTasks",
|
||||
tags=["ExperienceTasks"]
|
||||
)
|
||||
app.include_router(
|
||||
projects.router,
|
||||
prefix="/api/projects",
|
||||
tags=["Projects"]
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
# routers/skills.py (sans générateur)
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import MySQLdb
|
||||
from database import get_db_connection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_experienceTasks():
|
||||
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 * FROM experience_tasks;"
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
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()
|
||||
@@ -0,0 +1,24 @@
|
||||
# routers/skills.py (sans générateur)
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import MySQLdb
|
||||
from database import get_db_connection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_experiences():
|
||||
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 * FROM experiences;"
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
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()
|
||||
@@ -0,0 +1,48 @@
|
||||
# routers/skills.py (sans générateur)
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import MySQLdb
|
||||
from database import get_db_connection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def read_projects():
|
||||
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.description,
|
||||
p.color,
|
||||
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()
|
||||
Reference in new issue
Block a user