def delete(self, title): todo = TodoModel.find_by_title(title) if todo: todo.delete_from_db() return {'message': 'todo deleted'}
def get(self, title): todo = TodoModel.find_by_title(title) if todo: return todo.json() return {'message': 'Note was never created'}
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()
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
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()
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
def delete(self, title): todo = TodoModel.find_by_title(title) if todo: todo.delete_from_db() return {"message": "Todo deleted"}
def get(self, title): todo = TodoModel.find_by_title(title) if todo: return todo.json() return {'message': 'Todo not found.'}, 404