QuentinL52 commited on
Commit
237ed98
·
verified ·
1 Parent(s): d6461d3

Update src/services/cv_router.py

Browse files
Files changed (1) hide show
  1. src/services/cv_router.py +4 -0
src/services/cv_router.py CHANGED
@@ -30,6 +30,7 @@ class CVResponse(BaseModel):
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
  cv_entry['id'] = cv_id
34
  return CVResponse(**cv_entry)
35
 
@@ -41,5 +42,8 @@ async def get_cv_by_id(cv_id: str, db: AsyncIOMotorDatabase = Depends(lambda: mo
41
  cv = await CVModel.get(db, CVModel.collection_name, {"_id": ObjectId(cv_id)})
42
  if cv is None:
43
  raise HTTPException(status_code=404, detail="CV not found")
 
 
 
44
  cv['id'] = str(cv.pop('_id'))
45
  return CVResponse(**cv)
 
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
  cv_entry['id'] = cv_id
35
  return CVResponse(**cv_entry)
36
 
 
42
  cv = await CVModel.get(db, CVModel.collection_name, {"_id": ObjectId(cv_id)})
43
  if cv is None:
44
  raise HTTPException(status_code=404, detail="CV not found")
45
+
46
+ # MODIFICATION : Convertit explicitement l'ObjectId en str avant de retourner l'objet.
47
+ # On supprime la clé '_id' d'origine pour ne pas avoir de conflits avec la clé 'id' lors de la validation.
48
  cv['id'] = str(cv.pop('_id'))
49
  return CVResponse(**cv)