12 Commits

Author SHA1 Message Date
26b713309f Kommentieren 2024-01-18 08:43:18 +01:00
c5f7391631 Kinder und Eltern 2024-01-17 11:21:26 +01:00
17bf862890 Merge remote-tracking branch 'origin/master' into SvenAccountverwaltung 2024-01-17 10:35:37 +01:00
c08e816e93 Merge pull request 'get ist jetzt String hehe' (#15) from samu_masken into master
Reviewed-on: #15
2024-01-17 10:33:47 +01:00
72a6d9a7e5 get ist jetzt String hehe 2024-01-17 10:30:11 +01:00
92d62509de Merge remote-tracking branch 'origin/master' into SvenAccountverwaltung
# Conflicts:
#	src/main/java/RestAPISchnittstelle/RestApiClient.java
2024-01-17 10:26:10 +01:00
0f52f19fc7 Merge pull request 'nextId Methode' (#14) from samu_masken into master
Reviewed-on: #14
2024-01-17 10:24:06 +01:00
1b2a0c0309 nextId Methode 2024-01-15 09:31:57 +01:00
4780f4403b KinderErstellen 2024-01-13 14:29:57 +01:00
8e1084f034 Merge remote-tracking branch 'origin/master' into SvenAccountverwaltung
# Conflicts:
#	src/main/java/RestAPISchnittstelle/RestApiClient.java
2024-01-11 12:11:11 +01:00
042c78e0d4 zwischenschritt 2024-01-11 12:10:07 +01:00
2a3ac1498b zwischenschritt 2024-01-08 09:18:25 +01:00
10 changed files with 153 additions and 36 deletions

3
.idea/misc.xml generated
View File

@@ -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>

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets;
import Logik.ElternAccount;
import Logik.Kind;
import com.google.gson.Gson;
import com.google.gson.*;
/**
* noch nicht getestet
@@ -32,8 +32,8 @@ public class RestApiClient implements IRestAPI{
RestApiClient client1 = new RestApiClient();
client1.post("Gericht", "{\"name\" : \"Svens Beine\", \"69.69\", \"beschreibung\" : \"Muss net schmegge, muss wirge\"}");
System.out.println(client1.nextId("Benutzer"));
}
/**
@@ -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()
@@ -54,13 +54,13 @@ public class RestApiClient implements IRestAPI{
// Send the request and get the response
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
Kind test = gson.fromJson(httpResponse.body(), Kind.class);
// Print the response status code and body
System.out.println("Status Code: " + httpResponse.statusCode());
System.out.println("Response Body: " + test.getName());
System.out.println("Response Body: " + httpResponse.body());
return httpResponse.body();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@@ -71,7 +71,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,9 +86,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 null;
}
}
@@ -100,7 +103,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,8 +118,10 @@ 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 null;
}
}
@@ -210,4 +215,34 @@ public class RestApiClient implements IRestAPI{
}
}
public int nextId(String controllerName){
URI apiUri = URI.create(String.format("%s/%s/nextId", urlBase, controllerName));
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(apiUri)
.GET()
.build();
try {
// Send the request and get the response
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
// Print the response status code and body
System.out.println("Status Code: " + httpResponse.statusCode());
System.out.println("Response Body: " + httpResponse.body());
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
JsonArray jsonArray = jsonElement.getAsJsonArray();
JsonObject json = jsonArray.get(0).getAsJsonObject();
return json.get("auto_increment").getAsInt();
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
}

View File

@@ -1,5 +1,10 @@
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;
import javafx.fxml.FXML;
@@ -8,11 +13,15 @@ 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 {
private @FXML TextField accountname;
private @FXML TextField email;
private @FXML Label status;
private @FXML Label einmalpw;
private @FXML HBox kindanzeige;
@@ -21,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) {
@@ -40,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);
@@ -72,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());
@@ -79,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;
}
@@ -92,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("");
@@ -113,18 +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 true;
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());
//Schnittstelle zur RestAPI
RestApiClient api = new RestApiClient();
//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");
}
}
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -28,9 +28,9 @@
<VBox styleClass="accounterstellung_links">
<GridPane styleClass="accounterstellung_daten">
<Label text="Accountname:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
<TextField GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<TextField fx:id="accountname" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Label text="E-Mail:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<TextField GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<TextField fx:id="email" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<RadioButton fx:id="typMitarbeiter" onAction="#onTypMitarbeiter" text="Mitarbeiter" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
<RadioButton fx:id="typEltern" onAction="#onTypEltern" text="Eltern" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
</GridPane>