コード例 #1
0
def getToDos():
    try:
        toDos = ToDo.find_all()
        resp = [toDo.json() for toDo in toDos]
        return json.dumps(resp)
    except Exception:
        return InternalServerError("Something went wrong!")
コード例 #2
0
ファイル: todo.py プロジェクト: VinceWetz/cc-to-do-list
 def post(self, list_id):
     data = request.get_json()
     data["todoId"] = random.randint(1, 99999999999)
     data["listId"] = list_id
     post_user = ToDo(**data).save()
     output = post_user
     return generate_json_response(result=output)
コード例 #3
0
def createToDo():
    try:
        body = request.json
        name = body.get("name")
        description = body.get("description")
        tasks = body.get("tasks")
        toDo = ToDo(name=name, description=description)
        toDo.save_to_db()
        taskList = []
        for task in tasks:
            tsk = Task(name=task.get("name"), toDoId=toDo.id, description=task.get("description"))
            tsk.save_to_db()
            taskList.append(tsk)
        return Response("Created ToDo with id {}".format(toDo.id), status=201)
    except Exception:
        return InternalServerError("Something went wrong")
コード例 #4
0
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!")
コード例 #5
0
ファイル: todo.py プロジェクト: VinceWetz/cc-to-do-list
 def post(self, list_id, todo_id):
     data = request.get_json()
     data["listId"] = list_id
     data["todoId"] = todo_id
     if "_id" in data:
         del data["_id"]
     post_user = ToDo.objects(todoId=todo_id, listId=list_id).update(**data)
     output = post_user
     return generate_json_response(result=output)
コード例 #6
0
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!")
コード例 #7
0
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")
コード例 #8
0
ファイル: todo.py プロジェクト: VinceWetz/cc-to-do-list
 def post(self, list_id, todo_id):
     output = {
         'listId': ToDo.objects(todoId=todo_id, listId=list_id).delete()
     }
     return generate_json_response(result=output)
コード例 #9
0
ファイル: todo.py プロジェクト: VinceWetz/cc-to-do-list
 def get(self, list_id):
     output = ToDo.objects(listId=list_id)
     return generate_json_response(result=output)