コード例 #1
0
ファイル: employee.py プロジェクト: iparinile/sanic_project
def get_employee(session: DBSession, *, login: str = None, employee_id: int = None) -> DBEmployee:
    db_employee = None

    if login is not None:
        db_employee = session.get_employee_by_login(login)
    elif employee_id is not None:
        db_employee = session.get_employee_by_id(employee_id)

    if db_employee is None:
        raise DBEmployeeNotExistsException
    return db_employee
コード例 #2
0
ファイル: message.py プロジェクト: RedPowDan/ProjectNIT
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
コード例 #3
0
ファイル: employee.py プロジェクト: NailNaMeste/messenger
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
コード例 #4
0
ファイル: message.py プロジェクト: NailNaMeste/messenger
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