Update code in endpoints/add.post.py
This commit is contained in:
parent
19a0f187db
commit
2db25e7c37
@ -0,0 +1,45 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from core.database import fake_users_db
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/add")
|
||||||
|
async def add_user_to_org(
|
||||||
|
user_id: str,
|
||||||
|
org_id: str,
|
||||||
|
role: str = "member"
|
||||||
|
):
|
||||||
|
"""Add user to organization"""
|
||||||
|
if user_id not in fake_users_db:
|
||||||
|
raise HTTPException(status_code=400, detail="User not found")
|
||||||
|
|
||||||
|
# Simulate org check in demo db
|
||||||
|
if not org_id:
|
||||||
|
raise HTTPException(status_code=400, detail="Organization not found")
|
||||||
|
|
||||||
|
membership_id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
# Update user's org membership in demo db
|
||||||
|
if "organizations" not in fake_users_db[user_id]:
|
||||||
|
fake_users_db[user_id]["organizations"] = {}
|
||||||
|
|
||||||
|
fake_users_db[user_id]["organizations"][org_id] = {
|
||||||
|
"membership_id": membership_id,
|
||||||
|
"role": role,
|
||||||
|
"joined_at": "2024-01-01T00:00:00Z" # Demo timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "User added to organization successfully",
|
||||||
|
"data": {
|
||||||
|
"user_id": user_id,
|
||||||
|
"org_id": org_id,
|
||||||
|
"membership_id": membership_id,
|
||||||
|
"role": role
|
||||||
|
},
|
||||||
|
"next_steps": [
|
||||||
|
"Set user permissions",
|
||||||
|
"Configure user access levels"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user