Add GET /api/v1/users endpoint for admin to list all users
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import timedelta
|
|||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from app.core.database import get_db
|
from app.core.database import get_db
|
||||||
from app.core.security import verify_password, create_access_token, decode_access_token, get_password_hash
|
from app.core.security import verify_password, create_access_token, decode_access_token, get_password_hash
|
||||||
@@ -144,6 +145,15 @@ async def update_current_user(
|
|||||||
db.refresh(current_user)
|
db.refresh(current_user)
|
||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
|
@router.get("/users", response_model=List[UserResponse])
|
||||||
|
async def list_users(
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
admin_user: User = Depends(get_current_admin_user)
|
||||||
|
):
|
||||||
|
"""Admin endpoint to list all users."""
|
||||||
|
users = db.query(User).all()
|
||||||
|
return users
|
||||||
|
|
||||||
@router.put("/users/{user_id}", response_model=UserResponse)
|
@router.put("/users/{user_id}", response_model=UserResponse)
|
||||||
async def update_user_admin(
|
async def update_user_admin(
|
||||||
user_id: int,
|
user_id: int,
|
||||||
|
|||||||
Reference in New Issue
Block a user