Merge remote-tracking branch 'origin/master' into SvenAccountverwaltung
# Conflicts: # src/main/java/RestAPISchnittstelle/RestApiClient.java
This commit is contained in:
commit
8e1084f034
@ -7,8 +7,9 @@
|
|||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -8,9 +8,11 @@ public class Account {
|
|||||||
// region Felder
|
// region Felder
|
||||||
private String passwort;
|
private String passwort;
|
||||||
|
|
||||||
private int id;
|
private transient int id;
|
||||||
|
|
||||||
private String benutzername;
|
private String name;
|
||||||
|
|
||||||
|
private int rid;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Getter & Setter
|
// region Getter & Setter
|
||||||
@ -32,18 +34,23 @@ public class Account {
|
|||||||
|
|
||||||
|
|
||||||
public String getBenutzername() {
|
public String getBenutzername() {
|
||||||
return benutzername;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBenutzername(String benutzername) {
|
public void setBenutzername(String benutzername) {
|
||||||
this.benutzername = benutzername;
|
this.name = benutzername;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Konstruktoren
|
// region Konstruktoren
|
||||||
public Account(String passwort, String benutzername) {
|
public Account(String passwort, String name) {
|
||||||
this.passwort = passwort;
|
this.passwort = passwort;
|
||||||
this.benutzername = benutzername;
|
this.name = name;
|
||||||
|
|
||||||
|
if(this instanceof MitarbeiterAccount)
|
||||||
|
rid = 0;
|
||||||
|
else if (this instanceof ElternAccount)
|
||||||
|
rid = 1;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -7,15 +7,14 @@
|
|||||||
|
|
||||||
package Logik;
|
package Logik;
|
||||||
|
|
||||||
import java.nio.file.WatchEvent;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Benutzer extends Account {
|
public class ElternAccount extends Account {
|
||||||
|
|
||||||
// region Felder
|
// region Felder
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
private ArrayList<Kind> kinder;
|
private transient ArrayList<Kind> kinder;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Getter & Setter
|
// region Getter & Setter
|
||||||
@ -37,7 +36,7 @@ public class Benutzer extends Account {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Konstruktoren
|
// region Konstruktoren
|
||||||
public Benutzer(String passwort, String benutzername, String email) {
|
public ElternAccount(String passwort, String benutzername, String email) {
|
||||||
super(passwort, benutzername);
|
super(passwort, benutzername);
|
||||||
this.email = email;
|
this.email = email;
|
||||||
kinder = new ArrayList<>();
|
kinder = new ArrayList<>();
|
@ -5,10 +5,12 @@ import java.util.ArrayList;
|
|||||||
public class Kind {
|
public class Kind {
|
||||||
|
|
||||||
// region Felder
|
// region Felder
|
||||||
|
|
||||||
|
private transient int id;
|
||||||
private String name;
|
private String name;
|
||||||
private String vorname;
|
private String vorname;
|
||||||
private int id;
|
private int bid;
|
||||||
// TODO Zutat implementieren!
|
|
||||||
private ArrayList<Zutat> filter;
|
private ArrayList<Zutat> filter;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@ -37,7 +39,13 @@ public class Kind {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Zutat implementieren!
|
public int getBid() {
|
||||||
|
return bid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBid(int bid) {
|
||||||
|
this.bid = bid;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Zutat> getFilter() {
|
public ArrayList<Zutat> getFilter() {
|
||||||
return filter;
|
return filter;
|
||||||
@ -49,10 +57,12 @@ public class Kind {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Konstruktoren
|
// region Konstruktoren
|
||||||
public Kind(String name, String vorname) {
|
public Kind(String name, String vorname, int bid) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.vorname = vorname;
|
this.vorname = vorname;
|
||||||
|
this.bid = bid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class MitarbeiterAccount extends Account {
|
|||||||
* @param kinder Eine Liste mit allen zugehörigen Kindern des Accounts
|
* @param kinder Eine Liste mit allen zugehörigen Kindern des Accounts
|
||||||
*/
|
*/
|
||||||
public void accountErstellen(String passwort, String benutzername, String email, ArrayList<Kind> kinder) {
|
public void accountErstellen(String passwort, String benutzername, String email, ArrayList<Kind> kinder) {
|
||||||
Benutzer newAccount = new Benutzer(passwort, benutzername, email);
|
ElternAccount newAccount = new ElternAccount(passwort, benutzername, email);
|
||||||
newAccount.setKinder(kinder);
|
newAccount.setKinder(kinder);
|
||||||
// Id muss aus der Datenbank geholt werden und dann gesetzt werden
|
// Id muss aus der Datenbank geholt werden und dann gesetzt werden
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,45 @@
|
|||||||
/**
|
|
||||||
* @author Samuel Wolff
|
|
||||||
* noch nicht getestet
|
|
||||||
* TODO FERTIG MACHEN
|
|
||||||
*/
|
|
||||||
|
|
||||||
package RestAPISchnittstelle;
|
package RestAPISchnittstelle;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import Logik.ElternAccount;
|
||||||
|
import Logik.Kind;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* noch nicht getestet
|
||||||
|
* TODO FERTIG MACHEN
|
||||||
|
* @author Samuel Wolff
|
||||||
|
*/
|
||||||
public class RestApiClient implements IRestAPI{
|
public class RestApiClient implements IRestAPI{
|
||||||
|
|
||||||
private final String urlBase = "https://pbg2h22awo.web.pb.bib.de/VPR_Schnittstelle/VPR_Schnittstelle/restAPI.php";
|
private final String urlBase = "https://pbg2h22awo.web.pb.bib.de/VPR_Schnittstelle/VPR_Schnittstelle/restAPI.php";
|
||||||
|
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
|
|
||||||
|
private final Gson gson;
|
||||||
|
|
||||||
public RestApiClient(){
|
public RestApiClient(){
|
||||||
client = HttpClient.newHttpClient();
|
client = HttpClient.newHttpClient();
|
||||||
|
gson = new Gson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
new RestApiClient().post("Benutzerkonto", "{\"name\":\"Sven\", \"email\":\"svenmail\", \"passwort\":\"5678765\", \"rid\":\"0\"}");
|
|
||||||
|
RestApiClient client1 = new RestApiClient();
|
||||||
|
|
||||||
|
client1.post("Gericht", "{\"name\" : \"Svens Beine\", \"69.69\", \"beschreibung\" : \"Muss net schmegge, muss wirge\"}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Get-Aufruf. Ruft alle Elemente einer Tabelle auf.
|
||||||
|
*
|
||||||
|
* @param controllerName Name des aufzurufenden Controllers
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void get(String controllerName) {
|
public void get(String controllerName) {
|
||||||
@ -47,17 +54,21 @@ public class RestApiClient implements IRestAPI{
|
|||||||
// Send the request and get the response
|
// Send the request and get the response
|
||||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
|
Kind test = gson.fromJson(httpResponse.body(), Kind.class);
|
||||||
|
|
||||||
// Print the response status code and body
|
// Print the response status code and body
|
||||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
System.out.println("Status Code: " + httpResponse.statusCode());
|
||||||
System.out.println("Response Body: " + httpResponse.body());
|
System.out.println("Response Body: " + test.getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Get-Aufruf. Ruft ein spezifisches Element auf.
|
||||||
* @param id
|
*
|
||||||
|
* @param controllerName Name des aufzurufenden Controllers
|
||||||
|
* @param id Id der Aufzurufenden Zeile
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void get(String controllerName, int id) {
|
public void get(String controllerName, int id) {
|
||||||
@ -73,17 +84,20 @@ public class RestApiClient implements IRestAPI{
|
|||||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
// Print the response status code and body
|
// Print the response status code and body
|
||||||
System.out.println("Status Code: " + httpResponse.statusCode());
|
System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
|
||||||
System.out.println("Response Body: " + httpResponse.body());
|
|
||||||
|
//System.out.println("Response Body: " + test);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Get-Aufruf. Ruft ein spezielles Element auf.
|
||||||
* @param id
|
*
|
||||||
* @param bezahlt
|
* @param controllerName Name des aufzurufenden Controllers
|
||||||
|
* @param id Id der Aufzurufenden Zeile
|
||||||
|
* @param bezahlt TODO Warum ist das hier?
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void get(String controllerName, int id, boolean bezahlt) {
|
public void get(String controllerName, int id, boolean bezahlt) {
|
||||||
@ -107,8 +121,11 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Put-Aufruf. Aktualisiert einen Eintrag.
|
||||||
* @param id
|
*
|
||||||
|
* @param controllerName Name des aufzurufenden Controllers.
|
||||||
|
* @param id Id des zu änderenden Eintrags.
|
||||||
|
* @param jsonData JsonString mit den neuen Daten.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void put(String controllerName, int id, String jsonData) {
|
public void put(String controllerName, int id, String jsonData) {
|
||||||
@ -134,20 +151,63 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Post-Aufruf. Fügt einen Eintrag in eine Datenbank hinzu.
|
||||||
|
*
|
||||||
|
* @param controllerName Name des aufzurufenden Controllers.
|
||||||
|
* @param jsonData JsonString mit den Daten des Eintrags.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void post(String controllerName, String jsonData) {
|
public void post(String controllerName, String jsonData) {
|
||||||
|
URI apiUri = URI.create(String.format("%s/%s", urlBase,controllerName));
|
||||||
|
|
||||||
|
System.out.println(apiUri);
|
||||||
|
|
||||||
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||||
|
.uri(apiUri)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(jsonData, StandardCharsets.UTF_8))
|
||||||
|
.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());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param controllerName
|
* Methode für einen Delete-Aufruf. Löscht einen Eintrag mit einer Id.
|
||||||
* @param id
|
*
|
||||||
|
* @param controllerName Name des aufzurufenden Controllers
|
||||||
|
* @param id Id des zu löschenden Eintrags.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void delete(String controllerName, int id) {
|
public void delete(String controllerName, int id) {
|
||||||
|
URI apiUri = URI.create(String.format("%s/%s/%d", urlBase,controllerName, id));
|
||||||
|
|
||||||
|
System.out.println(apiUri);
|
||||||
|
|
||||||
|
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||||
|
.uri(apiUri)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.DELETE()
|
||||||
|
.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());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ module de.subway_surfers.vpr_app {
|
|||||||
requires com.google.gson;
|
requires com.google.gson;
|
||||||
|
|
||||||
|
|
||||||
opens de.subway_surfers.vpr_app to javafx.fxml;
|
opens de.subway_surfers.vpr_app to javafx.fxml, com.google.gson;
|
||||||
|
opens Logik to com.google.gson;
|
||||||
exports de.subway_surfers.vpr_app;
|
exports de.subway_surfers.vpr_app;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user