Skip to content

Commit

Permalink
#24 first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoliai committed Dec 3, 2018
1 parent 81a7552 commit dc50336
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
package verkocht.handlers;

import static com.amazon.ask.request.Predicates.intentName;
import static verkocht.handlers.SelectRecipeByNameInputRecipeIntentHandler.RECIPE_KEY;
import static verkocht.handlers.SelectRecipeByNameInputRecipeIntentHandler.RECIPE_SLOT;
import static verkocht.handlers.WhatsMyColorIntentHandler.COLOR_KEY;
import static verkocht.handlers.WhatsMyColorIntentHandler.COLOR_SLOT;

import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -76,7 +72,12 @@ public Optional<Response> handle(HandlerInput input) {
recipe = foundRecipe.getName(); //recipe could be found
}
if (recipe != null && !recipe.isEmpty()) {//string is not empty and not null
TellRecipeStepsIntentHandler.setRecipeToRead(foundRecipe);
speechText = String.format("Ich lese dir das Rezept %s vor.", recipe);




} else {
speechText = "Ich weiss nicht welches Rezept ich vorlesen soll. Sag mir den Rezeptnamen. Sage zum Beispiel: ich möchte Schnitzel kochen.";
}
Expand All @@ -86,4 +87,4 @@ public Optional<Response> handle(HandlerInput input) {
.withSimpleCard("Rezeptauswahl", speechText)
.withShouldEndSession(false).build();
}
}
}
43 changes: 27 additions & 16 deletions src/main/java/verkocht/handlers/TellRecipeStepsIntentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,33 @@
import com.amazon.ask.dispatcher.request.handler.RequestHandler;
import com.amazon.ask.model.Response;

import verkocht.model.Recipe;

public class TellRecipeStepsIntentHandler implements RequestHandler {

@Override
public boolean canHandle(HandlerInput input) {
return input.matches(intentName("TellRecipeStepsIntent"));
}

@Override
public Optional<Response> handle(HandlerInput input) {
String speechText = "Hier kannst du dir spaeter die Rezeptschritte vorlesen lassen.";

return input.getResponseBuilder()
.withSpeech(speechText)
.withSimpleCard("Rezeptschritte", speechText)
.withReprompt("Wie kann ich dir helfen?")
.withShouldEndSession(false)
.build();
}
@Override
public boolean canHandle(HandlerInput input) {
return input.matches(intentName("TellRecipeStepsIntent"));
}

@Override
public Optional<Response> handle(HandlerInput input) {
Recipe recipeToRead = Recipe.getRecipeToRead();
String recipeStep = recipeToRead.getSteps().get(Recipe.getStepsCounter());
String speechText = String.format("Neuer Schritt %s %d toSet %d", recipeStep, Recipe.getStepsCounter(),
Recipe.getStepsCounter());
Recipe.incStepsCounter();

return input.getResponseBuilder().withSpeech(speechText).withSimpleCard("Rezeptschritte", speechText)
.withReprompt("Wie kann ich dir helfen?").withShouldEndSession(false).build();
}

public static Recipe getRecipeToRead() {
return Recipe.getRecipeToRead();
}

public static void setRecipeToRead(Recipe recipeToRead) {
Recipe.setRecipeToRead(recipeToRead);
}

}
22 changes: 19 additions & 3 deletions src/main/java/verkocht/model/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Map;

import verkocht.handlers.TellRecipeStepsIntentHandler;

/*
* The class that represents a recipe.
*/
Expand All @@ -15,6 +17,9 @@ public class Recipe {
private int cookingTime;
private Category category;
private Map<Ingredient, Integer> ingredientAmounts = new HashMap<Ingredient, Integer> ();
private static int stepsCounter;
private static Recipe recipeToRead;


public Recipe(String name, Category category, int nrOfPeople, int coockingTime) {
this.name = name;
Expand Down Expand Up @@ -55,9 +60,20 @@ public void setSteps(List<String> steps) {
this.steps = steps;
}



public static int getStepsCounter() {
return stepsCounter;
}

public static void incStepsCounter() {
Recipe.stepsCounter++;
}



public static Recipe getRecipeToRead() {
return recipeToRead;
}

public static void setRecipeToRead(Recipe recipeToRead) {
Recipe.recipeToRead = recipeToRead;
}
}
39 changes: 39 additions & 0 deletions src/test/java/test/TellRecipeStepsIntentHandlerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package test;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazonaws.services.dynamodbv2.document.Item;

import verkocht.VerkochtStreamHandler;
import verkocht.handlers.TellRecipeStepsIntentHandler;
import verkocht.model.CookingBook;
import verkocht.model.Recipe;

public class TellRecipeStepsIntentHandlerTest {


@Mock
HandlerInput input;


@InjectMocks
private TellRecipeStepsIntentHandler tellRecipeStepsHandler = new TellRecipeStepsIntentHandler();

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
// @Test
// public void testHandle() {
// //VerkochtStreamHandler verkochtStreamHandler = new VerkochtStreamHandler();
// CookingBook coockingBook = new CookingBook();
// Recipe selectedRecipe = coockingBook.getAllRecipes().get(0); //schnitzel
// tellRecipeStepsHandler.handle(input);
// }

}

0 comments on commit dc50336

Please sign in to comment.