Compare commits

...

4 Commits

4 changed files with 20 additions and 8 deletions

View File

@ -3,6 +3,8 @@
package Logik;
import RestAPISchnittstelle.RestApiClient;
public class Account {
// region Felder
@ -14,7 +16,6 @@ public class Account {
private String email;
private int rid;
// endregion
@ -57,6 +58,7 @@ public class Account {
public Account(String passwort, String name, String email) {
this.passwort = passwort;
this.name = name;
this.email = email;
if(this instanceof MitarbeiterAccount)
rid = 0;
@ -64,5 +66,4 @@ public class Account {
rid = 1;
}
// endregion
}

View File

@ -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()
@ -57,8 +57,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;
}
}
@ -69,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()
@ -84,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;
}
}
@ -98,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()
@ -113,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;
}
}

View File

@ -138,6 +138,9 @@ public class AccounterstellungMitarbeiter {
status.setText("Daten Erfolgreich gespeichert");
einmalpw.setText(einmalPwGenerieren());
RestApiClient api = new RestApiClient();
int id = api.nextId("Benutzer");
//String json = String.format("{\"name\":\"%s\", \"email\":\"%s\", \"passwort\":\"%d\", \"rid\":\"%d\"}",
// accountname.getText(), email.getText(), einmalpw.getText().hashCode(), (typMitarbeiter.isSelected() ? 0:1));
@ -145,6 +148,7 @@ public class AccounterstellungMitarbeiter {
Account neuer;
if (typEltern.isSelected()) {
neuer = new ElternAccount(String.format("%d",einmalpw.getText().hashCode()), accountname.getText(), email.getText());
System.out.println(neuer.getEmail());
for (Kind k : kinder) {
((ElternAccount)neuer).getKinder().add(k);
}
@ -161,10 +165,10 @@ public class AccounterstellungMitarbeiter {
Gson gson = new Gson();
System.out.println(gson.toJson(neuer));
RestApiClient api = new RestApiClient();
api.post("Benutzer", gson.toJson(neuer));
if (neuer instanceof ElternAccount) {
for (Kind k : ((ElternAccount)neuer).getKinder()) {
k.setBid(id);
api.post("Kind", gson.toJson(k));
}
}
@ -172,7 +176,5 @@ public class AccounterstellungMitarbeiter {
else {
status.setText("Accounterstellung Fehlgeschlagen");
}
}
}

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;