Skip to content
Snippets Groups Projects

Add to shopping list from recipe convert amount fix

Merged Axel Ytterås requested to merge AddToShoppingListFromRecipeConvertAmountFix into main
3 files
+ 58
8
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -332,10 +332,22 @@ public class ShoppingListService {
}
double quantityToAddOfWare = ingredientAmountNotOwned/itemAmount;
if (quantityToAddOfWare > 0) {
Ingredient shoppingListIngredient = new Ingredient(ingredient.getItem(), new Amount(Math.ceil(quantityToAddOfWare), Count.COUNT).serialize());
shoppingListIngredient.setStatus(Ingredient.Status.REQUESTED);
ingredientRepository.save(shoppingListIngredient);
shoppingList.addIngredient(shoppingListIngredient);
//check if it exists first if so add to that request instead
boolean alreadyRequested = false;
for (Ingredient ingredient1: shoppingList.getIngredientList()) {
if (ingredient1.getStatus() == Ingredient.Status.REQUESTED && Objects.equals(ingredient1.getItem().getId(), ingredient.getItem().getId())) {
ingredient1.getAmount().setQuantity(ingredient1.getAmount().getQuantity() + Math.ceil(quantityToAddOfWare));
alreadyRequested = true;
}
}
//otherwise
if (!alreadyRequested) {
Ingredient shoppingListIngredient = new Ingredient(ingredient.getItem(), new Amount(Math.ceil(quantityToAddOfWare), Count.COUNT).serialize());
shoppingListIngredient.setStatus(Ingredient.Status.REQUESTED);
ingredientRepository.save(shoppingListIngredient);
shoppingList.addIngredient(shoppingListIngredient);
}
}
});
return shoppingListRepository.save(shoppingList);
Loading