refactor(api): rename client endpoints to tiers for consistency (Generalized contact's creation endpoint)

This commit is contained in:
Fanilo-Nantenaina 2025-12-29 13:27:08 +03:00
parent efe5961bea
commit 0e2398278f

22
api.py
View file

@ -5995,13 +5995,13 @@ async def get_document_pdf(
@app.post("/clients/{numero}/contacts", response_model=Contact, tags=["Contacts"])
@app.post("/tiers/{numero}/contacts", response_model=Contact, tags=["Contacts"])
async def creer_contact(numero: str, contact: ContactCreate):
try:
try:
sage_client.lire_client(numero)
sage_client.lire_tiers(numero)
except:
raise HTTPException(404, f"Client {numero} non trouvé")
raise HTTPException(404, f"Tiers {numero} non trouvé")
if contact.numero != numero:
contact.numero = numero
@ -6016,8 +6016,8 @@ async def creer_contact(numero: str, contact: ContactCreate):
raise HTTPException(500, str(e))
@app.get("/clients/{numero}/contacts", response_model=List[Contact], tags=["Contacts"])
async def lister_contacts_client(numero: str):
@app.get("/tiers/{numero}/contacts", response_model=List[Contact], tags=["Contacts"])
async def lister_contacts(numero: str):
try:
contacts = sage_client.lister_contacts(numero)
return [Contact(**c) for c in contacts]
@ -6026,7 +6026,7 @@ async def lister_contacts_client(numero: str):
raise HTTPException(500, str(e))
@app.get("/clients/{numero}/contacts/{contact_numero}", response_model=Contact, tags=["Contacts"])
@app.get("/tiers/{numero}/contacts/{contact_numero}", response_model=Contact, tags=["Contacts"])
async def obtenir_contact(numero: str, contact_numero: int):
try:
contact = sage_client.obtenir_contact(numero, contact_numero)
@ -6040,7 +6040,7 @@ async def obtenir_contact(numero: str, contact_numero: int):
raise HTTPException(500, str(e))
@app.put("/clients/{numero}/contacts/{contact_numero}", response_model=Contact, tags=["Contacts"])
@app.put("/tiers/{numero}/contacts/{contact_numero}", response_model=Contact, tags=["Contacts"])
async def modifier_contact(numero: str, contact_numero: int, contact: ContactUpdate):
try:
contact_existant = sage_client.obtenir_contact(numero, contact_numero)
@ -6062,7 +6062,7 @@ async def modifier_contact(numero: str, contact_numero: int, contact: ContactUpd
raise HTTPException(500, str(e))
@app.delete("/clients/{numero}/contacts/{contact_numero}", tags=["Contacts"])
@app.delete("/tiers/{numero}/contacts/{contact_numero}", tags=["Contacts"])
async def supprimer_contact(numero: str, contact_numero: int):
try:
resultat = sage_client.supprimer_contact(numero, contact_numero)
@ -6072,7 +6072,7 @@ async def supprimer_contact(numero: str, contact_numero: int):
raise HTTPException(500, str(e))
@app.post("/clients/{numero}/contacts/{contact_numero}/definir-defaut", tags=["Contacts"])
@app.post("/tiers/{numero}/contacts/{contact_numero}/definir-defaut", tags=["Contacts"])
async def definir_contact_defaut(numero: str, contact_numero: int):
try:
resultat = sage_client.definir_contact_defaut(numero, contact_numero)
@ -6111,11 +6111,7 @@ async def obtenir_tiers(
@app.get("/tiers/{code}", response_model=TiersDetails, tags=["Tiers"])
async def lire_tiers_detail(code: str):
"""
Lecture détaillée d'un tiers par son code.
Retourne toutes les informations du tiers ainsi que ses contacts.
"""
try:
tiers = sage_client.lire_tiers(code)
if not tiers: