Skip to content

Commit

Permalink
#28 #29 changed intents and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Plugsocket committed Dec 16, 2018
1 parent 2f81aba commit 45c5a97
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/main/java/verkocht/VerkochtStreamHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static Skill getSkill() {
new SetNumberOfPeopleIntentHandler(),
new TellRecipeStepsIntentHandler(),
new TellMeCategoriesIntentHandler())
// .withSkillId("amzn1.ask.skill.c5bc074f-b96e-4343-ba1e-393f8084fe94")
.withSkillId("amzn1.ask.skill.4c560721-fd0a-48db-9101-37b3f9c67a4d")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ public boolean canHandle(HandlerInput input) {
return input.matches(intentName("SelectRecipeByCategoryIntent"));
}

@SuppressWarnings("null")
@Override
public Optional<Response> handle(HandlerInput input) {
String speechText;
String speechText = "";
Request request = input.getRequestEnvelope().getRequest();
IntentRequest intentRequest = (IntentRequest) request;
Intent intent = intentRequest.getIntent();
Expand All @@ -56,31 +55,34 @@ public Optional<Response> handle(HandlerInput input) {

String chosenCategorie = chosenCategorieSlot.getValue();
input.getAttributesManager().setSessionAttributes(Collections.singletonMap(CATEGORY_KEY, chosenCategorie));



String actualCategorie = (String) input.getAttributesManager().getSessionAttributes().get(CATEGORY_KEY);
CookingBook cookingBook = new CookingBook();
Category[] categories = Category.values();
List<Recipe> foundRecipes = new ArrayList<>();

if (actualCategorie != null || !actualCategorie.isEmpty()) {

for (int i = 0; i <= Category.values().length; i++) {
if (categories[i].getName() == actualCategorie) {
if (actualCategorie == null || actualCategorie.isEmpty()) {
speechText = PhrasesForAlexa.CATEGORIES_UNKOWN;
} else {
CookingBook cookingBook = new CookingBook();
Category[] categories = Category.values();
List<Recipe> foundRecipes = new ArrayList<>();

for (int i = 0; i < categories.length; i++) {
if (categories[i].getName().equalsIgnoreCase(actualCategorie)) {
foundRecipes = cookingBook.findByCategory(categories[i]);
}
}

String responseMessage = null;
for (int i = 0; i <= foundRecipes.size(); i++){
responseMessage += foundRecipes.get(i).getName();
}

speechText = String.format(PhrasesForAlexa.TELL_CATEGORIES, responseMessage);

}

speechText = PhrasesForAlexa.CATEGORIES_UNKOWN;
}
}

String responseMessage = "";

if (foundRecipes.size() == 1) {
speechText = PhrasesForAlexa.TELL_CATEGORIES;
} else {
for (int i = 0; i < foundRecipes.size() - 1 ; i++){
responseMessage += foundRecipes.get(i).getName();
}
responseMessage += "und" + foundRecipes.get(foundRecipes.size());
speechText = String.format(PhrasesForAlexa.TELL_CATEGORIES, responseMessage);
}
}

return input.getResponseBuilder()
.withSpeech(speechText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,31 @@ public Optional<Response> handle(HandlerInput input) {
case "eine":
case "mich":
recipe.setNumberOfPeople(1);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 1);
break;
case "zwei":
recipe.setNumberOfPeople(2);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 2);
break;
case "drei":
recipe.setNumberOfPeople(3);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 3);
break;
case "vier":
recipe.setNumberOfPeople(4);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 4);
break;
case "fuenf":
recipe.setNumberOfPeople(5);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 5);
break;
case "sechs":
recipe.setNumberOfPeople(6);
recipe.changeIngredientAmounts();
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, 6);
break;
default:
speechText = PhrasesForAlexa.PEOPLE_NUMBER_UNCLEAR;
}
speechText = String.format(PhrasesForAlexa.PEOPLE_SET, actualNumber);
}

return input.getResponseBuilder()
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/verkocht/model/PhrasesForAlexa.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private PhrasesForAlexa() {
"Sag mir den Rezeptnamen. Sage zum Beispiel: ich moechte Schnitzel kochen.";

// Categories
public static final String TELL_CATEGORIES = "Folgende Rezepte befinden sich in der Kategorie";
public static final String TELL_CATEGORIES = "Die Rezepte %s befinden sich in der ausgewählten Kategorie";
public static final String CATEGORIES_UNKOWN = "Ich weiss nicht welche Kategorie ich vorlesen soll. Sag mir den Namen der Kategorie. Sage zum Beispiel: Sage mir alle Rezepte der Kategorie Vegan.";

// Favorites
Expand All @@ -59,7 +59,8 @@ private PhrasesForAlexa() {

//Number of People
public static final String PEOPLE_UNKNOWN = "Ich habe die Anzahl der Personen leider nicht genau verstanden, sage zum Beispiel: Ich moechte fuer zwei Personen kochen";
public static final String PEOPLE_SET = "Dein Rezept ist nun fuer %s ausgerichtet";
public static final String PEOPLE_SET = "Dein Rezept ist nun fuer %i ausgerichtet";
public static final String PEOPLE_NUMBER_UNCLEAR = "Die Gerichte koennen fuer maximal sechs Leute ausgerichtet werden";

// Cancel-/Stop-/Help-/Fallback-Intent
public static final String SORRY = "Tut mir leid, das weiss ich nicht. Sage einfach Hilfe.";
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/verkocht/model/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public Map<Ingredient, Integer> getIngredients() {
*
* @return
*/
public Recipe changeIngredientAmounts() {
public Recipe changeIngredientAmounts(int numberOfPerson) {
for (Ingredient key : this.ingredientAmounts.keySet() ) {
Integer r = ingredientAmounts.get(key);
ingredientAmounts.replace(key, r, r * this.numberOfPeople);
int a = (int) r * numberOfPerson / this.numberOfPeople;
ingredientAmounts.replace(key, r, a);
}
this.setNumberOfPeople(numberOfPerson);
return null;
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/test/CookingBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public void testFindByCategory() {
listOfRecipes.clear();
listOfRecipes.add(cookingBook.getAllRecipes().get(2));
assertEquals(cookingBook.findByCategory(Category.VEGAN),listOfRecipes);
}

}
}
10 changes: 4 additions & 6 deletions src/test/java/test/RecipeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ public void testChangeIngredientAmount() {
CookingBook cookingBook = new CookingBook();
CookingBook cookingBook2 = new CookingBook();

Integer a = 100;
cookingBook.getAllRecipes().get(0).setNumberOfPeople(2);
cookingBook.getAllRecipes().get(0).changeIngredientAmounts();
Integer a = 25;
cookingBook.getAllRecipes().get(0).changeIngredientAmounts(2);
Integer b = cookingBook.getAllRecipes().get(0).getIngredients().get(cookingBook.getIngredientByName("Mehl"));
assertEquals(a,b);

a = 200;
cookingBook2.getAllRecipes().get(0).setNumberOfPeople(4);
cookingBook2.getAllRecipes().get(0).changeIngredientAmounts();
a = 50;
cookingBook2.getAllRecipes().get(0).changeIngredientAmounts(4);
b = cookingBook2.getAllRecipes().get(0).getIngredients().get(cookingBook2.getIngredientByName("Mehl"));
assertEquals(a,b);
}
Expand Down

0 comments on commit 45c5a97

Please sign in to comment.