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
|
import os
|
||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from routers import skills, experiences, experienceTasks, projects
|
from routers import skills, experiences, experienceTasks, shortProjects, longProjects
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -37,7 +37,12 @@ app.include_router(
|
|||||||
tags=["ExperienceTasks"]
|
tags=["ExperienceTasks"]
|
||||||
)
|
)
|
||||||
app.include_router(
|
app.include_router(
|
||||||
projects.router,
|
shortProjects.router,
|
||||||
prefix="/api/projects",
|
prefix="/api/shortProjects",
|
||||||
tags=["Projects"]
|
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
|
from fastapi import APIRouter, HTTPException
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
from database import get_db_connection
|
from database import get_db_connection
|
||||||
@@ -7,7 +6,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
def read_projects():
|
def read_shortProjects():
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
if not conn:
|
if not conn:
|
||||||
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
raise HTTPException(status_code=503, detail="Service de base de données indisponible.")
|
||||||
@@ -18,10 +17,11 @@ def read_projects():
|
|||||||
SELECT
|
SELECT
|
||||||
p.id,
|
p.id,
|
||||||
p.title,
|
p.title,
|
||||||
p.description,
|
p.short_description,
|
||||||
p.color,
|
p.school,
|
||||||
p.nb_image,
|
|
||||||
p.image_name,
|
p.image_name,
|
||||||
|
p.beginning_year,
|
||||||
|
p.end_year,
|
||||||
GROUP_CONCAT(DISTINCT s.name ORDER BY s.name SEPARATOR ', ') AS skills
|
GROUP_CONCAT(DISTINCT s.name ORDER BY s.name SEPARATOR ', ') AS skills
|
||||||
FROM
|
FROM
|
||||||
projects p
|
projects p
|
||||||
Reference in new issue
Block a user