|
|
@@ -7,7 +7,7 @@ from apis.v1.route_auth import get_current_user |
|
|
|
from db.models.user import User |
|
|
|
from schemas.user import UserCreate, ShowUser |
|
|
|
from db.session import get_db |
|
|
|
from db.repository.user import create_new_user, list_users, get_user_by_id |
|
|
|
from db.repository.user import create_new_user, list_users, get_user_by_id, replace_user_data |
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter() |
|
|
@@ -35,6 +35,18 @@ def get_all_users(db: Session = Depends(get_db), role: str = None): |
|
|
|
users = list_users(db=db, role=role) |
|
|
|
return users |
|
|
|
|
|
|
|
@router.put("/{user_id}", response_model=ShowUser, status_code=status.HTTP_202_ACCEPTED) |
|
|
|
def update_user( |
|
|
|
user_id: int, |
|
|
|
user: UserCreate, |
|
|
|
db: Session = Depends(get_db), |
|
|
|
current_user: User = Depends(get_current_user), |
|
|
|
): |
|
|
|
if current_user.Role != "Admin": |
|
|
|
raise HTTPException(status_code=403, detail="You are not authorized to perform this action") |
|
|
|
user = replace_user_data(user_id=user_id, user=user, db=db) |
|
|
|
return user |
|
|
|
|
|
|
|
|
|
|
|
@router.get("/me", response_model=ShowUser, status_code=status.HTTP_200_OK) |
|
|
|
def get_user_me( |
|
|
|