From 671d5bac15907f25ee3dd0001736049df3646fda Mon Sep 17 00:00:00 2001 From: Fanilo-Nantenaina Date: Wed, 14 Jan 2026 15:20:16 +0300 Subject: [PATCH] feat(society): add logo support and preview endpoint --- api.py | 93 +++++++++++++++++++++++++++++++++++++- schemas/society/societe.py | 10 ++-- 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/api.py b/api.py index 72e741e..7c3146e 100644 --- a/api.py +++ b/api.py @@ -1,6 +1,6 @@ from fastapi import FastAPI, HTTPException, Path, Query, Depends, status, Body from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import StreamingResponse +from fastapi.responses import StreamingResponse, HTMLResponse, Response from fastapi.encoders import jsonable_encoder from pydantic import BaseModel, Field, EmailStr from typing import List, Optional @@ -2874,6 +2874,97 @@ async def obtenir_informations_societe(): raise HTTPException(500, str(e)) +@app.get("/societe/logo", tags=["Société"]) +async def obtenir_logo_societe(): + """Retourne le logo en tant qu'image directe""" + try: + societe = sage_client.lire_informations_societe() + + if not societe or not societe.get("logo_base64"): + raise HTTPException(404, "Logo introuvable") + + import base64 + + image_data = base64.b64decode(societe["logo_base64"]) + + return Response(content=image_data, media_type=societe["logo_content_type"]) + + except HTTPException: + raise + except Exception as e: + logger.error(f"Erreur récupération logo: {e}") + raise HTTPException(500, str(e)) + + +@app.get("/societe/preview", response_class=HTMLResponse, tags=["Société"]) +async def preview_societe(): + """Page HTML pour visualiser les infos société avec logo""" + try: + societe = sage_client.lire_informations_societe() + + if not societe: + return "

Société introuvable

" + + logo_html = "" + if societe.get("logo_base64"): + logo_html = f'' + else: + logo_html = "

Aucun logo disponible

" + + html = f""" + + + + + Informations Société + + + +
+

Informations Société

+ + + +
+ Raison sociale: {societe["raison_sociale"]} +
+
+ SIRET: {societe["siret"] or "N/A"} +
+
+ Adresse: {societe["adresse"] or "N/A"} +
+
+ Code postal: {societe["code_postal"] or "N/A"} +
+
+ Ville: {societe["ville"] or "N/A"} +
+
+ Email: {societe["email"] or "N/A"} +
+
+ Téléphone: {societe["telephone"] or "N/A"} +
+
+ + + """ + return html + + except Exception as e: + return f"

Erreur

{str(e)}

" + + @app.get("/health", tags=["System"]) async def health_check( sage: SageGatewayClient = Depends(get_sage_client_for_user), diff --git a/schemas/society/societe.py b/schemas/society/societe.py index 01fa308..08309e5 100644 --- a/schemas/society/societe.py +++ b/schemas/society/societe.py @@ -9,14 +9,12 @@ class ExerciceComptable(BaseModel): class SocieteInfo(BaseModel): - # Identification raison_sociale: str numero_dossier: str siret: Optional[str] = None code_ape: Optional[str] = None numero_tva: Optional[str] = None - # Adresse adresse: Optional[str] = None complement_adresse: Optional[str] = None code_postal: Optional[str] = None @@ -24,27 +22,25 @@ class SocieteInfo(BaseModel): code_region: Optional[str] = None pays: Optional[str] = None - # Contacts telephone: Optional[str] = None telecopie: Optional[str] = None email: Optional[str] = None email_societe: Optional[str] = None site_web: Optional[str] = None - # Informations juridiques capital: float = 0.0 forme_juridique: Optional[str] = None - # Exercices comptables exercices: List[ExerciceComptable] = [] - # Configuration devise_compte: int = 0 devise_equivalent: int = 0 longueur_compte_general: int = 0 longueur_compte_analytique: int = 0 regime_fec: int = 0 - # Autres base_modele: Optional[str] = None marqueur: int = 0 + + logo_base64: Optional[str] = None + logo_content_type: Optional[str] = None