diff --git a/client/src/main/java/client/scenes/AddQuoteCtrl.java b/client/src/main/java/client/scenes/AddQuoteCtrl.java index 1ddf889..4d7a82f 100644 --- a/client/src/main/java/client/scenes/AddQuoteCtrl.java +++ b/client/src/main/java/client/scenes/AddQuoteCtrl.java @@ -15,11 +15,9 @@ */ package client.scenes; +import client.utils.ServerUtils; import com.google.inject.Inject; -import client.utils.ServerUtilsExample; -import commons.Person; -import commons.Quote; import jakarta.ws.rs.WebApplicationException; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -27,11 +25,13 @@ import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.stage.Modality; +import java.io.IOException; + public class AddQuoteCtrl { - private final ServerUtilsExample server; + private final ServerUtils server; private final MainCtrl mainCtrl; - + public TextField recipeName; @FXML private TextField firstName; @@ -42,10 +42,9 @@ public class AddQuoteCtrl { private TextField quote; @Inject - public AddQuoteCtrl(ServerUtilsExample server, MainCtrl mainCtrl) { + public AddQuoteCtrl(ServerUtils server, MainCtrl mainCtrl) { this.mainCtrl = mainCtrl; this.server = server; - } public void cancel() { @@ -53,9 +52,9 @@ public class AddQuoteCtrl { mainCtrl.showOverview(); } - public void ok() { + public void ok() throws IOException, InterruptedException { try { - server.addQuote(getQuote()); + server.addRecipeName(recipeName.getText()); } catch (WebApplicationException e) { var alert = new Alert(Alert.AlertType.ERROR); @@ -63,25 +62,19 @@ public class AddQuoteCtrl { alert.setContentText(e.getMessage()); alert.showAndWait(); return; + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); } clearFields(); - mainCtrl.showOverview(); - } - - private Quote getQuote() { - var p = new Person(firstName.getText(), lastName.getText()); - var q = quote.getText(); - return new Quote(p, q); + mainCtrl.showFoodpal(); } private void clearFields() { - firstName.clear(); - lastName.clear(); - quote.clear(); + recipeName.clear(); } - public void keyPressed(KeyEvent e) { + public void keyPressed(KeyEvent e) throws IOException, InterruptedException { switch (e.getCode()) { case ENTER: ok(); diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index 2b4d7ca..95247a7 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -1,8 +1,11 @@ package client.scenes; +import javafx.event.ActionEvent; +import java.io.IOException; import java.util.List; +import client.utils.ServerUtils; import commons.Recipe; import jakarta.inject.Inject; @@ -14,6 +17,8 @@ import javafx.scene.control.ListView; public class FoodpalApplicationCtrl { private final MainCtrl mainCtrl; + private final ServerUtils server; + // all of these aren't used with only my part of the code // everything in the top bar === @@ -68,12 +73,13 @@ public class FoodpalApplicationCtrl { private Button addPreparationStepButton; @Inject - public FoodpalApplicationCtrl(MainCtrl mainCtrl) { + public FoodpalApplicationCtrl(MainCtrl mainCtrl, ServerUtils server) { this.mainCtrl = mainCtrl; + this.server = server; } @FXML - private void initialize() { + private void initialize() throws IOException, InterruptedException { // Show recipe name in the list recipeList.setCellFactory(list -> new ListCell<>() { @Override @@ -106,9 +112,9 @@ public class FoodpalApplicationCtrl { // Button handlers @FXML - public void refresh() { + public void refresh() throws IOException, InterruptedException { // TODO: someone else doing this - List recipes = showRecipeDetails(); + List recipes = server.getRecipes(); recipeList.getItems().setAll(recipes); // Select first recipe in the list by default @@ -117,15 +123,12 @@ public class FoodpalApplicationCtrl { } } - // to remove error till everything else is implemented - private List showRecipeDetails() { - return List.of(); - } @FXML - private void addRecipe() { + private void addRecipe(ActionEvent e) { + // Navigate to "create recipe" screen (should be like a pop-up or new screen or just another place in the app) - mainCtrl.showOverview(); + mainCtrl.showAdd(); } @FXML @@ -147,7 +150,7 @@ public class FoodpalApplicationCtrl { return; } // Let MainCtrl open the full detail screen - mainCtrl.showOverview(); //I had showrecipedetail but intelij says showoverview + mainCtrl.showAdd(); //I had showrecipedetail but intelij says showoverview } @FXML @@ -185,20 +188,6 @@ public class FoodpalApplicationCtrl { System.out.println("Switch language to PL"); } - @FXML - private void closeWindow() { - System.out.println("Close window"); - } - - @FXML - private void maximizeWindow() { - System.out.println("Maximize window"); - } - - @FXML - private void minimizeWindow() { - System.out.println("Minimize window"); - } @FXML private void MakePrintable() { diff --git a/client/src/main/java/client/scenes/MainCtrl.java b/client/src/main/java/client/scenes/MainCtrl.java index 160104c..a368e16 100644 --- a/client/src/main/java/client/scenes/MainCtrl.java +++ b/client/src/main/java/client/scenes/MainCtrl.java @@ -20,6 +20,8 @@ import javafx.scene.Scene; import javafx.stage.Stage; import javafx.util.Pair; +import java.io.IOException; + public class MainCtrl { private Stage primaryStage; @@ -36,7 +38,7 @@ public class MainCtrl { public void initialize(Stage primaryStage, Pair overview, Pair add, - Pair foodpal){ + Pair foodpal) throws IOException, InterruptedException { this.primaryStage = primaryStage; @@ -60,12 +62,18 @@ public class MainCtrl { } public void showAdd() { - primaryStage.setTitle("Quotes: Adding Quote"); + primaryStage.setTitle("Naming recipes"); primaryStage.setScene(add); - add.setOnKeyPressed(e -> addCtrl.keyPressed(e)); + add.setOnKeyPressed(e -> { + try { + addCtrl.keyPressed(e); + } catch (IOException | InterruptedException ex) { + throw new RuntimeException(ex); + } + }); } - public void showFoodpal(){ + public void showFoodpal() throws IOException, InterruptedException { primaryStage.setTitle("FoodPal"); primaryStage.setScene(foodpal); foodpalCtrl.refresh(); diff --git a/client/src/main/java/client/utils/ServerUtils.java b/client/src/main/java/client/utils/ServerUtils.java index 37ebd30..f7df0b4 100644 --- a/client/src/main/java/client/utils/ServerUtils.java +++ b/client/src/main/java/client/utils/ServerUtils.java @@ -2,9 +2,11 @@ package client.utils; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import commons.Quote; import commons.Recipe; import jakarta.ws.rs.ProcessingException; import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; import org.glassfish.jersey.client.ClientConfig; @@ -156,4 +158,11 @@ public class ServerUtils { } return true; } + + public Recipe addRecipeName(String name) throws IOException, InterruptedException { + Recipe newRecipe = new Recipe(); + newRecipe.setName(name); + return addRecipe(newRecipe); + + } } \ No newline at end of file diff --git a/client/src/main/resources/client/scenes/AddQuote.fxml b/client/src/main/resources/client/scenes/AddQuote.fxml index db10049..e49562a 100644 --- a/client/src/main/resources/client/scenes/AddQuote.fxml +++ b/client/src/main/resources/client/scenes/AddQuote.fxml @@ -5,15 +5,11 @@ - + -