Spaces:
Sleeping
Sleeping
File size: 1,882 Bytes
048373b 4c4b933 048373b dd5badb 4c4b933 048373b 4c4b933 048373b 4c4b933 048373b 4c4b933 048373b 4c4b933 33039d3 9d070d3 89990f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 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 |