def update_task(id_task): if request.method == "POST": # query for check id task query_db = db.read("tasks", "id", id_task) task = query_db[0] if len(query_db) == 1 else None if task == None: return jsonify(error(404, "Task not exists")) else: json = request.get_json() id = task["id"] title = json["title"] description = json["description"] date = task["date"] id_list = task["id_list"] status = json["status"] task = Task( id=id, id_list=id_list, title=title, description=description, date=date, status=status, ) if db.update("tasks", id_task, task.to_dict()): return jsonify(task.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def delete_list(id_list): if request.method == "DELETE": # query for check list query_db = db.read("lists", "id", id_list) list_user = query_db[0] if len(query_db) == 1 else None if list_user == None: return jsonify(error(404, "List not exists")) else: if db.delete("lists", id_list): # delete all tasks tasks = db.read("tasks", "id_list", id_list) if len(tasks) > 0: for task in tasks: db.delete("tasks", task["id"]) return jsonify(error(200, "Removed")) else: return jsonify(error(400, "Not removed"))
def delete_task(id_task): if request.method == "DELETE": # query for check task query_db = db.read("tasks", "id", id_task) task = query_db[0] if len(query_db) == 1 else None if task == None: return jsonify(error(404, "Task not exists")) else: if db.delete("tasks", id_task): return jsonify(error(200, "Removed")) else: return jsonify(error(400, "Not removed"))
def update_list(id_list): if request.method == "POST": # query for check username query_db = db.read("lists", "id", id_list) list_user = query_db[0] if len(query_db) == 1 else None if list_user == None: return jsonify(error(404, "List not exists")) else: json = request.get_json() id = list_user["id"] title = json["title"] date = list_user["date"] id_user = list_user["id_user"] link = list_user["link"] list_user = List(id, id_user, title, date) if db.update("lists", id_list, list_user.to_dict()): return jsonify(list_user.to_dict()) else: return jsonify(error(203, "Not Allowed"))
def get_list(id_list): return jsonify(db.read("lists", "id", id_list))
def get_lists_by_user(id_user): return jsonify(db.read("lists", "id_user", id_user))
def get_tasks_by_list(id_list): return jsonify(db.read("tasks", "id_list", id_list))
def get_task(id_task): return jsonify(db.read("tasks", "id", id_task))