Beispiel #1
0
def modifyIngredientQuantity(recipe_id):
  recipe = recipeDao.getById(recipe_id)
  response.ensureIdentity(recipe.id_User, current_identity)

  body = request.get_json(force=True)
  result = recipeIngredientDao.modifyQuantity(recipe_id, body['id_Ingredient'], body['totalQuantity'])
  return response.success(result)
Beispiel #2
0
def modifyRecipeDirective(recipe_id):
  recipe = recipeDao.getById(recipe_id)
  response.ensureIdentity(recipe.id_User, current_identity)

  body = request.get_json(force=True)
  result = recipeDao.modifyRecipeDirective(body['directives'], recipe_id)
  return response.success(result)
Beispiel #3
0
def modifyCountry(id):
    response.ensureIdentity(id, current_identity)

    userData = accountDao.getAccountByUserId(id)
    addressId = userData.id_Address
    body = request.get_json(force=True)
    data = addressDao.modifyCountry(body['country'], addressId)
    return response.success(data)
Beispiel #4
0
def modifyRecipeName(id_Cart, id_Ingredient):
    cart = cartDao.getById(id_Cart)
    response.ensureIdentity(cart.id_User, current_identity)

    body = request.get_json(force=True)
    result = cartItemDao.modifyQuantity(body['multiplier'], id_Cart,
                                        id_Ingredient)
    return response.success(result)
Beispiel #5
0
def createCommand(id):
    cart = cartDao.getById(id)
    response.ensureIdentity(cart.id_User, current_identity)

    data = {'id_Cart': id, 'creationDate': datetime.now()}
    commandModel = CommandModel(**data)
    data = commandsDao.save(commandModel)
    return response.success(data)
Beispiel #6
0
def addItemToCart(id):
    cart = cartDao.getById(id)
    response.ensureIdentity(cart.id_User, current_identity)

    body = request.get_json(force=True)
    data = {'id_Ingredient': body['id_Ingredient'], 'id_Cart': id}
    cartItemModel = CartItemModel(**data)
    result = cartItemDao.save(cartItemModel)
    return response.success(result)
Beispiel #7
0
def modifyPassword(id):
    response.ensureIdentity(id, current_identity)

    body = request.get_json(force=True)
    try:
        accountDao.modifyPassword(body['password'], id)
        return response.success('')
    except Exception as e:
        return response.error(e)
Beispiel #8
0
def modifyEmail(id):
    response.ensureIdentity(id, current_identity)

    body = request.get_json(force=True)
    try:
        result = accountDao.modifyEmail(body['email'], id)
        return response.success(result)
    except Exception as e:
        return response.error(e)
Beispiel #9
0
def getUserCommands(id):
    response.ensureIdentity(id, current_identity)

    commands = commandDao.getUserCommands(id)
    data = []
    for command in commands:
        cart = cartDao.getById(command.id_Cart)
        data.append({**command.serialize(), 'totalCost': cart.totalCost})
    return response.success(data)
Beispiel #10
0
def getAccount(id):
    response.ensureIdentity(id, current_identity)

    account = accountDao.getAccountByUserId(id)
    del account.password
    address = addressDao.getById(account.id_Address)
    return response.success({
        **account.serialize(), 'address':
        address.serialize()
    })
Beispiel #11
0
def addRecipe():
  body = request.get_json(force=True)
  data = {
    'id_User': body['id_User'],
    'name': body['name'],
    'directives': body['directives']
  }

  response.ensureIdentity(data['id_User'], current_identity)

  recipeModel = RecipeModel(**data)
  result = recipeDao.save(recipeModel, body['ingredients'])
  return response.success(result)
Beispiel #12
0
def addCommentRecipe(recipe_id):
  body = request.get_json(force=True)
  data = {
    'id_Recipe': recipe_id,
    'id_User': body['id_User'],
    'text': body['text']
  }

  response.ensureIdentity(data['id_User'], current_identity)

  commentModel = CommentModel(**data)
  result = commentDao.save(commentModel)
  return response.success(result)
Beispiel #13
0
def addRateRecipe(recipe_id):
  body = request.get_json(force=True)
  data = {
    'id_Recipe': recipe_id,
    'id_User': body['id_User'],
    'value': body['value']
  }

  response.ensureIdentity(data['id_User'], current_identity)

  ratingModel = RatingModel(**data)
  if request.method == 'POST':
    result = ratingDao.save(ratingModel)
  else:
    result = ratingDao.replace(ratingModel)
  return response.success(result)
Beispiel #14
0
def getCartItems(id):
    cart = cartDao.getById(id)
    response.ensureIdentity(cart.id_User, current_identity)

    cartItems = cartItemDao.getItemsByCart(id)
    data = []
    for cartItem in cartItems:
        ingredient = ingredientDao.getById(cartItem.id_Ingredient)
        quantity_unit = quantityUnitDao.getById(ingredient.id_QuantityUnit)
        quantity = str.format('{} {}', int(ingredient.baseQuantity),
                              quantity_unit.abbreviation)
        data.append({
            **cartItem.serialize(), 'name': ingredient.name,
            'baseCost': ingredient.baseCost,
            'quantity': quantity
        })
    return response.success(data)
Beispiel #15
0
def likeRecipe(recipe_id):
  body = request.get_json(force=True)
  data = {
    'id_Recipe': recipe_id,
    'id_User': body['id_User']
  }

  response.ensureIdentity(data['id_User'], current_identity)

  likeRecipeModel = LikeRecipeModel(**data)

  if request.method == 'POST':
    result = likeRecipeDao.save(likeRecipeModel)
    return response.success(result)
  else:
    likeRecipeDao.delete(likeRecipeModel)
    return response.empty()
Beispiel #16
0
def modifyCity(id):
    if not response.ensureIdentity(id, current_identity):
        return response.error('Access forbidden', status=401)

    userData = accountDao.getAccountByUserId(id)
    addressId = userData.id_Address
    body = request.get_json(force=True)
    data = addressDao.modifyCity(body['city'], addressId)
    return response.success(data)
Beispiel #17
0
def getRatings(id):
    response.ensureIdentity(id, current_identity)

    data = ratingDao.getRatingsByUser(id)
    return response.success(data)
Beispiel #18
0
def getAddress(id):
    response.ensureIdentity(id, current_identity)

    userData = accountDao.getAccountByUserId(id)
    address = userData.id_Address
    return response.success(addressDao.getAddress(address))
Beispiel #19
0
def deleteItemFromCart(id_Cart, id_Ingredient):
    cart = cartDao.getById(id_Cart)
    response.ensureIdentity(cart.id_User, current_identity)

    cartItemDao.deleteIngredient(id_Cart, id_Ingredient)
    return response.success("", status=204)
Beispiel #20
0
def getCart(id):
    cart = cartDao.getById(id)
    response.ensureIdentity(cart.id_User, current_identity)

    return response.success(cart)
Beispiel #21
0
def deleteRecipe(recipe_id):
  recipe = recipeDao.getById(recipe_id)
  response.ensureIdentity(recipe.id_User, current_identity)

  recipeDao.delete(recipe_id)
  return response.empty()
Beispiel #22
0
def getUserCart(id):
    response.ensureIdentity(id, current_identity)

    data = cartDao.getCurrentUserCart(id)
    return response.success(data)