Exemplo n.º 1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('idQuestion',
                            help='This field cannot be blank',
                            required=True,
                            location='headers')
        parser.add_argument('reply',
                            help='This field cannot be blank',
                            required=True)

        data = parser.parse_args()

        if Question.query.get(data['idQuestion']) is None:
            return {'message': f'Question doesn\'t exist'}

        new_reply = Reply(idQuestion=data['idQuestion'], reply=data['reply'])

        try:
            new_reply.save_to_db()
            return {'message': 'Reply was added'}
        except:
            return {'message': 'Something went wrong'}, 500