Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter, HTTPException, Request | |
| from config.database import get_supabase_admin | |
| from middleware.auth_guard import get_current_user_optional | |
| from models.support import SupportTicket, TicketReply | |
| from services.email import send_support_notification_to_admin, send_support_confirmation_to_user | |
| router = APIRouter(prefix="/api/support", tags=["support"]) | |
| ADMIN_EMAIL = "admin@codenexus.qzz.io" | |
| async def submit_ticket(data: SupportTicket, request: Request): | |
| user = await get_current_user_optional(request) | |
| db = get_supabase_admin() | |
| ticket = { | |
| "user_email": data.user_email, | |
| "category": data.category, | |
| "message": data.message, | |
| "status": "open", | |
| } | |
| if data.screenshot_url: | |
| ticket["screenshot_url"] = data.screenshot_url | |
| if user: | |
| ticket["user_id"] = str(user.id) | |
| result = db.table("support_tickets").insert(ticket).execute() | |
| # Send emails (non-blocking — don't fail ticket if email fails) | |
| try: | |
| await send_support_notification_to_admin(ADMIN_EMAIL, data.user_email, data.category, data.message) | |
| await send_support_confirmation_to_user(data.user_email, data.category) | |
| except Exception: | |
| pass | |
| return {"message": "Ticket submitted successfully", "id": result.data[0]["id"] if result.data else None} | |
| async def submit_feedback(request: Request): | |
| body = await request.json() | |
| analysis_id = body.get("analysis_id") | |
| helpful = body.get("helpful", True) | |
| db = get_supabase_admin() | |
| if analysis_id: | |
| db.table("analyses").update({"feedback": "helpful" if helpful else "not_helpful"}).eq("id", analysis_id).execute() | |
| return {"message": "Feedback recorded"} | |