fix skills router
This commit is contained in:
1 parent
4e14592fdb
commit
9a74817a08
3 files changed
+22
-24
No files matched your search
+21
@@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
import MySQLdb
|
||||||
|
from fastapi import HTTPException
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
def get_db_connection():
|
||||||
|
try:
|
||||||
|
conn = MySQLdb.connect(
|
||||||
|
user=os.getenv("DB_USER"),
|
||||||
|
passwd=os.getenv("DB_PASS"),
|
||||||
|
host=os.getenv("DB_HOST"),
|
||||||
|
db=os.getenv("DB_NAME"),
|
||||||
|
charset='utf8mb4',
|
||||||
|
cursorclass=MySQLdb.cursors.DictCursor
|
||||||
|
)
|
||||||
|
return conn
|
||||||
|
except MySQLdb.Error as e:
|
||||||
|
print(f"Erreur de connexion à la base de données : {e}")
|
||||||
|
raise HTTPException(status_code=500, detail="Erreur interne du serveur lors de la connexion à la base de données.")
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
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
|
||||||
import MySQLdb
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
from routers import skills
|
from routers import skills
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
origins = [
|
origins = [
|
||||||
@@ -21,29 +17,10 @@ app.add_middleware(
|
|||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_db_connection():
|
|
||||||
try:
|
|
||||||
conn = MySQLdb.connect(
|
|
||||||
user=os.getenv("DB_USER"),
|
|
||||||
passwd=os.getenv("DB_PASS"),
|
|
||||||
host=os.getenv("DB_HOST"),
|
|
||||||
db=os.getenv("DB_NAME"),
|
|
||||||
charset='utf8mb4',
|
|
||||||
cursorclass=MySQLdb.cursors.DictCursor
|
|
||||||
)
|
|
||||||
return conn
|
|
||||||
except MySQLdb.Error as e:
|
|
||||||
print(f"Erreur de connexion à la base de données : {e}")
|
|
||||||
raise HTTPException(status_code=500, detail="Erreur interne du serveur lors de la connexion à la base de données.")
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def read_root():
|
def read_root():
|
||||||
return {"status": "API Portfolio fonctionnelle !"}
|
return {"status": "API Portfolio fonctionnelle !"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.include_router(
|
app.include_router(
|
||||||
skills.router,
|
skills.router,
|
||||||
prefix="/api/skills",
|
prefix="/api/skills",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
from ..main import get_db_connection
|
from ..database import get_db_connection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user