def handleIngredientRetrieve(self, ingredientID): db = GroceryDB() if not db.ingredientExists(ingredientID): self.handle404("Ingredient does not exist.") else: ingredient = db.getIngredient(ingredientID) self.handle200JSONResponse(ingredient)
def handleUpdateIngredient(self, ingredientID): parsedBody = self.getParsedBody() db = GroceryDB() ingredient = db.getIngredient(ingredientID) label = ingredient["label"] category = ingredient["category"] if parsedBody.get("label") != None: label = parsedBody["label"][0] if parsedBody.get("category") != None: category = parsedBody["category"][0] db.updateIngredient(label, category, ingredientID) self.handle201("Ingredient updated.")