Samad14's picture
feat: domains, interactions, primers, structure analysis, wizard, phylo tree, conservation
bac1801
Raw History Blame Contribute Delete
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 = ""
@router.get("")
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"}
@router.put("", response_model=ProfileUpdateResponse)
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"}