Esempio n. 1
0
    def post(self, channel_name):

        channel_id = ChannelModel.find_id_by_name(channel_name)

        if channel_id:
            random_data = randomData()
            message_id = hashData(str(random_data))

            if MessageModel.find_msg_by_channel_id_msg_id(
                    channel_id, message_id):
                return {'message': 'Bad message id'}, 400

            data = Message.parser.parse_args()
            date_now = datetime.utcnow()

            user_id = get_jwt_identity()
            user = UserModel.find_by_id(user_id)
            print(user.username)
            message = MessageModel(message_id, channel_id, data['content'],
                                   date_now, user.username,
                                   UserModel.get_avatar(user.username))

            message.save_to_db()
            return message.json(), 201
        else:

            return {'message': 'Channel not exist.'}, 404
Esempio n. 2
0
 def post(self):
     data = _message_parser.parse_args()
     data['sender'] = UserModel.find_by_id(get_jwt_identity()).username
     if UserModel.find_by_username(data['receiver']) is None:
         return {"error": f"The user {data['receiver']} does not exist."}
     message = MessageModel(data['sender'], data['receiver'],
                            data['message'], data['subject'])
     message.save_to_db()
     return message.json()
Esempio n. 3
0
 def post(self):
     user = current_identity
     request_data = Message.parser.parse_args()
     message = MessageModel(user.id, **request_data)
     try:
         message.save_to_db()
     except:
         return {"message": "Internal error occurred."}, 500
     return message.json(), 201
Esempio n. 4
0
    def post(self):
        data = Message.parser.parse_args()

        messageing = MessageModel(**data)

        try:
            messageing.save_to_db()
        except:
            return {"message": "An error occurred inserting the message."}, 500

        return messageing.json(), 201
Esempio n. 5
0
 def post(self, team_id):
     # Set data for the message before it gets placed into the database
     data = Message.parser.parse_args()
     created_at = time.time()
     created_by_user = current_identity.username
     msg_to_save = MessageModel(self.random_id(13), data['message'],
                                data['team_id'], created_at,
                                created_by_user)
     try:
         msg_to_save.save_to_db()
     except Exception as e:
         print e
         return {"message": "An error occurred inserting the message."}, 500
     #Will desplay message
     return msg_to_save.json(), 201
Esempio n. 6
0
    def post(self, name):
        if MessageModel.find_by_name(name):
            return {
                'message':
                "An item with name '{}' already exists.".format(name)
            }, 400

        data = Message.parser.parse_args()

        message = MessageModel(name, data['avatar'], data['date'],
                               data['header'], data['content'])

        try:
            message.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return message.json(), 201
Esempio n. 7
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument(consts.RECEIVER_ID,
                            type=str,
                            required=True,
                            help="This field cannot be blank.")
        parser.add_argument(consts.CONTENT,
                            type=str,
                            required=True,
                            help="This field cannot be blank.")

        data = parser.parse_args()

        message = MessageModel(get_jwt_identity(), data[consts.RECEIVER_ID],
                               data[consts.CONTENT], datetime.utcnow())
        message.save_to_db()

        return message.json(), 201