def getToDoItem(toDoId): try: toDo = ToDo.find_by_id(int(toDoId)) if toDo is None: return BadRequest("No ToDo matches id {}".format(toDoId)) return json.dumps(toDo.json()) except Exception: return InternalServerError("Something went wrong!")
def deleteToDoItem(toDoId): try: toDo = ToDo.find_by_id(int(toDoId)) if toDo is None: return BadRequest("No ToDo matches id {}".format(toDoId)) toDo.delete_from_db() return Response("ToDo with id {} successfully deleted".format(toDo.id), status=201) except Exception: return InternalServerError("Something went wrong!")
def updateToDoItem(toDoId): try: toDo = ToDo.find_by_id(toDoId) if toDo is None: return BadRequest("No ToDo matches id {}".format(toDoId)) body = request.json toDo.name = body.get("name") toDo.description = body.get("description") toDo.save_to_db() toDo.delete_tasks() tasks = body.get("tasks") for task in tasks: tsk = Task(name=task.get("name"), toDoId=toDo.id, description=task.get("description")) tsk.save_to_db() return Response("ToDo with id {} successfully updated".format(toDo.id), status=201) except Exception: return InternalServerError("Something went wrong")