|
|
@@ -1,12 +1,12 @@ |
|
|
|
# Routes for user. MAIN PART OF THE API |
|
|
|
from fastapi import APIRouter, status |
|
|
|
from fastapi import APIRouter, HTTPException, status |
|
|
|
from sqlalchemy.orm import Session |
|
|
|
from fastapi import Depends |
|
|
|
from typing import List |
|
|
|
|
|
|
|
from schemas.user import UserCreate, ShowUser |
|
|
|
from db.session import get_db |
|
|
|
from db.repository.user import create_new_user, list_users |
|
|
|
from db.repository.user import create_new_user, list_users, get_user_by_id |
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter() |
|
|
@@ -25,3 +25,11 @@ def get_all_users(db: Session = Depends(get_db), role: str = None): |
|
|
|
return users |
|
|
|
users = list_users(db=db, role=role) |
|
|
|
return users |
|
|
|
|
|
|
|
|
|
|
|
@router.get("/{user_id}", response_model=ShowUser, status_code=status.HTTP_200_OK) |
|
|
|
def get_user(user_id: int, db: Session = Depends(get_db)): |
|
|
|
user = get_user_by_id(user_id=user_id, db=db) |
|
|
|
if not user: |
|
|
|
raise HTTPException(status_code=404, detail="User not found") |
|
|
|
return user |