Spaces:
Running
Running
Download bioai-platform/backend/app/routers/profile.py from Samad14/bio-nexus-api: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/Samad14/bio-nexus-api/resolve/main/bioai-platform/backend/app/routers/profile.py
- Command line
-
hf download hf://spaces/Samad14/bio-nexus-api/bioai-platform/backend/app/routers/profile.py
-
curl -L -o profile.py https://huggingface.co/spaces/Samad14/bio-nexus-api/resolve/main/bioai-platform/backend/app/routers/profile.py
1.33 kB
| from fastapi import APIRouter, HTTPException, Depends | |
| from pydantic import BaseModel | |
| from typing import Any, Optional | |
| from app.services.supabase import get_supabase | |
| from app.services.auth import get_user_id, require_user_id | |
| from app.models.responses import ProfileUpdateResponse | |
| router = APIRouter() | |
| class ProfileUpdate(BaseModel): | |
| full_name: str = "" | |
| institution: str = "" | |
| async def get_profile(user_id: str = Depends(require_user_id)): | |
| supabase = get_supabase() | |
| result = supabase.table("profiles").select("*").eq("id", user_id).execute() | |
| if result.data: | |
| return result.data[0] | |
| return {"error": "Profile not found"} | |
| async def update_profile(profile: ProfileUpdate, user_id: str = Depends(require_user_id)): | |
| supabase = get_supabase() | |
| data = {} | |
| if "full_name" in profile.model_dump() and profile.full_name is not None: | |
| data["full_name"] = profile.full_name | |
| if "institution" in profile.model_dump() and profile.institution is not None: | |
| data["institution"] = profile.institution | |
| if data: | |
| result = supabase.table("profiles").update(data).eq("id", user_id).execute() | |
| return {"status": "updated", "data": result.data[0] if result.data else data} | |
| return {"status": "no changes"} | |