from fastapi import APIRouter, Depends from ..auth import get_current_user from ..models import User_Pydantic, User, File, Folder from typing import Dict, Any router = APIRouter( prefix="/users", tags=["users"], ) @router.get("/me", response_model=User_Pydantic) async def read_users_me(current_user: User = Depends(get_current_user)): return await User_Pydantic.from_tortoise_orm(current_user) @router.get("/me/export", response_model=Dict[str, Any]) async def export_my_data(current_user: User = Depends(get_current_user)): """ Exports all personal data associated with the current user. Includes user profile, and metadata for all owned files and folders. """ user_data = await User_Pydantic.from_tortoise_orm(current_user) files = await File.filter(owner=current_user).values( "id", "name", "size", "created_at", "modified_at", "file_type", "parent_id" ) folders = await Folder.filter(owner=current_user).values( "id", "name", "created_at", "modified_at", "parent_id" ) return { "user_profile": user_data.dict(), "files_metadata": files, "folders_metadata": folders, # In a more complete implementation, other data like activity logs, # share information, etc., would also be included. } @router.delete("/me", status_code=204) async def delete_my_account(current_user: User = Depends(get_current_user)): """ Deletes the current user's account and all associated data. This includes all files and folders owned by the user. """ # Delete all files and folders owned by the user await File.filter(owner=current_user).delete() await Folder.filter(owner=current_user).delete() # Finally, delete the user account await current_user.delete() return {}