Beispiel #1
0
    def put(self, id):
        id = TodoModel.is_valid_id(id)
        data = Todo.parser.parse_args()

        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)

        current_user = current_identity

        if not todo:
            todo = TodoModel(id, current_user.username, data['text'], False)
            todo.save_to_db()
            return {'message': 'Saved a new todo'}, 201

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        todo.text = data.text
        todo.done = data.done

        todo.save_to_db()

        return {'message': 'updated'}
Beispiel #2
0
    def delete(self, id):
        todo = TodoModel.find_by_id(id)

        if todo:
            if current_identity.id == todo.user_id:
                todo.delete_from_db()
                return {'message': 'Todo deleted'}
            else:
                return {'message': 'Sorry, this todo was not created by you.'}
        return {'message': 'Todo does not exist.'}
Beispiel #3
0
 def put(self, id):
     data = Todo.parser.parse_args()
     todo = TodoModel.find_by_id(id)
     if todo:
         if current_identity.id == todo.user_id:
             todo.desc = data['desc']
             todo.done = data['done']
             todo.save_to_db()
             return todo.json()
         else:
             return {'message': 'Sorry, this todo was not created by you.'}
     else:
         return {'message': 'Todo not found'}, 404
Beispiel #4
0
    def put(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            data = self.parser.parse_args()

            todo.description = data['description']
            todo.done = data['done']
            todo.createdAt = data['createdAt']

            todo.save_to_db()

            return todo.json()

        return {'message': 'Todo not found'}, 404
Beispiel #5
0
    def get(self, id):
        id = TodoModel.is_valid_id(id)

        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)

        if not todo:
            return {'message': 'todo was not found'}, 404

        current_user = current_identity

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        return todo.json()
Beispiel #6
0
    def delete(self, id):
        id = TodoModel.is_valid_id(id)
        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)
        if not todo:
            return {'message': 'todo was not found'}, 400

        current_user = current_identity

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        try:
            todo.delete_from_db()
        except:
            return {'message': 'something went wrong'}, 500

        return {'message': 'Deleted'}, 200
Beispiel #7
0
    def delete(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            todo.delete_from_db()
        return {'message': 'Todo deleted'}
Beispiel #8
0
    def get(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            return todo.json()
        return {'message': 'Todo not found'}, 404