def get_items(): c = DatabaseConnection() itemid = int(request.args.get("itemid", 0)) if itemid: item = c.get_item(itemid) if not item: return {"err": "item does not exist"}, 409 return {"item": c.get_item(itemid)}, 200 listid = int(request.args.get("listid", 0)) return {"items": c.get_items(listid)}, 200
def modify_item(): j = request.get_json() c = DatabaseConnection() auth = check_auth(j, c) if auth: return auth itemid = j.get("itemid", 0) if not itemid: return {"err": "itemid must not be empty"}, 400 user = c.get_user(username=j["username"]) item = c.get_item(itemid) if not item: return {"err": "item does not exist"}, 400 l = c.get_list(item["listid"]) if l["userid"] != user["id"]: return {"err": "item does not belong to user"}, 409 # deleting item if request.path == "/api/deleteitem": c.delete_item(itemid) return {"msg": "successfully deleted item"}, 200 # updating item elif request.path == "/api/updateitem": if not c.update_item(itemid, j): return {"err": "attempted to give item duplicate name"}, 409 return {"msg": "successfully updated item"}, 200 return {"err": "invalid method used"}, 405