habulaj commited on
Commit
cae332c
·
verified ·
1 Parent(s): ee7d07a

Update routes/onboarding.py

Browse files
Files changed (1) hide show
  1. routes/onboarding.py +27 -0
routes/onboarding.py CHANGED
@@ -77,6 +77,33 @@ async def update_onboarding_question(payload: UpdateOnboardingQuestion = Body(..
77
  logger.error(f"❌ Erro interno ao atualizar pergunta: {str(e)}")
78
  raise HTTPException(status_code=500, detail="Erro interno do servidor")
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  @router.get("/onboarding/questions")
81
  async def get_onboarding_questions() -> Dict[str, List[Dict[str, Any]]]:
82
  """
 
77
  logger.error(f"❌ Erro interno ao atualizar pergunta: {str(e)}")
78
  raise HTTPException(status_code=500, detail="Erro interno do servidor")
79
 
80
+ @router.delete("/onboarding/delete-question")
81
+ async def delete_onboarding_question(id: int = Query(..., description="ID da pergunta a ser deletada")):
82
+ """
83
+ Deleta uma pergunta de onboarding com base no ID (passado via query parameter).
84
+ """
85
+ try:
86
+ query_url = f"{SUPABASE_URL}/rest/v1/Onboarding?id=eq.{id}"
87
+ headers = SUPABASE_ROLE_HEADERS.copy()
88
+ headers["Prefer"] = "return=representation"
89
+
90
+ async with aiohttp.ClientSession() as session:
91
+ async with session.delete(query_url, headers=headers) as response:
92
+ if response.status != 200:
93
+ detail = await response.text()
94
+ logger.error(f"❌ Erro ao deletar pergunta: {detail}")
95
+ raise HTTPException(status_code=response.status, detail="Erro ao deletar pergunta")
96
+
97
+ deleted = await response.json()
98
+ if not deleted:
99
+ raise HTTPException(status_code=404, detail="Pergunta não encontrada ou já deletada.")
100
+
101
+ return {"message": "🗑️ Pergunta deletada com sucesso!", "deleted": deleted}
102
+
103
+ except Exception as e:
104
+ logger.error(f"❌ Erro interno ao deletar pergunta: {str(e)}")
105
+ raise HTTPException(status_code=500, detail="Erro interno do servidor")
106
+
107
  @router.get("/onboarding/questions")
108
  async def get_onboarding_questions() -> Dict[str, List[Dict[str, Any]]]:
109
  """