KinderErstellen
This commit is contained in:
parent
8e1084f034
commit
4780f4403b
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>
|
@ -12,6 +12,9 @@ public class Account {
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
|
||||
private int rid;
|
||||
// endregion
|
||||
|
||||
@ -32,6 +35,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,7 +54,7 @@ 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;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -11,11 +11,11 @@ public interface IRestAPI {
|
||||
|
||||
// region Get
|
||||
|
||||
void get(String controllerName);
|
||||
String get(String controllerName);
|
||||
|
||||
void get (String controllerName, int id);
|
||||
String get (String controllerName, int id);
|
||||
|
||||
void get (String controllerName, int id, boolean bezahlt);
|
||||
String get (String controllerName, int id, boolean bezahlt);
|
||||
|
||||
//endregion
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class RestApiClient implements IRestAPI{
|
||||
* @param controllerName Name des aufzurufenden Controllers
|
||||
*/
|
||||
@Override
|
||||
public void get(String controllerName) {
|
||||
public String get(String controllerName) {
|
||||
URI apiUri = URI.create(String.format("%s/%s", urlBase, controllerName));
|
||||
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||
@ -59,9 +59,12 @@ public class RestApiClient implements IRestAPI{
|
||||
// Print the response status code and body
|
||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
||||
System.out.println("Response Body: " + test.getName());
|
||||
|
||||
return httpResponse.body();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +74,7 @@ public class RestApiClient implements IRestAPI{
|
||||
* @param id Id der Aufzurufenden Zeile
|
||||
*/
|
||||
@Override
|
||||
public void get(String controllerName, int id) {
|
||||
public String get(String controllerName, int id) {
|
||||
URI apiUri = URI.create(String.format("%s/%s/%s", urlBase, controllerName, id));
|
||||
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||
@ -86,10 +89,12 @@ public class RestApiClient implements IRestAPI{
|
||||
// Print the response status code and body
|
||||
System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
||||
|
||||
return httpResponse.body();
|
||||
//System.out.println("Response Body: " + test);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +105,7 @@ public class RestApiClient implements IRestAPI{
|
||||
* @param bezahlt TODO Warum ist das hier?
|
||||
*/
|
||||
@Override
|
||||
public void get(String controllerName, int id, boolean bezahlt) {
|
||||
public String get(String controllerName, int id, boolean bezahlt) {
|
||||
URI apiUri = URI.create(String.format("%s/%s?%s&%s", urlBase, controllerName, id, bezahlt));
|
||||
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||
@ -115,9 +120,12 @@ public class RestApiClient implements IRestAPI{
|
||||
// Print the response status code and body
|
||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
||||
System.out.println("Response Body: " + httpResponse.body());
|
||||
|
||||
return httpResponse.body();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user