25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
817 B

  1. # Routes for user. MAIN PART OF THE API
  2. from fastapi import APIRouter, status
  3. from sqlalchemy.orm import Session
  4. from fastapi import Depends
  5. from typing import List
  6. from schemas.user import UserCreate, ShowUser
  7. from db.session import get_db
  8. from db.repository.user import create_new_user, list_users
  9. router = APIRouter()
  10. @router.post("/", response_model=ShowUser, status_code=status.HTTP_201_CREATED)
  11. def create_user(user: UserCreate, db: Session = Depends(get_db)):
  12. user = create_new_user(user=user, db=db)
  13. return user
  14. @router.get("/", response_model=List[ShowUser], status_code=status.HTTP_200_OK)
  15. def get_all_users(db: Session = Depends(get_db), role: str = None):
  16. if role == None:
  17. users = list_users(db=db)
  18. return users
  19. users = list_users(db=db, role=role)
  20. return users