def update_user(user: UserBase, db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user: User = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") return crud_user.update_user(db=db, user=user, db_user=db_user)
def read_room_by_user(db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") roons = crud_room.get_all_rooms_by_User(db, db_user) return roons
def create_room(room: RoomCreate, db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user = crud_user.get_user_by_uuid(db, uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") return crud_room.create_room(db, room)
def delete_user(test_id: int, db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user: User = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") db_test: Test = crud_test.get_test_by_id(db, test_id=test_id) if db_test is None: raise HTTPException(status_code=404, detail="Test not found") return crud_test.delele_test(db=db, db_test=db_test, db_user=db_user)
def update_test(test: TestUpdate, db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user: User = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") db_test: Test = crud_test.get_test_by_id(db, test_id=test.idTest) if db_test is None: raise HTTPException(status_code=404, detail="Test not found") db_test: Test = crud_test.update_test(db=db, test=test, db_test=db_test, db_user=db_user) questions = db_test.questions questions = sorted(questions, key=lambda q: q.idQuestion) db_test.questions = questions return db_test
def check_token(uuid: str = Depends(check_token_access), db: Session = Depends(get_db)): db_user: User = crud_user.get_user_by_uuid(db, uuid) if db_user: return True return False
def read_tests(skip: int = 0, limit: int = 100, db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user: User = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") return crud_test.get_all_test_of_user(db, db_user=db_user, skip=skip, limit=limit)
def generate_to_home(db: Session = Depends(get_db), uuid: str = Depends(check_token_access)): db_user: User = crud_user.get_user_by_uuid(db, uuid=uuid) if db_user is None: raise HTTPException(status_code=404, detail="User not found") return crud_statisc.generate_to_home(db, db_user)