Spaces:
Sleeping

maidapp / app /debug.py
low-key-007's picture
Update app/debug.py
89990f5 verified
Raw History Blame Contribute Delete
1.88 kB
import os
from fastapi import APIRouter
from app.config import settings
from app.supabase_client import supabase_request
import redis.asyncio as aioredis
from fastapi import APIRouter, Depends
from app.auth import get_current_user
from app.supabase_client import supabase_request
router = APIRouter(tags=["debug"])
@router.get("/debug/ping")
async def ping():
return {"status": "ok", "app": "maidapp"}
@router.get("/debug/supabase")
async def debug_supabase():
try:
# simple SELECT 1 via PostgREST: call the "rpc" or access the version via a safe endpoint
# PostgREST has no generic "select 1", but we can query one known table if present (services)
resp = await supabase_request("GET", "services", params={"select": "*", "limit": 1})
return {"status": "ok", "services_sample": resp}
except Exception as e:
return {"status": "error", "error": str(e)}
@router.get("/debug/redis")
async def debug_redis():
if not settings.REDIS_URL:
return {"status": "error", "error": "REDIS_URL not set"}
try:
r = aioredis.from_url(settings.REDIS_URL, encoding="utf-8", decode_responses=True)
pong = await r.ping()
return {"status": "ok", "pong": pong}
except Exception as e:
return {"status": "error", "error": str(e)}
from fastapi import Depends
from app.auth import get_current_user
@router.get("/protected")
async def protected(current_user: dict = Depends(get_current_user)):
return {
"message": f"Hello {current_user['phone']}, you are a {current_user['role']}!"
}
@router.get("/messages/me")
async def get_my_messages(current_user: dict = Depends(get_current_user)):
user_id = current_user["sub"]
res = await supabase_request("GET", "messages", params={
"user_id": f"eq.{user_id}", "select": "*", "order": "created_at.desc"
})
return res