def update_task_for_board(board_id, task_id, data):
    not_valid = validator.validate_update_task_for_board(data)
    if not_valid:
        return not_valid
    task_data = Task.query.filter_by(id=task_id,
                                     board_id=board_id,
                                     user_id=data["user_id"]).first()
    if task_data:
        if data.get("is_archived") is not None:
            task_data.is_archived = data.get("is_archived")
        if data.get("due_date"):
            task_data.due_date = datetime.datetime.strptime(
                data.get("due_date"), "%Y-%m-%d")
        if data.get("status"):
            task_data.status = data.get("status")
        if data.get("priority"):
            task_data.priority = data.get("priority")
        if data.get("title"):
            task_data.title = data['title']
        if data.get("desc"):
            task_data.desc = data['desc']
        if data.get("label"):
            labels = data.get("label")
            task_data.label_personal = "Personal" if "Personal" in labels else None
            task_data.label_work = "Work" if "Work" in labels else None
            task_data.label_shopping = "Shopping" if "Shopping" in labels else None
            task_data.label_others = "Others" if "Others" in labels else None

        task_data.update_date = datetime.datetime.utcnow()
        db.session.commit()
        return get_response(200, "{} task updated.".format(task_data.title),
                            []), 200
    else:
        return get_response(404, "{} task didn't found.".format(task_id),
                            []), 404
def archive_task_for_board(board_id, task_id, data):
    task_data = Task.query.filter_by(id=task_id,
                                     board_id=board_id,
                                     user_id=data["user_id"]).first()
    if task_data:
        task_data.is_archived = True
        db.session.commit()
        return get_response(200, "{} task archived.".format(task_data.title),
                            []), 200
    else:
        return get_response(404, "{} task didn't found.".format(task_id),
                            []), 404
def get_filtered_task(board_id, data):
    query = Task.query.filter_by(board_id=board_id,
                                 user_id=data["user_id"],
                                 is_archived=False)
    if data.get("status"):
        query = query.filter_by(status=data["status"])

    if data.get("priority"):
        query = query.filter_by(priority=data["priority"])
    if data.get("query"):
        query = query.filter((Task.title.like("%{}%".format(data["query"])))
                             | (Task.desc.like("%{}%".format(data["query"]))))
    if data.get("to") and data.get("from"):
        to_date = datetime.datetime.strptime(data.get("to"), "%Y-%m-%d")
        from_date = datetime.datetime.strptime(data.get("from"), "%Y-%m-%d")
        query = query.filter(Task.due_date.between(from_date, to_date))

    if data.get("label"):
        label = data["label"]
        if label == "Personal":
            query = query.filter_by(label_personal=label)
        if label == "Work":
            query = query.filter_by(label_work=label)
        if label == "Shopping":
            query = query.filter_by(label_shopping=label)
        if label == "Others":
            query = query.filter_by(label_others=label)
    print(query)
    task_data = query.all()
    task_details_list = map_task_data(task_data)
    return get_response(200, "", task_details_list), 200
def get_all_boards(data):
    not_valid = validator.validate_get_all_boards(data)
    if not_valid:
        return not_valid
    board_data = Board.query.filter_by(user_id=data['user_id']).all()
    board_details_list = map_board_data(board_data)
    return get_response(200, "", board_details_list), 200
def add_board(data):
    not_valid = validator.validate_add_board(data)
    if not_valid:
        return not_valid
    new_board = Board(name=data['name'], user_id=data['user_id'])
    save_changes(new_board)
    return get_response(200, "{} board created".format(data['name']), []), 200
def delete_board(board_id, data):
    not_valid = validator.validate_delete_board(data)
    if not_valid:
        return not_valid
    Task.query.filter_by(user_id=data['user_id'], board_id=board_id).delete()
    Board.query.filter_by(user_id=data['user_id'], id=board_id).delete()
    db.session.commit()
    return get_response(200, "Deleted Board", []), 200
def get_task(board_id, task_id, data):
    task_data = Task.query.filter_by(id=task_id,
                                     board_id=board_id,
                                     user_id=data["user_id"]).all()
    task_details_list = map_task_data(task_data)
    data = []
    if task_details_list:
        data = task_details_list[0]

    return get_response(200, "", data), 200
Esempio n. 8
0
def add_task_for_board(board_id, data):
    new_task = Task(title=data['title'],
                    board_id=board_id,
                    user_id=data['user_id'],
                    status=data['status'],
                    desc=data.get('desc'),
                    priority=data.get('priority'),
                    creation_date=datetime.datetime.utcnow(),
                    update_date=datetime.datetime.utcnow())
    save_changes(new_task)
    return get_response(200, "{} task created".format(data['title']), []), 200
def get_board(board_id, data):
    not_valid = validator.validate_get_board(data)
    if not_valid:
        return not_valid
    task_data = Task.query.filter_by(user_id=data['user_id'],
                                     board_id=board_id,
                                     is_archived=False).all()
    task_details_list = map_task_data(task_data)
    data = {
        "tasks": task_details_list,
        "label": get_label(),
        "priority": get_priority(),
        "task_status": get_status()
    }
    return get_response(200, "", data), 200
def add_task_for_board(board_id, data):
    not_valid = validator.validate_add_task(data)
    if not_valid:
        return not_valid
    labels = data.get("label") if data.get("label") else []
    new_task = Task(
        title=data['title'],
        board_id=board_id,
        user_id=data['user_id'],
        status=data['status'],
        desc=data.get('desc'),
        label_personal="Personal" if "Personal" in labels else None,
        label_work="Work" if "Work" in labels else None,
        label_shopping="Shopping" if "Shopping" in labels else None,
        label_others="Others" if "Others" in labels else None,
        priority=data.get('priority'),
        creation_date=datetime.datetime.utcnow(),
        update_date=datetime.datetime.utcnow(),
        due_date=datetime.datetime.strptime(data.get("due_date"), "%Y-%m-%d")
        if data.get('due_date') else None)
    save_changes(new_task)
    return get_response(200, "{} task created".format(data['title']), []), 200
def get_all_priority():
    priority = get_priority()
    return get_response(200, "", priority)
def get_all_status():
    status = get_status()
    return get_response(200, "", status)
def get_all_label():
    labels = get_label()
    return get_response(200, "", labels)