Spaces:
Sleeping
Sleeping
Update src/services/cv_router.py
Browse files
src/services/cv_router.py
CHANGED
|
@@ -23,16 +23,17 @@ class CVResponse(BaseModel):
|
|
| 23 |
|
| 24 |
class Config:
|
| 25 |
populate_by_name = True
|
| 26 |
-
json_encoders = {ObjectId: str}
|
| 27 |
from_attributes = True
|
| 28 |
|
| 29 |
@router.post("/cvs", response_model=CVResponse)
|
| 30 |
async def create_cv(cv: CVCreate, db: AsyncIOMotorDatabase = Depends(lambda: mongo_db)):
|
| 31 |
-
cv_entry =
|
| 32 |
-
cv_id = await CVModel.create(db, CVModel.collection_name, cv_entry
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
@router.get("/cvs/{cv_id}", response_model=CVResponse)
|
| 38 |
async def get_cv_by_id(cv_id: str, db: AsyncIOMotorDatabase = Depends(lambda: mongo_db)):
|
|
@@ -43,5 +44,6 @@ async def get_cv_by_id(cv_id: str, db: AsyncIOMotorDatabase = Depends(lambda: mo
|
|
| 43 |
if cv is None:
|
| 44 |
raise HTTPException(status_code=404, detail="CV not found")
|
| 45 |
|
| 46 |
-
# MODIFICATION :
|
|
|
|
| 47 |
return CVResponse(**cv)
|
|
|
|
| 23 |
|
| 24 |
class Config:
|
| 25 |
populate_by_name = True
|
| 26 |
+
json_encoders = {ObjectId: str}
|
| 27 |
from_attributes = True
|
| 28 |
|
| 29 |
@router.post("/cvs", response_model=CVResponse)
|
| 30 |
async def create_cv(cv: CVCreate, db: AsyncIOMotorDatabase = Depends(lambda: mongo_db)):
|
| 31 |
+
cv_entry = cv.model_dump(by_alias=True, exclude_unset=True)
|
| 32 |
+
cv_id = await CVModel.create(db, CVModel.collection_name, cv_entry)
|
| 33 |
+
|
| 34 |
+
# MODIFICATION : Retourne directement l'objet Pydantic pour sérialisation
|
| 35 |
+
cv_entry['id'] = cv_id
|
| 36 |
+
return CVResponse(**cv_entry)
|
| 37 |
|
| 38 |
@router.get("/cvs/{cv_id}", response_model=CVResponse)
|
| 39 |
async def get_cv_by_id(cv_id: str, db: AsyncIOMotorDatabase = Depends(lambda: mongo_db)):
|
|
|
|
| 44 |
if cv is None:
|
| 45 |
raise HTTPException(status_code=404, detail="CV not found")
|
| 46 |
|
| 47 |
+
# MODIFICATION : Convertit explicitement l'ObjectId en str avant de retourner l'objet
|
| 48 |
+
cv['id'] = str(cv['_id'])
|
| 49 |
return CVResponse(**cv)
|