Пример #1
0
def get_user(session: DBSession,
             *,
             username: str = None,
             user_id: int = None) -> UserModel:
    db_employee = None

    if username is not None:
        db_employee = session.get_user_by_username(username)
    elif user_id is not None:
        db_employee = session.get_user_by_id(user_id)

    if db_employee is None or db_employee.is_delete is True:
        raise DBUserNotExistsException
    return db_employee
Пример #2
0
def create_user(session: DBSession, user: ReqCreateUserDTO,
                password: str) -> UserModel:
    if session.get_user_by_username(user.username) is not None:
        raise DBUserExistsException

    new_user = UserModel(
        username=user.username,
        password=password,
        first_name=user.first_name,
        last_name=user.last_name,
    )

    session.add_model(new_user)

    return new_user