trabajar por logos para checklists

This commit is contained in:
2025-11-26 17:42:06 -03:00
parent 637b21d85f
commit 16a25799e9
2 changed files with 236 additions and 2 deletions

View File

@@ -203,7 +203,7 @@ def send_completed_inspection_to_n8n(inspection, db):
# No lanzamos excepción para no interrumpir el flujo normal
BACKEND_VERSION = "1.0.27"
BACKEND_VERSION = "1.0.28"
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
# S3/MinIO configuration
@@ -878,6 +878,71 @@ def update_checklist(
return db_checklist
@app.post("/api/checklists/{checklist_id}/upload-logo")
async def upload_checklist_logo(
checklist_id: int,
file: UploadFile = File(...),
db: Session = Depends(get_db),
current_user: models.User = Depends(get_current_user)
):
"""Subir logo para un checklist (solo admin)"""
if current_user.role != "admin":
raise HTTPException(status_code=403, detail="Solo administradores pueden subir logos")
# Verificar que el checklist existe
checklist = db.query(models.Checklist).filter(models.Checklist.id == checklist_id).first()
if not checklist:
raise HTTPException(status_code=404, detail="Checklist no encontrado")
# Validar que es una imagen
if not file.content_type.startswith('image/'):
raise HTTPException(status_code=400, detail="El archivo debe ser una imagen")
# Subir a S3/MinIO
file_extension = file.filename.split(".")[-1]
now = datetime.now()
folder = f"checklist-logos/{now.year}/{now.month:02d}"
file_name = f"checklist_{checklist_id}_{uuid.uuid4().hex}.{file_extension}"
s3_key = f"{folder}/{file_name}"
file_content = await file.read()
s3_client.upload_fileobj(
BytesIO(file_content),
S3_IMAGE_BUCKET,
s3_key,
ExtraArgs={"ContentType": file.content_type}
)
logo_url = f"{S3_ENDPOINT}/{S3_IMAGE_BUCKET}/{s3_key}"
# Actualizar checklist
checklist.logo_url = logo_url
db.commit()
db.refresh(checklist)
return {"logo_url": logo_url, "message": "Logo subido exitosamente"}
@app.delete("/api/checklists/{checklist_id}/logo")
def delete_checklist_logo(
checklist_id: int,
db: Session = Depends(get_db),
current_user: models.User = Depends(get_current_user)
):
"""Eliminar logo de un checklist (solo admin)"""
if current_user.role != "admin":
raise HTTPException(status_code=403, detail="Solo administradores pueden eliminar logos")
checklist = db.query(models.Checklist).filter(models.Checklist.id == checklist_id).first()
if not checklist:
raise HTTPException(status_code=404, detail="Checklist no encontrado")
checklist.logo_url = None
db.commit()
return {"message": "Logo eliminado exitosamente"}
# ============= QUESTION ENDPOINTS =============
@app.post("/api/questions", response_model=schemas.Question)
def create_question(