Exemple #1
0
def create_employee(session: DBSession, user: RequestCreateEmployeeDto) -> DBEmployee:
    user = DBEmployee(
        first_name=user.first_name,
        last_name=user.last_name
    )
    session.add_model(user, need_flush=True)

    return user
Exemple #2
0
def create_message(session: DBSession, message: RequestCreateMessageDto,
                   converse_id: dict) -> DBMessage:
    new_message = DBMessage(message=message.message,
                            sender_id=converse_id.get('sender_id'),
                            recipient_id=converse_id.get('recipient_id'))

    session.add_model(new_message)

    return new_message
Exemple #3
0
def create_file(session: DBSession, user_id: int, file_name: str) -> DBFile:
    new_file = DBFile(
        sender_id=user_id,
        ref_file=file_name,
    )

    session.add_model(new_file)

    return new_file
Exemple #4
0
def create_message(session: DBSession, message: RequestCreateMessageDto, sender_id: int) -> DBMessage:

    new_message = DBMessage(
        message=message.message,
        recipient_id=message.recipient_id,
        sender_id=sender_id
    )
    session.add_model(new_message)

    return new_message
def create_message(session: DBSession, *, message: str, sender_id: str,
                   recipient_id: str) -> DBMessage:
    new_message = DBMessage(
        message=message,
        sender_id=sender_id,
        recipient_id=recipient_id,
    )
    session.add_model(new_message)

    return new_message
Exemple #6
0
def create_employee(session: DBSession,
                    employee: RequestCreateEmployeeDto) -> DBEmployee:
    new_employee = DBEmployee(
        first_name=employee.first_name,
        last_name=employee.last_name,
    )

    session.add_model(new_employee)

    return new_employee
Exemple #7
0
def create_user(session: DBSession, user: RequestCreateUserDto) -> DBUser:
    new_user = DBUser(
        login=user.login,
        password=user.password,
    )

    if session.get_user_by_login(new_user.login) is not None:
        raise UserExistException

    session.add_model(new_user)

    return new_user
Exemple #8
0
def create_user(session: DBSession, user: RequestCreateUserDto,
                hashed_password: bytes) -> DBUser:
    new_user = DBUser(login=user.login,
                      password=hashed_password,
                      first_name=user.first_name,
                      last_name=user.last_name)

    if session.get_user_by_login_with_deleted(new_user.login) is not None:
        raise DBUserExistsException

    session.add_model(new_user)

    return new_user
Exemple #9
0
def create_message(session: DBSession, message: RequestCreateMessageDto,
                   sender: int) -> DBMessage:
    if session.get_user_by_id(uid=message.recipient_id) is None:
        raise DBUserNotExistsException

    new_message = DBMessage(
        recipient_id=message.recipient_id,
        message=message.message,
        sender_id=sender,
    )
    session.add_model(new_message)

    return new_message
Exemple #10
0
def create_message(session: DBSession, message: RequestCreateMessageDto,
                   token: dict, recipient_id: int) -> DBMessage:
    # создание модели DBMessage
    new_message = DBMessage(
        message=message.message,
        sender_id=token['id'],
        recipient_id=recipient_id,
    )

    # добавляем модель в БД
    session.add_model(new_message)

    return new_message
Exemple #11
0
def create_msg_file_relation(session: DBSession, user_id: int, msg_id: int, file_id: int) -> DBMsgFile:
    db_file = session.get_file_by_id(file_id)
    if db_file is None:
        raise DBFileNotExistsException
    if db_file.sender_id != user_id:
        raise DBResourceOwnerException
    msg_file = DBMsgFile(
        msg_id=msg_id,
        file_id=file_id,
    )

    session.add_model(msg_file)

    return msg_file
Exemple #12
0
def create_message(session: DBSession, message: RequestCreateMessageDto,
                   sender_id: int) -> DBMessage:
    # Поиск по login в users
    recipient = session.get_user_by_login(message.recipient)
    if recipient is None:
        raise DBUserNotExistsException

    new_message = DBMessage(sender_id=sender_id,
                            recipient_id=recipient.id,
                            message=message.message)

    session.add_model(new_message)

    return new_message
Exemple #13
0
def create_employee(session: DBSession, employee: RequestCreateEmployeeDto,
                    hashed_password: bytes) -> DBEmployee:
    new_employee = DBEmployee(
        login=employee.login,
        password=hashed_password,
        first_name=employee.first_name,
        last_name=employee.last_name,
    )

    if session.get_employee_by_login(new_employee.login) is not None:
        raise DBEmployeeExistsException

    session.add_model(new_employee)

    return new_employee
Exemple #14
0
def create_message(session: DBSession, message: RequestCreateMessageDto, eid: int) -> DBMessage:
    new_message = DBMessage(
        user_message=message.user_message,
        recipient=message.recipient,
        recipient_id=session.get_recipient_id_by_login(message.recipient),
        sender_id=eid

    )

    if session.get_employee_by_login(new_message.recipient) is None:
        raise DBEmployeeNotExistsException

    session.add_model(new_message)

    return new_message
Exemple #15
0
def create_message(session: DBSession, message: RequestCreateMessageDto, sender_id: int) -> DBMessage:
    recipient = session.get_employee_by_login(login=message.recipient)

    if recipient is None:
        raise DBEmployeeNotExistsException

    new_message = DBMessage(
        sender_id=sender_id,
        recipient_id=recipient.id,
        message=message.message
    )

    session.add_model(new_message)

    return new_message
Exemple #16
0
def create_message(session: DBSession, message: RequestCreateMessageDto, uid: int) -> DBMessage:
    recipient = session.get_user_by_login(login=message.recipient, add_filter='users.is_delete = False')

    if recipient is None:
        raise DBUserNotExistsException

    new_message = DBMessage(
        sender_id=uid,
        message=message.message,
        recipient_id=recipient.id,
    )

    session.add_model(new_message)

    return new_message
def create_message(session: DBSession, message: RequestCreateMessageDto, uid: int) -> DBMessage:

    recipient_id = get_uid_by_login(session=session, login=message.recipient)

    new_message = DBMessage(

        sender_id=uid,
        recipient_id=recipient_id,
        message=message.message

    )

    session.add_model(new_message)

    return new_message
Exemple #18
0
def create_message(session: DBSession, message: RequestCreateMessageDto,
                   user_id: int) -> DBMessage:
    try:
        recipient_id = session.get_user_id_by_login(message.recipient)
    except Exception:
        raise DBUserNotExistsException

    new_message = DBMessage(
        message=message.message,
        sender_id=user_id,
        recipient_id=recipient_id,
    )

    session.add_model(new_message)

    return new_message
Exemple #19
0
def create_message(session: DBSession, message: RequestCreateMessageDto, sid: int) -> DBMessage:

    rid = get_employee_id_by_login(session, message.recipient)

    try:
        session.get_employee_by_id(rid)
    except DBEmployeeNotExistsException:
        raise SanicEmployeeNotFound('Employee not found')

    new_message = DBMessage(
        sender_id=sid,
        recipient_id=rid,
        message=message.message,
    )

    session.add_model(new_message)

    return new_message
Exemple #20
0
def create_user(
    session: DBSession, *, user: RequestCreateUserDto, hashed_password: bytes
) -> DBUser:
    new_user = DBUser(
        login=user.login,
        password=hashed_password,
        first_name=user.first_name,
        last_name=user.last_name,
    )

    try:
        if get_user_by_login(session, login=new_user.login):
            raise DBUserExists(new_user.login)
    except DBUserNotExists:
        pass

    session.add_model(new_user)

    return new_user
Exemple #21
0
def create_user(session: DBSession, user: RequestCreateUserDto,
                hashed_password: bytes, secret_word: bytes) -> DBUser:
    # создание модели DBUser
    new_user = DBUser(
        login=user.login,
        password=hashed_password,  # записываем в базу хэшированный пароль
        first_name=user.first_name,
        last_name=user.last_name,
        secret_word=secret_word,
    )

    # сначала попробуем получить пользователя по login перед созданием записи в БД
    # если не None, то получается, что пользователь с таким логином уже есть в БД -> рейзим исключение
    if session.get_user_by_login(new_user.login) is not None:
        raise DBUserAlreadyExistsException

    # добавляем модель в базу данных
    session.add_model(new_user)

    return new_user