feat(Contact): add civilite mapping and validator
This commit is contained in:
parent
f414a2889e
commit
c101e45afd
1 changed files with 19 additions and 0 deletions
19
api.py
19
api.py
|
|
@ -150,6 +150,25 @@ class Contact(BaseModel):
|
|||
linkedin: Optional[str] = Field(None, description="Profil LinkedIn (CT_LinkedIn)")
|
||||
skype: Optional[str] = Field(None, description="Identifiant Skype (CT_Skype)")
|
||||
|
||||
_civilite_map = {
|
||||
0: "M.",
|
||||
1: "Mme",
|
||||
2: "Mlle",
|
||||
3: "Société",
|
||||
}
|
||||
|
||||
@validator("civilite", pre=True, always=True)
|
||||
def convert_civilite(cls, v):
|
||||
"""
|
||||
Si la civilité est fournie sous forme de code numérique,
|
||||
on la transforme en chaîne de caractères.
|
||||
"""
|
||||
if v is None:
|
||||
return v
|
||||
if isinstance(v, int):
|
||||
return cls._civilite_map.get(v, str(v)) # retourne le code en string si non mappé
|
||||
return v
|
||||
|
||||
class Config:
|
||||
json_schema_extra = {
|
||||
"example": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue