From d75a5590ccfba060ca67a258720961722560017f Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sun, 31 Aug 2025 00:21:39 +0200 Subject: [PATCH 1/2] add of experiences router and experienceTasks router --- main.py | 14 ++++++++++++-- routers/experienceTasks.py | 24 ++++++++++++++++++++++++ routers/experiences.py | 24 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 routers/experienceTasks.py create mode 100644 routers/experiences.py diff --git a/main.py b/main.py index e800499..d228b7b 100644 --- a/main.py +++ b/main.py @@ -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 app = FastAPI() @@ -24,5 +24,15 @@ 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"] ) \ No newline at end of file diff --git a/routers/experienceTasks.py b/routers/experienceTasks.py new file mode 100644 index 0000000..716d8cd --- /dev/null +++ b/routers/experienceTasks.py @@ -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() \ No newline at end of file diff --git a/routers/experiences.py b/routers/experiences.py new file mode 100644 index 0000000..551cb27 --- /dev/null +++ b/routers/experiences.py @@ -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() \ No newline at end of file From 900a17eac5e40597df33bc8e07e8edcf9e1e28fd Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sun, 31 Aug 2025 18:22:58 +0200 Subject: [PATCH 2/2] add of projects router --- main.py | 7 ++++++- routers/projects.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 routers/projects.py diff --git a/main.py b/main.py index d228b7b..d200679 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import os from fastapi import FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware -from routers import skills, experiences, experienceTasks +from routers import skills, experiences, experienceTasks, projects app = FastAPI() @@ -35,4 +35,9 @@ app.include_router( experienceTasks.router, prefix="/api/experienceTasks", tags=["ExperienceTasks"] +) +app.include_router( + projects.router, + prefix="/api/projects", + tags=["Projects"] ) \ No newline at end of file diff --git a/routers/projects.py b/routers/projects.py new file mode 100644 index 0000000..00c7d05 --- /dev/null +++ b/routers/projects.py @@ -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() \ No newline at end of file