From 9c09cb17026a091a6adcab88076ff23db4420b6a Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 21 Mar 2025 07:10:46 +0000 Subject: [PATCH] Update code in endpoints/Add_user_organization.post.py --- endpoints/Add_user_organization.post.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/endpoints/Add_user_organization.post.py b/endpoints/Add_user_organization.post.py index e69de29..a35ab90 100644 --- a/endpoints/Add_user_organization.post.py +++ b/endpoints/Add_user_organization.post.py @@ -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" + } + } \ No newline at end of file