From d75a5590ccfba060ca67a258720961722560017f Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Sun, 31 Aug 2025 00:21:39 +0200 Subject: [PATCH] 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