KinderErstellen
This commit is contained in:
@@ -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;
|
||||
@@ -11,6 +15,7 @@ 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 {
|
||||
@@ -25,11 +30,15 @@ public class AccounterstellungMitarbeiter {
|
||||
private @FXML RadioButton typEltern;
|
||||
private ToggleGroup accountTyp;
|
||||
|
||||
private ArrayList<Kind> kinder;
|
||||
|
||||
public void initialize() {
|
||||
accountTyp = new ToggleGroup();
|
||||
accountTyp.getToggles().add(typEltern);
|
||||
accountTyp.getToggles().add(typMitarbeiter);
|
||||
einmalpw.setText(einmalPwGenerieren());
|
||||
|
||||
kinder = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void onZurueck(ActionEvent actionEvent) {
|
||||
@@ -96,9 +105,12 @@ public class AccounterstellungMitarbeiter {
|
||||
}
|
||||
|
||||
if (vnameGueltig && gebGueltig && nnameGueltig) {
|
||||
Kind kind = new Kind(nnameEingabe.getText(), vnameEingabe.getText(), 0);
|
||||
kinder.add(kind);
|
||||
kindanzeige.getChildren().add(neues);
|
||||
neues.setOnAction(a -> {
|
||||
((HBox) neues.getParent()).getChildren().remove(neues);
|
||||
kinder.remove(kind);
|
||||
});
|
||||
vnameEingabe.setText("");
|
||||
nnameEingabe.setText("");
|
||||
@@ -126,15 +138,36 @@ public class AccounterstellungMitarbeiter {
|
||||
status.setText("Daten Erfolgreich gespeichert");
|
||||
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));
|
||||
|
||||
//Gson gson = new Gson();
|
||||
//String jay = gson.toJson(this);
|
||||
//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);
|
||||
Account neuer;
|
||||
if (typEltern.isSelected()) {
|
||||
neuer = new ElternAccount(String.format("%d",einmalpw.getText().hashCode()), accountname.getText(), email.getText());
|
||||
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());
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
kinder.clear();
|
||||
|
||||
Gson gson = new Gson();
|
||||
|
||||
System.out.println(gson.toJson(neuer));
|
||||
RestApiClient api = new RestApiClient();
|
||||
api.post("Benutzerkonto", json);
|
||||
api.post("Benutzer", gson.toJson(neuer));
|
||||
if (neuer instanceof ElternAccount) {
|
||||
for (Kind k : ((ElternAccount)neuer).getKinder()) {
|
||||
api.post("Kind", gson.toJson(k));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
status.setText("Accounterstellung Fehlgeschlagen");
|
||||
|
Reference in New Issue
Block a user