コード例 #1
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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)
コード例 #2
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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)
コード例 #3
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def signup_route():
  body = request.get_json(force=True)

  user = address = account = None

  try:
    user = body['user']
  except Exception as e:
    print(e)
    return response.error('user field cannot be empty', status=400)
  
  try:
    address = body['address']
  except Exception as e:
    print(e)
    return response.error('address field cannot be empty', status=400)
    
  try:
    account = body['account']
  except:
    print(e)
    return response.error('account field cannot be empty', status=400)

  try:
    result = signup.register(user, address, account)
    return response.success(result)
  except ValueError as e:
    print(e)
    return response.error(e, status=400)
  except Exception as e:
    raise e
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def getRecipeComments(recipe_id):
  comments = commentDao.getRecipeComments(recipe_id)
  data = []
  for comment in comments:
    user = userDao.getById(comment.id_User)
    data.append({
      **comment.serialize(),
      'user': user.serialize()
    })
  return response.success(data)
コード例 #13
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def getRecipeById(recipe_id):
  recipe = recipeDao.getById(recipe_id)
  user = userDao.getById(recipe.id_User)
  data = {
    **recipe.serialize(),
    'user': {
      **user.serialize()
    }
  }
  return response.success(data)
コード例 #14
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()
    })
コード例 #15
0
def getLikeRecipes(id):
    recipes = []
    likes = likeRecipeDao.getLikeRecipeByUser(id)
    for like in likes:
        recipe = recipeDao.getById(like.id_Recipe)
        recipes.append({
            'id': recipe.id,
            'name': recipe.name,
            'description': recipe.description
        })

    return response.success(recipes)
コード例 #16
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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)
コード例 #17
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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)
コード例 #18
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def getIngredientsByRecipe(recipe_id):
  data = []
  recipeIngredients = recipeIngredientDao.getIngredientsByRecipe(recipe_id)
  for recipeIngredient in recipeIngredients:
    ingredient = ingredientDao.getById(recipeIngredient.id_Ingredient)
    quantityUnit = quantityUnitDao.getById(recipeIngredient.id_QuantityUnit)
    data.append({
      'id': ingredient.id,
      'name': ingredient.name,
      'quantityUnit': quantityUnit.serialize(),
      'totalQuantity': recipeIngredient.totalQuantity
    })

  return response.success(data)
コード例 #19
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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)
コード例 #20
0
ファイル: controller.py プロジェクト: xchsp/Cooky
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()
コード例 #21
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)
コード例 #22
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def index():
    populated_ingredients = []
    ingredients = []

    search_name = request.args.get('name')
    if (search_name):
        ingredients = ingredientDao.getIngredientsByName(search_name)
    else:
        ingredients = ingredientDao.getAll()

    for ingredient in ingredients:
        quantity_unit = quantityUnitDao.getById(ingredient.id_QuantityUnit)
        quantity = str.format('{} {}', int(ingredient.baseQuantity),
                              quantity_unit.abbreviation)
        populated_ingredients.append({
            'id': ingredient.id,
            'name': ingredient.name,
            'quantity': quantity,
            'price': ingredient.baseCost
        })
    return response.success(populated_ingredients)
コード例 #23
0
def index():
    return response.success(userDao.getAll())
コード例 #24
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)
コード例 #25
0
def getUserCart(id):
    response.ensureIdentity(id, current_identity)

    data = cartDao.getCurrentUserCart(id)
    return response.success(data)
コード例 #26
0
def getCart(id):
    cart = cartDao.getById(id)
    response.ensureIdentity(cart.id_User, current_identity)

    return response.success(cart)
コード例 #27
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def getMesures(id):
    quantityUnits = quantityUnitDao.getAllQuantityUnitsByIngredientId(id)
    return response.success(quantityUnits)
コード例 #28
0
def getRatings(id):
    response.ensureIdentity(id, current_identity)

    data = ratingDao.getRatingsByUser(id)
    return response.success(data)
コード例 #29
0
ファイル: controller.py プロジェクト: xchsp/Cooky
def index():
  searched_name = request.args.get('name')
  if (searched_name):
    return response.success(recipeDao.getRecipesByName(searched_name))
  else:
    return response.success(recipeDao.getAll())
コード例 #30
0
def getAddress(id):
    response.ensureIdentity(id, current_identity)

    userData = accountDao.getAccountByUserId(id)
    address = userData.id_Address
    return response.success(addressDao.getAddress(address))