Ejemplo n.º 1
0
    def delete(self, title):

        todo = TodoModel.find_by_title(title)

        if todo:
            todo.delete_from_db()

        return {'message': 'todo deleted'}
Ejemplo n.º 2
0
    def get(self, title):

        todo = TodoModel.find_by_title(title)

        if todo:
            return todo.json()

        return {'message': 'Note was never created'}
Ejemplo n.º 3
0
    def put(self, title):
        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, **data)
        else:
            todo.content = data['content']
        todo.save_to_db()
        return todo.json()
Ejemplo n.º 4
0
    def post(self, title):
        if TodoModel.find_by_title(title):
            return {
                'message': "the todo '{}' already exists".format(title)
            }, 400

        data = Todo.parser.parse_args()

        todo = TodoModel(title, data['content'])

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

        return todo.json(), 201
Ejemplo n.º 5
0
    def put(self, title):

        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, data['description'], data['description'])
        else:
            todo.description = data['description']
            todo.category_id = data['category']

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error updating todo'}, 500

        return todo.json()
Ejemplo n.º 6
0
    def post(self, title):

        if TodoModel.find_by_title(title):
            return {
                "message":
                "A todo with the title of '{}' already exists.".format(title)
            }

        data = Todo.parser.parse_args()
        todo = TodoModel(title, data['description'], data['category'])

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error saving todo'}, 500

        return todo.json(), 201
Ejemplo n.º 7
0
 def delete(self, title):
     todo = TodoModel.find_by_title(title)
     if todo:
         todo.delete_from_db()
     return {"message": "Todo deleted"}
Ejemplo n.º 8
0
 def get(self, title):
     todo = TodoModel.find_by_title(title)
     if todo:
         return todo.json()
     return {'message': 'Todo not found.'}, 404