Update code in endpoints/Add_user_organization.post.py

This commit is contained in:
Backend IM Bot 2025-03-21 07:10:46 +00:00
parent 7506f42c5e
commit 9c09cb1702

View File

@ -0,0 +1,34 @@
from fastapi import APIRouter, HTTPException
organizations = [] # In-memory storage
router = APIRouter()
@router.post("/Add_user_organization")
async def add_user_organization(
user_id: str,
organization_id: str
):
"""Add user to organization endpoint"""
org = next((o for o in organizations if o["id"] == organization_id), None)
if not org:
raise HTTPException(status_code=400, detail="Organization not found")
if user_id in org.get("members", []):
raise HTTPException(status_code=400, detail="User already in organization")
if "members" not in org:
org["members"] = []
org["members"].append(user_id)
return {
"message": "User added to organization successfully",
"organization_id": organization_id,
"user_id": user_id,
"status": "active",
"features": {
"access_level": "member",
"added_at": "now"
}
}