Account laden
This commit is contained in:
parent
1db44e7b22
commit
39b9266067
@ -17,6 +17,8 @@ public interface IRestAPI {
|
||||
|
||||
String get (String controllerName, int id, boolean bezahlt);
|
||||
|
||||
String get(String controllerName, String[] params);
|
||||
|
||||
//endregion
|
||||
|
||||
// region put
|
||||
|
@ -125,6 +125,36 @@ public class RestApiClient implements IRestAPI{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String controllerName, String[] params) {
|
||||
String ende = "";
|
||||
for (String str : params) {
|
||||
ende += str + ",";
|
||||
}
|
||||
ende = ende.substring(0, ende.length() - 1);
|
||||
URI apiUri = URI.create(String.format("%s/%s?%s", urlBase, controllerName, ende));
|
||||
|
||||
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() + httpResponse.body());
|
||||
|
||||
return httpResponse.body();
|
||||
|
||||
//System.out.println("Response Body: " + test);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode für einen Put-Aufruf. Aktualisiert einen Eintrag.
|
||||
*
|
||||
|
@ -5,6 +5,9 @@ import Logik.ElternAccount;
|
||||
import Logik.Kind;
|
||||
import Logik.MitarbeiterAccount;
|
||||
import RestAPISchnittstelle.RestApiClient;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
@ -91,7 +94,10 @@ public class AccounterstellungMitarbeiter {
|
||||
Button hinzufuegen = new Button("hinzufügen");
|
||||
kindDaten.add(hinzufuegen, 1, 4);
|
||||
|
||||
if (kindDaten.getRowCount() < 5) {
|
||||
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());
|
||||
@ -204,4 +210,51 @@ public class AccounterstellungMitarbeiter {
|
||||
status.setText("Accounterstellung Fehlgeschlagen");
|
||||
}
|
||||
}
|
||||
|
||||
public void onLaden(ActionEvent actionEvent) {
|
||||
Gson gson = new Gson();
|
||||
RestApiClient api = new RestApiClient();
|
||||
|
||||
String[] params = {String.format("name=%s", accountname.getText())};
|
||||
String jsonAcc = api.get("Benutzer", params);
|
||||
|
||||
System.out.println(jsonAcc);
|
||||
|
||||
Account acc;
|
||||
if (jsonAcc.contains("\"rid\":\"0\"")) {
|
||||
acc = gson.fromJson(jsonAcc, MitarbeiterAccount.class);
|
||||
|
||||
accountTyp.selectToggle(typMitarbeiter);
|
||||
}
|
||||
else if (jsonAcc.contains("\"rid\":\"1\"")) {
|
||||
acc = gson.fromJson(jsonAcc, ElternAccount.class);
|
||||
|
||||
accountTyp.selectToggle(typEltern);
|
||||
onTypEltern(new ActionEvent());
|
||||
|
||||
kindDaten.addRow(5);
|
||||
|
||||
String jsonString = api.get("Kind", acc.getId());
|
||||
JsonElement je = JsonParser.parseString(jsonString);
|
||||
JsonArray ja = je.getAsJsonArray();
|
||||
|
||||
for (JsonElement str : ja) {
|
||||
Kind kind = gson.fromJson(str, Kind.class);
|
||||
|
||||
Button btn = new Button();
|
||||
btn.setText(kind.getVorname());
|
||||
|
||||
kindDaten.add(btn, 0, 5);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
status.setText("Account nicht gefunden");
|
||||
return;
|
||||
}
|
||||
|
||||
email.setText(acc.getEmail());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,7 @@
|
||||
<right>
|
||||
<HBox styleClass="button-untenrechts">
|
||||
<Label fx:id="status"/>
|
||||
<Button text="Laden" onAction="#onLaden"/>
|
||||
<Button text="Speichern" defaultButton="true" onAction="#onSpeichern"/>
|
||||
</HBox>
|
||||
</right>
|
||||
|
Loading…
Reference in New Issue
Block a user