Beispiel #1
0
 def handleAddRecipeIngredient(self):
     db = GroceryDB()
     parsedBody = self.getParsedBody()
     ingredientID = -1
     recipeID = -1
     if parsedBody.get("ingredient_id") != None:
         ingredientID = parsedBody["ingredient_id"][0]
     if parsedBody.get("recipe_id") != None:
         recipeID = parsedBody["recipe_id"][0]
     if not db.ingredientExists(ingredientID) or not db.recipeExists(
             recipeID):
         self.handle404("Ingredient or recipe does not exist.")
     elif db.recipeIngredientExists(recipeID, ingredientID):
         self.handle422("Recipe ingredient already exists.")
     else:
         quantity = "1"
         quantityType = ""
         if parsedBody.get("quantity") != None:
             tempQuantity = parsedBody["quantity"][0]
             if isValidQuantityString(tempQuantity):
                 quantity = parseQuantityString(tempQuantity)
         if parsedBody.get("quantity_type") != None:
             quantityType = parsedBody["quantity_type"][0]
         db.addIngredientToRecipe(recipeID, ingredientID, quantity,
                                  quantityType)
         self.handle201("Recipe ingredient added.")
Beispiel #2
0
 def handleDeleteRecipeIngredient(self, queryString):
     db = GroceryDB()
     parsedQs = parse_qs(queryString)
     parsedBody = self.getParsedBody()
     ingredientID = -1
     recipeID = -1
     if parsedBody.get("ingredient_id") != None:
         ingredientID = parsedBody["ingredient_id"][0]
     if parsedBody.get("recipe_id") != None:
         recipeID = parsedBody["recipe_id"][0]
     if parsedQs.get("ingredient_id") != None:
         ingredientID = parsedQs["ingredient_id"][0]
     if parsedQs.get("recipe_id") != None:
         recipeID = parsedQs["recipe_id"][0]
     if not db.recipeIngredientExists(recipeID, ingredientID):
         print(recipeID, ingredientID)
         self.handle404("Recipe ingredient does not exist.")
     else:
         db.deleteRecipeIngredient(recipeID, ingredientID)
         self.handle200("Recipe ingredient successfully deleted")
Beispiel #3
0
 def handleUpdateRecipeIngredient(self):
     db = GroceryDB()
     parsedBody = self.getParsedBody()
     ingredientID = -1
     recipeID = -1
     if parsedBody.get("ingredient_id") != None:
         ingredientID = parsedBody["ingredient_id"][0]
     if parsedBody.get("recipe_id") != None:
         recipeID = parsedBody["recipe_id"][0]
     if not db.recipeIngredientExists(recipeID, ingredientID):
         self.handle404("Recipe ingredient does not exist.")
     else:
         recipeIngredient = db.getRecipeIngredient(recipeID, ingredientID)
         quantity = recipeIngredient["quantity"]
         quantityType = recipeIngredient["quantity_type"]
         if parsedBody.get("quantity") != None:
             tempQuantity = parsedBody["quantity"][0]
             if isValidQuantityString(tempQuantity):
                 quantity = parseQuantityString(tempQuantity)
         if parsedBody.get("quantity_type") != None:
             quantityType = parsedBody["quantity_type"][0].strip()
         db.updateRecipeIngredient(recipeID, ingredientID, quantity,
                                   quantityType)
         self.handle201("Recipe ingredient updated.")