From 5978a079bf70ac5e8bf629d34dbce5d3a4522cc9 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Wed, 1 Feb 2023 07:21:59 +0100 Subject: [PATCH] add: createFood --- .../CreateFoodController.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java new file mode 100644 index 0000000..7370fdf --- /dev/null +++ b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java @@ -0,0 +1,71 @@ +package com.bib.essensbestellungsverwaltung; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.RadioButton; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.text.Text; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CreateFoodController { + @FXML + public TextField name; + @FXML + public TextArea description; + @FXML + public RadioButton isHauptgerichtRadio; + @FXML + public RadioButton isDessertRadio; + @FXML + public RadioButton isVegetarischRadio; + @FXML + public RadioButton isVeganRadio; + @FXML + public RadioButton isFleischRadio; + @FXML + public TextArea allergienTextBox; + @FXML + public Text responseText; + + @FXML + public void onAbbrechen(ActionEvent actionEvent) { + clearInputs(); + } + + @FXML + public void onHinzufügen(ActionEvent actionEvent) { + String gerichtName = name.getText(); + String beschreibung = description.getText(); + if(!isHauptgerichtRadio.isSelected() && !isDessertRadio.isSelected()){ + // art auswähelen + } + boolean isNachtisch = !isHauptgerichtRadio.isSelected(); + if(!isVegetarischRadio.isSelected() && !isVeganRadio.isSelected() && isFleischRadio.isSelected()){ + // Typ auswählen + } + int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3; + FoodType foodType = new FoodType(ft, "Vegan"); + List allergies = new ArrayList<>(); + // TODO: allergien hinzufügen + + long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies)); + System.out.println("Food created with id: " + id); + responseText.setText("New Food Created"); + clearInputs(); + } + + private void clearInputs(){ + name.setText(""); + description.setText(""); + isHauptgerichtRadio.setSelected(false); + isDessertRadio.setSelected(false); + isVeganRadio.setSelected(false); + isVegetarischRadio.setSelected(false); + isFleischRadio.setSelected(false); + allergienTextBox.setText(""); + } +}