fixed bugs

This commit is contained in:
belviskhoremk
2026-02-23 16:47:03 +00:00
parent e151c42e81
commit 07c4c55072
6 changed files with 254 additions and 41 deletions

View File

@@ -60,6 +60,7 @@ async def list_marketplace_chatbots(
languages=c.get("languages", ["en"]),
primary_color=c.get("primary_color", "#6366f1"),
welcome_message=c.get("welcome_message", "Hello!"),
logo_url=c.get("logo_url"),
average_rating=c.get("average_rating"),
total_conversations=c.get("total_conversations", 0),
company_name=company_data.get("name"),
@@ -74,23 +75,27 @@ async def list_marketplace_chatbots(
total=total,
page=page,
limit=limit,
has_more=(offset + limit) < total,
has_more=(offset + limit < total),
)
@router.get("/chatbots/{chatbot_id}", response_model=ChatbotPublicResponse)
async def get_marketplace_chatbot(chatbot_id: str):
async def get_marketplace_chatbot(chatbot_id: str, user=Depends(get_optional_user)):
supabase = get_supabase()
result = supabase.table("chatbots").select("*, companies(name, logo_url)") \
.eq("id", chatbot_id) \
.eq("is_published", True) \
.execute()
result = supabase.table("chatbots").select(
"*, companies(name, logo_url)"
).eq("id", chatbot_id).eq("is_published", True).execute()
if not result.data:
raise HTTPException(status_code=404, detail="Chatbot not found in marketplace")
raise HTTPException(status_code=404, detail="Chatbot not found")
c = result.data[0]
company_data = c.get("companies") or {}
conv_count = supabase.table("conversations").select("id", count="exact") \
.eq("chatbot_id", chatbot_id).execute()
return ChatbotPublicResponse(
id=c["id"],
name=c["name"],
@@ -100,8 +105,9 @@ async def get_marketplace_chatbot(chatbot_id: str):
languages=c.get("languages", ["en"]),
primary_color=c.get("primary_color", "#6366f1"),
welcome_message=c.get("welcome_message", "Hello!"),
logo_url=c.get("logo_url"),
average_rating=c.get("average_rating"),
total_conversations=c.get("total_conversations", 0),
total_conversations=conv_count.count or 0,
company_name=company_data.get("name"),
company_logo=company_data.get("logo_url"),
created_at=c.get("created_at"),
@@ -130,4 +136,4 @@ async def rate_chatbot(
new_avg = (current + rating.rating) / 2
supabase.table("chatbots").update({"average_rating": round(new_avg, 1)}).eq("id", chatbot_id).execute()
return {"message": "Rating submitted", "new_average": round(new_avg, 1)}
return {"message": "Rating submitted", "new_average": round(new_avg, 1)}