示例#1
0
    def save(self, ratingModel):
        if not isinstance(ratingModel, RatingModel):
            raise ValueError("ratingModel should be of type RatingModel")

        query = 'INSERT INTO Rating (id, id_Recipe, id_User, value) VALUES (%s, %s, %s, %s)'
        newItemId = db.create(query, self._mapper.to_tuple(ratingModel))
        return self.getById(newItemId)
示例#2
0
    def save(self, cartModel):
        if not isinstance(cartModel, CartModel):
            raise ValueError("cartModel should be of type cartModel")
        query = 'INSERT INTO Cart (id, id_User, totalCost) VALUES (%s, %s, %s)'
        cartId = db.create(query, self._mapper.to_tuple(cartModel))

        if cartId:
            return self.getById(cartId)
        else:
            raise Exception("Could not save cart")
示例#3
0
    def save(self, commentModel):
        if not isinstance(commentModel, CommentModel):
            raise ValueError("commentModel should be of type CommentModel")
        query = 'INSERT INTO Comment (id, id_Recipe, id_User, text) VALUES (%s, %s, %s, %s)'
        newCommandId = db.create(query, self._mapper.to_tuple(commentModel))

        if newCommandId:
            return self.getById(newCommandId)
        else:
            raise Exception("Could not save commend")
示例#4
0
    def save(self, cartItemModel):
        if not isinstance(cartItemModel, CartItemModel):
            raise ValueError("cartItemModel should be of type CartItemModel")
        query = 'INSERT INTO CartItem (id, id_Ingredient, id_Cart, multiplier, subCost) VALUES (%s, %s, %s, %s, %s)'
        newItemId = db.create(query, self._mapper.to_tuple(cartItemModel))

        if newItemId:
            return self.getById(newItemId)
        else:
            raise Exception("Could not save ingredient to cart")
示例#5
0
    def save(self, commandsModel):
        if not isinstance(commandsModel, CommandModel):
            raise ValueError("commandsModel should be of type CommandModel")

        query = 'INSERT INTO Command (id, id_Cart, creationDate, arrivalDate) VALUES (%s, %s, %s, %s)'
        newCommand = db.create(query, self._mapper.to_tuple(commandsModel))

        if newCommand:
            return self.getById(newCommand)
        else:
            raise Exception("Could not add newCommand")
示例#6
0
    def save(self, likeRecipeModel):
        if not isinstance(likeRecipeModel, LikeRecipeModel):
            raise ValueError(
                "likeRecipeModel should be of type LikeRecipeModel")
        query = 'INSERT INTO LikeRecipe (id, id_Recipe, id_User) VALUES (%s, %s, %s)'
        newLikeRecipe = db.create(query,
                                  self._mapper.to_tuple(likeRecipeModel))

        if newLikeRecipe:
            return self.getById(newLikeRecipe)
        else:
            raise Exception("Could not like this recipe")
示例#7
0
    def save(self, ingredientModel):
        if not isinstance(ingredientModel, IngredientModel):
            raise ValueError(
                "ingredientModel should be of type IngredientModel")

        query = 'INSERT INTO Ingredient (id, id_IngredientType, id_QuantityUnit, name, baseCost, baseQuantity) VALUES (%s, %s, %s, %s, %s, %s)'
        ingredientId = db.create(query, self._mapper.to_tuple(ingredientModel))

        if ingredientId:
            return self.getById(ingredientId)
        else:
            raise Exception("Could not save ingredient")
示例#8
0
    def save(self, recipeIngredientModel, autocommit=True):
        if not isinstance(recipeIngredientModel, RecipeIngredientModel):
            raise ValueError(
                "recipeIngredientModel should be of type RecipeIngredientModel"
            )
        query = 'INSERT INTO RecipeIngredient (id, id_Recipe, id_Ingredient, id_QuantityUnit, totalQuantity) VALUES (%s, %s, %s, %s, %s)'
        newRecipeId = db.create(query,
                                self._mapper.to_tuple(recipeIngredientModel),
                                autocommit=autocommit)

        if newRecipeId:
            return self.getById(newRecipeId)
        else:
            raise Exception("Could not save ingredient to cart")