Add user and team models with auth routes and admin endpoints
This commit is contained in:
+25
-16
@@ -1,27 +1,36 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi import HTTPException
|
||||
|
||||
from models.user import User, UserChangePassword
|
||||
from lib.db import get_connection
|
||||
|
||||
router = APIRouter(prefix="/users", tags=["users"])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
@router.get("/", response_model=list[User])
|
||||
async def list_users():
|
||||
return {"users": []}
|
||||
with get_connection() as conn:
|
||||
users = conn.execute('SELECT * FROM "User"').fetchdf()
|
||||
|
||||
# Convert DataFrame to dict
|
||||
users_dict = users.to_dict(orient="records")
|
||||
return users_dict
|
||||
|
||||
|
||||
@router.get("/{user_id}")
|
||||
@router.get("/{user_id}", response_model=User)
|
||||
async def get_user(user_id: int):
|
||||
return {"user_id": user_id}
|
||||
with get_connection() as conn:
|
||||
user_df = conn.execute(
|
||||
'SELECT * FROM "User" WHERE id = ?', (user_id,)
|
||||
).fetchdf()
|
||||
|
||||
if user_df.empty:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
user_data = user_df.to_dict(orient="records")[0]
|
||||
return User(**user_data)
|
||||
|
||||
|
||||
# @router.post("/")
|
||||
# async def create_user(user: User):
|
||||
# return {"user": user}
|
||||
|
||||
# @router.patch("/{user_id}")
|
||||
# async def update_user(user_id: int, user: User):
|
||||
# return {"user_id": user_id, "user": user}
|
||||
|
||||
|
||||
@router.delete("/{user_id}")
|
||||
async def delete_user(user_id: int):
|
||||
return {"user_id": user_id}
|
||||
@router.patch("/{user_id}")
|
||||
async def change_password(user: UserChangePassword):
|
||||
raise HTTPException(status_code=401, detail="Not implemented")
|
||||
|
||||
Reference in New Issue
Block a user