Update code in endpoints/users.post.py
This commit is contained in:
parent
183963f062
commit
b3a6ff25bd
@ -0,0 +1,39 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from core.database import fake_users_db
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/users")
|
||||||
|
async def create_user(
|
||||||
|
username: str,
|
||||||
|
email: str,
|
||||||
|
password: str
|
||||||
|
):
|
||||||
|
"""Create new user endpoint"""
|
||||||
|
if username in fake_users_db:
|
||||||
|
raise HTTPException(status_code=400, detail="Username already exists")
|
||||||
|
|
||||||
|
user_id = str(uuid.uuid4())
|
||||||
|
new_user = {
|
||||||
|
"id": user_id,
|
||||||
|
"username": username,
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
"disabled": False
|
||||||
|
}
|
||||||
|
|
||||||
|
fake_users_db[username] = new_user
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "User created successfully",
|
||||||
|
"data": {
|
||||||
|
"user_id": user_id,
|
||||||
|
"username": username,
|
||||||
|
"email": email
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"created_at": "2024-01-01T00:00:00Z",
|
||||||
|
"status": "active"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user