Exemplo n.º 1
0
 def delete(self, idea_id):
     user_id = get_jwt_identity()
     idea = Idea.get_idea(idea_id)
     if idea.user_id == user_id:
         db.session.delete(idea)
         db.session.commit()
         return None, 204
     return {"error": "User not authorized to delete the idea"}, 400
Exemplo n.º 2
0
    def put(self, idea_id):
        data = request.get_json()
        if not are_idea_params_valid(**data):
            return {
                "error":
                "Input parameters not valid. Scores should be between 1 and 10"
            }, 400
        user_id = get_jwt_identity()
        idea = Idea.get_idea(idea_id)
        if user_id != idea.user_id:
            return {"error": "User not authorized to update the idea"}, 400
        idea.update_idea(**data)

        return idea.get_idea_json(), 200