Update code in endpoints/Add_user_organization.post.py
This commit is contained in:
parent
7506f42c5e
commit
9c09cb1702
@ -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"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user