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
def create_msg(session: DBSession, message: ReqCreateMsgDTO, sender_id: int) -> MessageModel: recip = get_user(session, username=message.recipient) if recip is None or recip.is_delete is True: raise DBUserNotExistsException new_msg = MessageModel( message=message.message, sender_id=sender_id, recipient_id=recip.id, ) session.add_model(new_msg) return new_msg