energensy contacts, dashboard
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -372,6 +372,58 @@ async def delete_emergency_contact(
|
||||
return None
|
||||
|
||||
|
||||
@app.get("/api/v1/users/dashboard", tags=["Dashboard"])
|
||||
async def get_user_dashboard(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Get user dashboard data"""
|
||||
try:
|
||||
# Get emergency contacts count
|
||||
emergency_contacts_result = await db.execute(
|
||||
select(EmergencyContact).filter(
|
||||
EmergencyContact.user_id == current_user.id,
|
||||
EmergencyContact.is_active == True
|
||||
)
|
||||
)
|
||||
emergency_contacts = emergency_contacts_result.scalars().all()
|
||||
|
||||
dashboard_data = {
|
||||
"user": {
|
||||
"id": current_user.id,
|
||||
"uuid": str(current_user.uuid),
|
||||
"email": current_user.email,
|
||||
"username": current_user.username,
|
||||
"first_name": current_user.first_name,
|
||||
"last_name": current_user.last_name,
|
||||
"avatar_url": current_user.avatar_url
|
||||
},
|
||||
"emergency_contacts_count": len(emergency_contacts),
|
||||
"settings": {
|
||||
"location_sharing_enabled": current_user.location_sharing_enabled,
|
||||
"emergency_notifications_enabled": current_user.emergency_notifications_enabled,
|
||||
"push_notifications_enabled": current_user.push_notifications_enabled
|
||||
},
|
||||
"verification_status": {
|
||||
"email_verified": current_user.email_verified,
|
||||
"phone_verified": current_user.phone_verified
|
||||
},
|
||||
"account_status": {
|
||||
"is_active": current_user.is_active,
|
||||
"created_at": str(current_user.created_at) if hasattr(current_user, 'created_at') else None
|
||||
}
|
||||
}
|
||||
|
||||
return dashboard_data
|
||||
|
||||
except Exception as e:
|
||||
print(f"Dashboard error: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to load dashboard data"
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/v1/health")
|
||||
async def health_check_v1():
|
||||
"""Health check endpoint with API version"""
|
||||
|
||||
Reference in New Issue
Block a user