Merge branch 'SvenAccountverwaltung'
# Conflicts: # src/main/java/de/subway_surfers/vpr_app/AccounterstellungMitarbeiter.java
This commit is contained in:
		
							
								
								
									
										3
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @@ -7,9 +7,8 @@ | ||||
|         <option value="$PROJECT_DIR$/pom.xml" /> | ||||
|       </list> | ||||
|     </option> | ||||
|     <option name="workspaceImportForciblyTurnedOn" value="true" /> | ||||
|   </component> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK"> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="21" project-jdk-type="JavaSDK"> | ||||
|     <output url="file://$PROJECT_DIR$/out" /> | ||||
|   </component> | ||||
| </project> | ||||
| @@ -3,6 +3,8 @@ | ||||
|  | ||||
| package Logik; | ||||
|  | ||||
| import RestAPISchnittstelle.RestApiClient; | ||||
|  | ||||
| public class Account { | ||||
|  | ||||
| 	// region Felder | ||||
| @@ -12,6 +14,8 @@ public class Account { | ||||
|  | ||||
| 	private String name; | ||||
|  | ||||
| 	private String email; | ||||
|  | ||||
| 	private int rid; | ||||
| 	// endregion | ||||
|  | ||||
| @@ -32,6 +36,14 @@ public class Account { | ||||
| 		this.id = id; | ||||
| 	} | ||||
|  | ||||
| 	public String getEmail() { | ||||
| 		return email; | ||||
| 	} | ||||
|  | ||||
| 	public void setEmail(String email) { | ||||
| 		this.email = email; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	public String getBenutzername() { | ||||
| 		return name; | ||||
| @@ -43,9 +55,10 @@ public class Account { | ||||
| 	// endregion | ||||
|  | ||||
| 	// region Konstruktoren | ||||
| 	public Account(String passwort, String name) { | ||||
| 	public Account(String passwort, String name, String email) { | ||||
| 		this.passwort = passwort; | ||||
| 		this.name = name; | ||||
| 		this.email = email; | ||||
|  | ||||
| 		if(this instanceof MitarbeiterAccount) | ||||
| 			rid = 0; | ||||
| @@ -53,5 +66,4 @@ public class Account { | ||||
| 			rid = 1; | ||||
| 	} | ||||
| 	// endregion | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -12,19 +12,10 @@ import java.util.ArrayList; | ||||
| public class ElternAccount extends Account { | ||||
|  | ||||
| 	// region Felder | ||||
| 	private String email; | ||||
|  | ||||
| 	private transient ArrayList<Kind> kinder; | ||||
| 	// endregion | ||||
|  | ||||
| 	// region Getter & Setter | ||||
| 	public String getEmail() { | ||||
| 		return email; | ||||
| 	} | ||||
|  | ||||
| 	public void setEmail(String email) { | ||||
| 		this.email = email; | ||||
| 	} | ||||
|  | ||||
| 	public ArrayList<Kind> getKinder() { | ||||
| 		return kinder; | ||||
| @@ -37,8 +28,7 @@ public class ElternAccount extends Account { | ||||
|  | ||||
| 	// region Konstruktoren | ||||
| 	public ElternAccount(String passwort, String benutzername, String email) { | ||||
| 		super(passwort, benutzername); | ||||
| 		this.email = email; | ||||
| 		super(passwort, benutzername, email); | ||||
| 		kinder = new ArrayList<>(); | ||||
| 	} | ||||
| 	// endregion | ||||
|   | ||||
| @@ -12,8 +12,8 @@ import java.util.ArrayList; | ||||
| public class MitarbeiterAccount extends Account { | ||||
|  | ||||
| 	// region Konstrukoren | ||||
| 	public MitarbeiterAccount(String passwort, String benutzername) { | ||||
| 		super(passwort, benutzername); | ||||
| 	public MitarbeiterAccount(String passwort, String benutzername, String email) { | ||||
| 		super(passwort, benutzername, email); | ||||
| 	} | ||||
| 	//endregion | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,9 @@ | ||||
| package de.subway_surfers.vpr_app; | ||||
|  | ||||
| import Logik.Account; | ||||
| import Logik.ElternAccount; | ||||
| import Logik.Kind; | ||||
| import Logik.MitarbeiterAccount; | ||||
| import RestAPISchnittstelle.RestApiClient; | ||||
| import javafx.collections.ListChangeListener; | ||||
| import javafx.event.ActionEvent; | ||||
| @@ -9,7 +13,9 @@ import javafx.scene.layout.Background; | ||||
| import javafx.scene.layout.GridPane; | ||||
| import javafx.scene.layout.HBox; | ||||
| import javafx.scene.layout.VBox; | ||||
| import com.google.gson.Gson; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Random; | ||||
|  | ||||
| public class AccounterstellungMitarbeiter { | ||||
| @@ -24,11 +30,17 @@ public class AccounterstellungMitarbeiter { | ||||
| 	private @FXML RadioButton typEltern; | ||||
| 	private       ToggleGroup accountTyp; | ||||
|  | ||||
| 	private ArrayList<Kind> kinder; | ||||
|  | ||||
| 	public void initialize() { | ||||
| 		//Die Radiobuttons zum auswählen eines Accountypes werden einer ToggleGroup hinzugefügt | ||||
| 		accountTyp = new ToggleGroup(); | ||||
| 		accountTyp.getToggles().add(typEltern); | ||||
| 		accountTyp.getToggles().add(typMitarbeiter); | ||||
|  | ||||
| 		einmalpw.setText(einmalPwGenerieren()); | ||||
|  | ||||
| 		kinder = new ArrayList<>(); | ||||
| 	} | ||||
|  | ||||
| 	public void onZurueck(ActionEvent actionEvent) { | ||||
| @@ -43,7 +55,12 @@ public class AccounterstellungMitarbeiter { | ||||
| 		kindDaten.getChildren().clear(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Einfügen der Eingabefelder für Kinder, wenn der Eltern-Radiobutton ausgewählt wird | ||||
| 	 * @param actionEvent | ||||
| 	 */ | ||||
| 	public void onTypEltern(ActionEvent actionEvent) { | ||||
| 		//Einfügen der Eingabefelder für Kinder | ||||
| 		Label ueberschrift = new Label(); | ||||
| 		ueberschrift.setText("Daten des Kindes:"); | ||||
| 		kindDaten.addRow(0); | ||||
| @@ -75,6 +92,7 @@ public class AccounterstellungMitarbeiter { | ||||
| 		kindDaten.add(hinzufuegen, 1, 4); | ||||
|  | ||||
| 		kindDaten.addRow(5); | ||||
| 		//wird der Button zum hinzufügen eines Kindes geclickt wird dieses Event ausgelöst | ||||
| 		hinzufuegen.setOnAction(e -> { | ||||
| 			Button neues = new Button(vnameEingabe.getText()); | ||||
|  | ||||
| @@ -82,6 +100,7 @@ public class AccounterstellungMitarbeiter { | ||||
| 			boolean gebGueltig = false; | ||||
| 			boolean nnameGueltig = false; | ||||
|  | ||||
| 			//Wenn alle Eingabefelder für Kinder ausgefüllt sind ist die Eingabe gültig | ||||
| 			if (!vnameEingabe.getText().equals("")) { | ||||
| 				vnameGueltig = true; | ||||
| 			} | ||||
| @@ -95,10 +114,15 @@ public class AccounterstellungMitarbeiter { | ||||
| 			} | ||||
|  | ||||
| 			if (vnameGueltig && gebGueltig && nnameGueltig) { | ||||
| 				Kind kind = new Kind(nnameEingabe.getText(), vnameEingabe.getText(), 0); | ||||
| 				kinder.add(kind); | ||||
| 				kindanzeige.getChildren().add(neues); | ||||
| 				//Wird auf ein Kind in der Anzeige geclickt, wird es aus der Liste entfernt. | ||||
| 				neues.setOnAction(a -> { | ||||
| 					((HBox) neues.getParent()).getChildren().remove(neues); | ||||
| 					kinder.remove(kind); | ||||
| 				}); | ||||
| 				//Die Eingabefelder werden zurückgesetzt | ||||
| 				vnameEingabe.setText(""); | ||||
| 				nnameEingabe.setText(""); | ||||
| 				geburtstagEingabe.getEditor().setText(""); | ||||
| @@ -116,25 +140,68 @@ public class AccounterstellungMitarbeiter { | ||||
| 		return pw; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Prüft, ob in allen Textfeldern für die Eltern Text steht. | ||||
| 	 * @return true, wenn kein Feld leer ist | ||||
| 	 */ | ||||
| 	private boolean eingabenGueltig() { | ||||
| 		return !accountname.getText().equals("") && !email.getText().equals("") && (typEltern.isSelected() || typMitarbeiter.isSelected()); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * | ||||
| 	 * @param actionEvent | ||||
| 	 */ | ||||
| 	public void onSpeichern(ActionEvent actionEvent) { | ||||
| 		if (eingabenGueltig()) { | ||||
| 			status.setText("Daten Erfolgreich gespeichert"); | ||||
| 			//Zeigt generiert ein Einmalpasswort und zeigt es an | ||||
| 			einmalpw.setText(einmalPwGenerieren()); | ||||
|  | ||||
| 			String json = String.format("{\"name\":\"%s\", \"email\":\"%s\", \"passwort\":\"%d\", \"rid\":\"%d\"}", | ||||
| 										accountname.getText(), email.getText(), einmalpw.getText().hashCode(), (typMitarbeiter.isSelected() ? 0:1)); | ||||
| 			System.out.println(json); | ||||
| 			//Schnittstelle zur RestAPI | ||||
| 			RestApiClient api = new RestApiClient(); | ||||
| 			api.post("Benutzerkonto", json); | ||||
|  | ||||
| 			//id, die das Elternobjekt bekommt, dass im laufe der Methode erstellt wird | ||||
| 			int id = api.nextId("Benutzer"); | ||||
|  | ||||
| 			//Erstellen des neuen Accounts | ||||
| 			Account neuer; | ||||
| 			//Handelt es sich um einen Elternaccount, werden alle Eingegebenen Kinder erstellt. | ||||
| 			if (typEltern.isSelected()) { | ||||
| 				neuer = new ElternAccount(String.format("%d",einmalpw.getText().hashCode()), accountname.getText(), email.getText()); | ||||
| 				System.out.println(neuer.getEmail()); | ||||
| 				//Kinder dem neuen Account hinzufügen | ||||
| 				for (Kind k : kinder) { | ||||
| 					((ElternAccount)neuer).getKinder().add(k); | ||||
| 				} | ||||
| 			} | ||||
| 			else if (typMitarbeiter.isSelected()) { | ||||
| 				neuer = new MitarbeiterAccount(String.format("%d",einmalpw.getText().hashCode()), accountname.getText(), email.getText()); | ||||
| 			} | ||||
| 			//Ist kein Radio Button ausgewählt, wird hier abgebrochen | ||||
| 			else { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			//Die Liste, zum Speichern der gespeicherten Liste wird zurückgesetzt, da die Kinder jetzt im Elternobjekt gespeichert werden | ||||
| 			kinder.clear(); | ||||
|  | ||||
| 			Gson gson = new Gson(); | ||||
|  | ||||
| 			//Das Elternelement wird in der DB gespeichert. | ||||
| 			api.post("Benutzer", gson.toJson(neuer)); | ||||
|  | ||||
| 			//handelt es sich um einen Elternaccount, werden alle Kind-Objekte in der DB gespeichert | ||||
| 			if (neuer instanceof ElternAccount) { | ||||
| 				for (Kind k : ((ElternAccount)neuer).getKinder()) { | ||||
| 					//setzen des Fremdschlüssels bid | ||||
| 					k.setBid(id); | ||||
| 					api.post("Kind", gson.toJson(k)); | ||||
| 				} | ||||
| 			} | ||||
| 			status.setText("Daten Erfolgreich gespeichert"); | ||||
| 		} | ||||
| 		else { | ||||
| 			status.setText("Accounterstellung Fehlgeschlagen"); | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -41,7 +41,9 @@ public class EssensverwaltungMitarbeiterView { | ||||
| 	} | ||||
|  | ||||
| 	public void onFilter(ActionEvent actionEvent) { | ||||
| 		VerwaltungApplication.sceneWechseln(new Stage(), 600, 400, "inhaltsstoffe_filtern-view.fxml"); | ||||
| 		Stage stage = new Stage(); | ||||
| 		VerwaltungApplication.sceneWechseln(stage, 450, 400, "inhaltsstoffe_filtern-view.fxml"); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	public void onHinzufuegen(ActionEvent actionEvent) { | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package de.subway_surfers.vpr_app; | ||||
|  | ||||
| import Logik.Account; | ||||
| import RestAPISchnittstelle.RestApiClient; | ||||
| import javafx.event.ActionEvent; | ||||
| import javafx.fxml.FXML; | ||||
| import javafx.fxml.FXMLLoader; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user