removing example code

This commit is contained in:
Mei Chang van der Werff 2025-12-02 18:46:38 +01:00
commit 29278c2fc1
5 changed files with 10 additions and 102 deletions

View file

@ -17,15 +17,11 @@ package client;
import static com.google.inject.Guice.createInjector; import static com.google.inject.Guice.createInjector;
import java.io.IOException;
import java.net.URISyntaxException;
import client.scenes.AddStepsCtrl; import client.scenes.AddStepsCtrl;
import client.scenes.MainCtrl; import client.scenes.MainCtrl;
import client.scenes.AddIngredientCtrl; import client.scenes.AddIngredientCtrl;
import client.scenes.AddNameCtrl; import client.scenes.AddNameCtrl;
import client.scenes.FoodpalApplicationCtrl; import client.scenes.FoodpalApplicationCtrl;
import client.scenes.QuoteOverviewCtrl;
import com.google.inject.Injector; import com.google.inject.Injector;
import client.utils.ServerUtilsExample; import client.utils.ServerUtilsExample;
@ -37,7 +33,7 @@ public class Main extends Application {
private static final Injector INJECTOR = createInjector(new MyModule()); private static final Injector INJECTOR = createInjector(new MyModule());
private static final MyFXML FXML = new MyFXML(INJECTOR); private static final MyFXML FXML = new MyFXML(INJECTOR);
public static void main(String[] args) throws URISyntaxException, IOException { public static void main(String[] args){
launch(); launch();
} }
@ -51,15 +47,12 @@ public class Main extends Application {
return; return;
} }
var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml");
var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml"); var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml");
var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml"); var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml");
var addIngredient = FXML.load(AddIngredientCtrl.class, "client", "scenes", "AddIngredient.fxml"); var addIngredient = FXML.load(AddIngredientCtrl.class, "client", "scenes", "AddIngredient.fxml");
var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml"); var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml");
var mainCtrl = INJECTOR.getInstance(MainCtrl.class); var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.initialize(primaryStage, overview, addName, foodpal, addIngredient, addStep); mainCtrl.initialize(primaryStage, addName, foodpal, addIngredient, addStep);
} }
} }

View file

@ -22,7 +22,6 @@ import com.google.inject.Scopes;
import client.scenes.AddNameCtrl; import client.scenes.AddNameCtrl;
import client.scenes.MainCtrl; import client.scenes.MainCtrl;
import client.scenes.QuoteOverviewCtrl;
public class MyModule implements Module { public class MyModule implements Module {
@ -31,6 +30,5 @@ public class MyModule implements Module {
binder.bind(MainCtrl.class).in(Scopes.SINGLETON); binder.bind(MainCtrl.class).in(Scopes.SINGLETON);
binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON); binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON);
binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON); binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON);
binder.bind(QuoteOverviewCtrl.class).in(Scopes.SINGLETON);
} }
} }

View file

@ -26,9 +26,6 @@ public class MainCtrl {
private Stage primaryStage; private Stage primaryStage;
private QuoteOverviewCtrl overviewCtrl;
private Scene overview;
private AddNameCtrl addNameCtrl; private AddNameCtrl addNameCtrl;
private Scene addName; private Scene addName;
@ -42,7 +39,6 @@ public class MainCtrl {
private Scene addStep; private Scene addStep;
public void initialize(Stage primaryStage, public void initialize(Stage primaryStage,
Pair<QuoteOverviewCtrl, Parent> overview,
Pair<AddNameCtrl, Parent> addName, Pair<AddNameCtrl, Parent> addName,
Pair<FoodpalApplicationCtrl, Parent> foodpal, Pair<FoodpalApplicationCtrl, Parent> foodpal,
Pair<AddIngredientCtrl, Parent> addIngredient, Pair<AddIngredientCtrl, Parent> addIngredient,
@ -51,9 +47,6 @@ public class MainCtrl {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
this.overviewCtrl = overview.getKey();
this.overview = new Scene(overview.getValue());
this.addNameCtrl = addName.getKey(); this.addNameCtrl = addName.getKey();
this.addName = new Scene(addName.getValue()); this.addName = new Scene(addName.getValue());
@ -71,11 +64,6 @@ public class MainCtrl {
primaryStage.show(); primaryStage.show();
} }
public void showOverview() {
primaryStage.setTitle("Quotes: Overview");
primaryStage.setScene(overview);
overviewCtrl.refresh();
}
public void showAddName() { public void showAddName() {
primaryStage.setTitle("Naming recipes"); primaryStage.setTitle("Naming recipes");

View file

@ -1,71 +0,0 @@
/*
* Copyright 2021 Delft University of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package client.scenes;
import java.net.URL;
import java.util.ResourceBundle;
import com.google.inject.Inject;
import client.utils.ServerUtilsExample;
import commons.Quote;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
public class QuoteOverviewCtrl implements Initializable {
private final ServerUtilsExample server;
private final MainCtrl mainCtrl;
private ObservableList<Quote> data;
@FXML
private TableView<Quote> table;
@FXML
private TableColumn<Quote, String> colFirstName;
@FXML
private TableColumn<Quote, String> colLastName;
@FXML
private TableColumn<Quote, String> colQuote;
@Inject
public QuoteOverviewCtrl(ServerUtilsExample server, MainCtrl mainCtrl) {
this.server = server;
this.mainCtrl = mainCtrl;
}
@Override
public void initialize(URL location, ResourceBundle resources) {
colFirstName.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().person.firstName));
colLastName.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().person.lastName));
colQuote.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().quote));
}
public void addQuote() {
mainCtrl.showAddName();
}
public void refresh() {
var quotes = server.getQuotes();
data = FXCollections.observableList(quotes);
table.setItems(data);
}
}

View file

@ -158,22 +158,22 @@ public class ServerUtils {
return true; return true;
} }
public Recipe addRecipeName(String name) throws IOException, InterruptedException { public void addRecipeName(String name) throws IOException, InterruptedException {
Recipe newRecipe = new Recipe(); Recipe newRecipe = new Recipe();
newRecipe.setName(name); newRecipe.setName(name);
return addRecipe(newRecipe); addRecipe(newRecipe);
} }
public Recipe addRecipeIngredient(Recipe recipe, String ingredient) throws IOException, InterruptedException { public void addRecipeIngredient(Recipe recipe, String ingredient) throws IOException, InterruptedException {
List<String> ingredients = new ArrayList<>(recipe.getIngredients()); List<String> ingredients = new ArrayList<>(recipe.getIngredients());
ingredients.add(ingredient); ingredients.add(ingredient);
recipe.setIngredients(ingredients); recipe.setIngredients(ingredients);
return updateRecipe(recipe); //updates the recipe instead of creating an whole new recipe updateRecipe(recipe);
} }
public Recipe updateRecipe(Recipe recipe) throws IOException, InterruptedException { public void updateRecipe(Recipe recipe) throws IOException, InterruptedException {
String json = objectMapper.writeValueAsString(recipe); String json = objectMapper.writeValueAsString(recipe);
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
@ -187,14 +187,14 @@ public class ServerUtils {
throw new IOException("Failed to update recipe: " + recipe.toDetailedString() + "body: " + response.body()); throw new IOException("Failed to update recipe: " + recipe.toDetailedString() + "body: " + response.body());
} }
return objectMapper.readValue(response.body(),Recipe.class); objectMapper.readValue(response.body(), Recipe.class);
} }
public Recipe addRecipeStep(Recipe recipe, String preparationStep) throws IOException, InterruptedException { public void addRecipeStep(Recipe recipe, String preparationStep) throws IOException, InterruptedException {
List<String> preparationSteps = new ArrayList<>(recipe.getPreparationSteps()); List<String> preparationSteps = new ArrayList<>(recipe.getPreparationSteps());
preparationSteps.add(preparationStep); preparationSteps.add(preparationStep);
recipe.setPreparationSteps(preparationSteps); recipe.setPreparationSteps(preparationSteps);
return updateRecipe(recipe); updateRecipe(recipe);
} }
} }