Ejemplo n.º 1
0
    def put(self, id):
        data = request.get_json()

        todoList = TodoList.get_by_id(id)

        if todoList is None:
            task_lst = []
            for task in data['tasks']:
                obj = Task(task_name=task['task_name'],
                           task_done=task['task_done'])
                task_lst.append(obj)

            todoList = TodoList(
                todoList_name=data['todoList_name'],
                todoList_done=data['todoList_done'],
            )
            todoList.tasks = task_lst

            todoList.save()

            return {'message': 'Successfully saved new data'}, 201
        else:
            todoList.todoList_name = data['todoList_name']
            todoList.todoList_done = data['todoList_done']
            for t in data['tasks']:
                task = Task.query.get(t['taskID'])
                task.task_name = t['task_name']
                task.task_done = t['task_done']

            todoList.save()
            return {'message': 'Updated data with '}
Ejemplo n.º 2
0
    def post(self):
        data = request.get_json()

        task_lst = []
        for task in data['tasks']:
            obj = Task(task_name=task['task_name'],
                       task_done=task['task_done'])
            task_lst.append(obj)

        todoList = TodoList(
            todoList_name=data['todoList_name'],
            todoList_done=data['todoList_done'],
        )
        todoList.tasks = task_lst

        todoList.save()

        return {'message': 'Successfully saved new data'}, 201
Ejemplo n.º 3
0
    def put(self, list_id):
        data = request.get_json()

        user = User.find_by_id(get_jwt_identity())

        todoList = TodoList.query.filter(and_(TodoList.id == list_id, TodoList.user_id == user.userID)).first()

        if todoList is None:
            task_lst = []
            for task in data['tasks']:
                obj = Task(
                    task_name=task['task_name'],
                    task_done=task['task_done']
                    )
                task_lst.append(obj)

            todoList = TodoList(
                todoList_name=data['todoList_name'],
                todoList_done=data['todoList_done'],
                user_id=user.userID
            )
            todoList.tasks = task_lst

            todoList.save()

            return {'message': 'Successfully saved new data'}, 201
        else:
            todoList.todoList_name = data['todoList_name']
            todoList.todoList_done = data['todoList_done']
            for t in data['tasks']:
                if t['id'] is "":
                    task = Task(
                        task_name=t['task_name'],
                        task_done=t['task_done']
                    )
                    todoList.tasks.append(task)
                else:
                    task = Task.get_by_id(t['id'])
                    task.task_name = t['task_name']
                    task.task_done = t['task_done']


            todoList.save()
            return {'message': 'Updated data'}
Ejemplo n.º 4
0
    def post(self):
        data = request.get_json()

        user = User.find_by_id(get_jwt_identity())


        task_lst = []
        for task in data['tasks']:
            obj = Task(
                task_name=task['task_name'],
                task_done=task['task_done']
                )
            task_lst.append(obj)

        todoList = TodoList(
            todoList_name=data['todoList_name'],
            todoList_done=data['todoList_done'],
            user_id=user.userID
        )
        todoList.tasks = task_lst

        todoList.save()

        return {'message': 'Successfully saved new data'}, 201