diff --git a/models/de-DE.json b/models/de-DE.json
index 455ed89..8e3253c 100644
--- a/models/de-DE.json
+++ b/models/de-DE.json
@@ -137,17 +137,19 @@
{
"name": "ModifyRecipeByUnitsIntent",
"slots": [
+ {
+ "name": "Ingredient_Value",
+ "type": "AMAZON.NUMBER"
+ },
{
"name": "Ingredient",
- "type": "AMAZON.NUMBER",
- "samples": [
- "Bitte sage mir die neue Menge dieser Zutat"
- ]
+ "type": "Ingredient"
}
],
"samples": [
"{Ingredient} anpassen",
- "kann ich ein Rezept nach Zutaten aendern"
+ "kann ich ein Rezept nach Zutaten aendern",
+ "{Ingredient} auf {Ingredient_Value} anpassen"
]
},
{
@@ -263,49 +265,73 @@
}
}
]
- }
- ]
- },
- "dialog": {
- "intents": [
+ },
{
- "name": "ModifyRecipeByUnitsIntent",
- "confirmationRequired": false,
- "prompts": {},
- "slots": [
+ "name": "Ingredient",
+ "values": [
{
- "name": "Ingredient",
- "type": "AMAZON.NUMBER",
- "confirmationRequired": true,
- "elicitationRequired": true,
- "prompts": {
- "confirmation": "Confirm.Slot.170099915505.1240512610375",
- "elicitation": "Elicit.Slot.170099915505.1240512610375"
+ "name": {
+ "value": "Eis"
+ }
+ },
+ {
+ "name": {
+ "value": "Oel"
+ }
+ },
+ {
+ "name": {
+ "value": "Paniermehl"
+ }
+ },
+ {
+ "name": {
+ "value": "Tomatensauce"
+ }
+ },
+ {
+ "name": {
+ "value": "Salz"
+ }
+ },
+ {
+ "name": {
+ "value": "Zucker"
+ }
+ },
+ {
+ "name": {
+ "value": "Erdbeeren"
+ }
+ },
+ {
+ "name": {
+ "value": "Fleisch"
+ }
+ },
+ {
+ "name": {
+ "value": "Spaghetti"
+ }
+ },
+ {
+ "name": {
+ "value": "Milch"
+ }
+ },
+ {
+ "name": {
+ "value": "Ei"
+ }
+ },
+ {
+ "name": {
+ "value": "Mehl"
}
}
]
}
]
- },
- "prompts": [
- {
- "id": "Elicit.Slot.170099915505.1240512610375",
- "variations": [
- {
- "type": "PlainText",
- "value": "Bitte sage mir die neue Menge dieser Zutat"
- }
- ]
- },
- {
- "id": "Confirm.Slot.170099915505.1240512610375",
- "variations": [
- {
- "type": "PlainText",
- "value": "Ist {Ingredient} richtig?"
- }
- ]
- }
- ]
+ }
}
}
\ No newline at end of file
diff --git a/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.png b/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.png
new file mode 100644
index 0000000..0fdbfe4
Binary files /dev/null and b/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.png differ
diff --git a/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.xml b/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.xml
new file mode 100644
index 0000000..aeb7a08
--- /dev/null
+++ b/sprint_ressources/sprint2/SaveRecipeToFavoriteHandler.xml
@@ -0,0 +1 @@
+5Vldk9o2FP01zLQPy/hLNn5c2Gzy0M5kSjJtH4UtbE2E5cgysPvrK9mSbVkQnIXdJhMeQLr69Dn3Hl2Zmb/aHd8zWOZ/0hSRmeekx5n/MPO8CPjiWxqeWkMYRa0hYzhtTW5vWONnpIyOstY4RZXRkVNKOC5NY0KLAiXcsEHG6MHstqXEXLWEGbIM6wQS2/o3TnmurG4Y9w0fEM5yvXQIgrZlA5MvGaN1oRacef62+bTNO6gnU09a5TClh4HJfzfzV4xS3pZ2xxUiEluNWzvu8Uxrt3GGCj5lgN73HpJaPfw9QUc480IiJlhumChlsqT2y580SGLrpSzWO/IH3iKCC1FblojhHeKIiRaizB972/KQY47WJUzk0IPwHmHL+Y6ImiuKglEOxRDW1QmBZYU3zaqOsDCU1KzCe/QXqlrHkVZac7nSqnMIp9vyEAyFzx4xjo4DkwLnPaJin+xJdFGtvq+IetJMK08+9H7h+cqWD1wCAOUrUPli1s3d0yEKipEz7ACLHYuGAXglxQVvlgPLGXgYsUEZz2lGC0iGfNgYdS4xGSTX9Q2QFo6FkY7sIUSu7ncNRK4m6FsYoSK9l7IgUShRYbqcaHzEcv7GZ1JY5ShVTefB4ZBliI8eH6WGrNh4DQABJwDRNoYI5MLDTV07AZJa4aPkfUhHYNDhgXgOzEkqWrMEqXFDeRhNBS7O1AJhzdTQ1j35NGePLCLXUIZ5gkv0iT7CPWVCOz7AIiXCdX9JOQIL77IcBeC15Gjxf8hR9L0guW5kguRN0yP/BnIUTlCjHwKihRnYzjSIgltAZB9qCSzasP7t9wmJxwA/+cRY5G33BGdC1h82lHO6a0VdK/6G0ORLYxIb/UfFYlP591JgtjJpnsVD5dcBcVH4r1R0Px7RtYgm6fkLVDgMLXY2IvW+lgR17Bqnq2hWqf9C1o6Yd+yIckPOPAaT+Vmc4Ae8FT+xwY/vvtopGdqnZN6Fzg8bKFoWLxKhAL1z5o7jqOTjSnIAMIPHD6cFTz+R7ki32wpdS2Bky59IHUpaVOgNg2wuTwAj0GJdH5w100nXBL8o+hRRknM95krOg9i8kQRjwTwTkFM4txZbxP7cCRdxCIAbecEo+w6dcN63+dEoD7udcruuZ3nW5+pXzZQ915TkU5my6yhluHmm3F0J3zQP7D1gMkyBqY3aOy+kgd+MyOkY2e+eLIwG6pYQWFU4Md3urKcYQhRMFKK3uZ97kXk/6fL3772dB954onCSyr1EXHzboaW4VA0cX2tUcYs74YLcZIvJyIe9JNhuD2tOlTrIAVCddgRt+YlDkFOpQpUQJVxkn2Tl4S640Ys/HUsaW8/Wj/hUaNzkndaZt7It2meShZ8c7tA8sJ1TSvRaeAenbu3tPTTFewPm8Gst380vJdp3Cq970SMRzy7PWt3e317VfXZs2NImlO2ZZcNdS4qc2AvKoz3tWsZc8ZzijMHdTnR7ruX3Z+kXzgo2P/0o/e6skAuWCCc5YoUxKWl/H9tdmTsVZmv3wtYgc+aK/lP74jh1iOzID4PbuKKo9v/1tLLc/6Hmv/sP
\ No newline at end of file
diff --git a/src/main/java/verkocht/handlers/ModifyRecipeByUnitsIntentHandler.java b/src/main/java/verkocht/handlers/ModifyRecipeByUnitsIntentHandler.java
index 3543274..6d3b4c2 100644
--- a/src/main/java/verkocht/handlers/ModifyRecipeByUnitsIntentHandler.java
+++ b/src/main/java/verkocht/handlers/ModifyRecipeByUnitsIntentHandler.java
@@ -7,24 +7,17 @@
import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazon.ask.dispatcher.request.handler.RequestHandler;
-import com.amazon.ask.model.Intent;
-import com.amazon.ask.model.IntentRequest;
-import com.amazon.ask.model.Request;
import com.amazon.ask.model.Response;
-import com.amazon.ask.model.Slot;
import verkocht.model.PhrasesForAlexa;
import verkocht.model.Recipe;
public class ModifyRecipeByUnitsIntentHandler implements RequestHandler {
- static int step;
+ static boolean state = false;
public static final String INGREDIENT_SLOT = "Ingredient";
public static final String INGREDIENT_VALUE_SLOT = "IngredientValue";
- private String ingredientToModify;
- private String ingredientValue;
-
@Override
public boolean canHandle(HandlerInput input) {
return input.matches(intentName("ModifyRecipeByUnitsIntent"));
@@ -32,45 +25,38 @@ public boolean canHandle(HandlerInput input) {
@Override
public Optional handle(HandlerInput input) {
+ Map sessionAttributes = input.getAttributesManager().getSessionAttributes();
String speechText = PhrasesForAlexa.MODIFY_UNIT_ERROR;
Recipe recipeToModify = Recipe.getSavedRecipe();
try {
- if (step == 3) {
- recipeToModify.modifyByUnit(this.ingredientToModify, this.ingredientValue);
- speechText = PhrasesForAlexa.MODIFY_UNIT_DONE;
- step = 0;
- } else if (step == 2) {
- Request request = input.getRequestEnvelope().getRequest();
- IntentRequest intentRequest = (IntentRequest) request;
- Intent intent = intentRequest.getIntent();
- Map slots = intent.getSlots();
- String getIngredientValue = slots.get(INGREDIENT_VALUE_SLOT).getValue();
-
- if (getIngredientValue.isEmpty()) {
- speechText = PhrasesForAlexa.MODIFY_UNIT_VALUE;
- } else {
- speechText = "Ok!";
- this.ingredientValue = getIngredientValue;
- step++;
- }
- } else if (step == 1) {
- Request request = input.getRequestEnvelope().getRequest();
- IntentRequest intentRequest = (IntentRequest) request;
- Intent intent = intentRequest.getIntent();
- Map slots = intent.getSlots();
- String getIngredientToModify = slots.get(INGREDIENT_SLOT).getValue();
-
- if (getIngredientToModify.isEmpty()) {
- speechText = PhrasesForAlexa.MODIFY_UNIT_SELECT_INGREDIENT;
+ if (recipeToModify != null) {
+ String getIngredient = "";
+ String getIngredientSlotValue = "";
+ int getIngredientValue = 0;
+ boolean worked = false;
+ if (state) {
+ try {
+ getIngredient = (String) sessionAttributes.get(INGREDIENT_SLOT);
+ getIngredientSlotValue = (String) sessionAttributes.get(INGREDIENT_VALUE_SLOT);
+ getIngredientValue = Integer.parseInt(getIngredientSlotValue);
+ worked = recipeToModify.modifyByUnit(getIngredient, getIngredientValue);
+ speechText = getIngredientSlotValue;
+ if (worked) {
+ speechText = PhrasesForAlexa.MODIFY_UNIT_DONE;
+ resetState();
+ } else {
+ speechText = PhrasesForAlexa.MODIFY_UNIT_NOT_DONE;
+ }
+ } catch (Exception e) {
+ speechText = PhrasesForAlexa.MODIFY_UNIT_NOT_DONE;
+ }
} else {
- speechText = "Ok!";
- this.ingredientToModify = getIngredientToModify;
- step++;
+ speechText = PhrasesForAlexa.MODIFY_UNIT_WELCOME;
+ toggleState();
}
- } else if (step == 0) {
- speechText = PhrasesForAlexa.MODIFY_UNIT_WELCOME;
- step++;
+ } else {
+ speechText = PhrasesForAlexa.MODIFY_UNIT_SELECT_RECIPE_FIRST;
}
} catch (Exception e) {
speechText = PhrasesForAlexa.MODIFY_UNIT_ERROR;
@@ -79,4 +65,12 @@ public Optional handle(HandlerInput input) {
return input.getResponseBuilder().withSpeech(speechText).withSimpleCard("Rezeptschritte", speechText)
.withReprompt("Wie kann ich dir helfen?").withShouldEndSession(false).build();
}
+
+ public static void resetState() {
+ state = false;
+ }
+
+ public static void toggleState() {
+ state = !state;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/verkocht/model/PhrasesForAlexa.java b/src/main/java/verkocht/model/PhrasesForAlexa.java
index ed902cc..c712564 100644
--- a/src/main/java/verkocht/model/PhrasesForAlexa.java
+++ b/src/main/java/verkocht/model/PhrasesForAlexa.java
@@ -50,12 +50,11 @@ private PhrasesForAlexa() {
+ "Markiere zuerst Favoriten, damit ich sie dir vorlesen kann.";
// Modify Unit
- public static final String MODIFY_UNIT_WELCOME = "Hier kannst du ein Rezept entsprechend einer Zutat modifizieren. Sage {Zutat} anpassen.";
+ public static final String MODIFY_UNIT_WELCOME = "Hier kannst du ein Rezept entsprechend einer Zutat modifizieren. Sage: {Zutat} auf {Menge} anpassen.";
public static final String MODIFY_UNIT_REPROMT = "Bitte nenne eine Zutat des Rezept.";
- public static final String MODIFY_UNIT_SELECT_FIRST = "Du musst erst ein Rezept auswaehlen, bevor du es modifizieren kannst.";
- public static final String MODIFY_UNIT_SELECT_INGREDIENT = "Waehle eine Zutat.";
- public static final String MODIFY_UNIT_VALUE = "Auf welchen Wert soll die Zutat geaendert werden.";
public static final String MODIFY_UNIT_ERROR = "Dies ist nicht moeglich.";
+ public static final String MODIFY_UNIT_SELECT_RECIPE_FIRST = "Waehle bitte zuerst ein Rezept aus.";
+ public static final String MODIFY_UNIT_NOT_DONE = "Das Rezept konnte nicht angepasst werden.";
public static final String MODIFY_UNIT_DONE = "Das Rezept wurde angepasst.";
//Number of People
diff --git a/src/main/java/verkocht/model/Recipe.java b/src/main/java/verkocht/model/Recipe.java
index 2e28377..a53094a 100644
--- a/src/main/java/verkocht/model/Recipe.java
+++ b/src/main/java/verkocht/model/Recipe.java
@@ -4,6 +4,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
+import verkocht.handlers.ModifyRecipeByUnitsIntentHandler;
/*
* The class that represents a recipe.
@@ -50,9 +53,41 @@ public Recipe changeIngredientAmounts() {
}
return null;
}
+
+ public void addIngredient(Ingredient ingredient, int value) {
+ if (ingredientAmounts.containsKey(ingredient)) {
+ ingredientAmounts.replace(ingredient, value);
+ } else {
+ ingredientAmounts.put(ingredient, value);
+ }
+ }
- public void modifyByUnit(String ingredient, String value) {
- throw new UnsupportedOperationException();
+ public boolean modifyByUnit(String ingredient, int value) {
+ Set keys = this.ingredientAmounts.keySet();
+ int originValue = 1;
+ boolean found = false;
+
+ for (Ingredient key : keys) {
+ found = key.getIngredient().equals(ingredient);
+
+ if (found) {
+ originValue = ingredientAmounts.get(key);
+ break;
+ }
+ }
+
+ if (found) {
+ int difference = ((value * 100) / originValue);
+ ingredientAmounts.forEach((k, v) -> {
+ if (k.getIngredient() != ingredient) {
+ ingredientAmounts.replace(k, (v * difference) / 100);
+ } else {
+ ingredientAmounts.replace(k, value);
+ }
+ });
+ }
+
+ return found;
}
public String getName() {
@@ -81,6 +116,7 @@ public static Recipe getSavedRecipe() {
public static void saveRecipe(Recipe recipeToSave) {
Recipe.savedRecipe = recipeToSave;
+ ModifyRecipeByUnitsIntentHandler.resetState();
}
public int getNumberOfPeople() {
diff --git a/src/test/java/test/RecipeTest.java b/src/test/java/test/RecipeTest.java
index 9715302..c23d94c 100644
--- a/src/test/java/test/RecipeTest.java
+++ b/src/test/java/test/RecipeTest.java
@@ -4,6 +4,7 @@
import org.junit.Test;
+<<<<<<< HEAD
import verkocht.model.*;
/**
@@ -27,4 +28,44 @@ public void testChangeIngredientAmount() {
b = cookingBook2.getAllRecipes().get(0).getIngredients().get(cookingBook2.getIngredientByName("Mehl"));
assertEquals(a,b);
}
-}
\ No newline at end of file
+}
+=======
+import verkocht.model.Category;
+import verkocht.model.Ingredient;
+import verkocht.model.Recipe;
+import verkocht.model.Unit;
+
+public class RecipeTest {
+ Recipe recipe = new Recipe("Pfannenkuchen", Category.VEGETARIAN, 2, 20);
+ Ingredient mehl = new Ingredient("Mehl", Unit.GRAMM);
+ Ingredient salz = new Ingredient("Salz", Unit.BRISE);
+ Ingredient ei = new Ingredient("Ei", Unit.STUECK);
+ Ingredient milch = new Ingredient("Milch", Unit.MILLILITER);
+ Ingredient notAdded = new Ingredient("NotAdded", Unit.ESSLOEFFEL);
+
+ @Test
+ public void testConstructorAndGetter() {
+ assertEquals("Should be Pfannenkuchen", "Pfannenkuchen", recipe.getName());
+ assertEquals("Should be vegetarian", Category.VEGETARIAN, recipe.getCategory());
+ assertEquals("Should be for two persons", 2, recipe.getNumberOfPeople());
+ assertEquals("Should be done in 20 minutes", 20, recipe.getCookingTime());
+ }
+
+ @Test
+ public void testIngredients() {
+ recipe.addIngredient(mehl, 200);
+ recipe.addIngredient(ei, 1);
+ recipe.addIngredient(salz, 1);
+ recipe.addIngredient(milch, 100);
+
+ assertEquals("Should have four ingredients", 4, recipe.getIngredients().size());
+
+ assertFalse(recipe.modifyByUnit("NotAdded", 4));
+ assertTrue(recipe.modifyByUnit("Mehl", new Integer(300)));
+ assertEquals("Should have four ingredients", 4, recipe.getIngredients().size());
+
+ assertEquals("Should be 300 now", 300, (int) recipe.getIngredients().get(mehl));
+ }
+
+}
+>>>>>>> 6cd7b9a227d3be0fdd7007c012075d0391a6f23d