Compare commits

..

No commits in common. "78ca0419d8117a7b3e4a666266082c5aef87acff" and "3832d5a3262f6c9f6b25182469fc10d6847584c9" have entirely different histories.

3 changed files with 28 additions and 45 deletions

2
.idea/misc.xml generated
View File

@ -8,7 +8,7 @@
</list>
</option>
</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

@ -11,6 +11,7 @@ public class Kind {
private String vorname;
private int bid;
// TODO Zutat implementieren!
private ArrayList<Zutat> filter;
// endregion
@ -47,6 +48,8 @@ public class Kind {
this.bid = bid;
}
// TODO Zutat implementieren!
public ArrayList<Zutat> getFilter() {
return filter;
}

View File

@ -5,6 +5,7 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.WatchEvent;
import Logik.Kind;
import com.google.gson.Gson;
@ -27,10 +28,20 @@ public class RestApiClient implements IRestAPI{
gson = new Gson();
}
public static void main(String[] args){
Kind kind = new Kind("Klein", "Kevin", 2);
String json = new Gson().toJson(kind);
new RestApiClient().post("Kind", json);
}
/**
* Methode für einen Get-Aufruf. Ruft alle Elemente einer Tabelle auf.
*
* @param controllerName Name des aufzurufenden Controllers
* @param controllerName
*/
@Override
public void get(String controllerName) {
@ -56,10 +67,8 @@ public class RestApiClient implements IRestAPI{
}
/**
* Methode für einen Get-Aufruf. Ruft ein spezifisches Element auf.
*
* @param controllerName Name des aufzurufenden Controllers
* @param id Id der Aufzurufenden Zeile
* @param controllerName
* @param id
*/
@Override
public void get(String controllerName, int id) {
@ -88,11 +97,9 @@ public class RestApiClient implements IRestAPI{
}
/**
* Methode für einen Get-Aufruf. Ruft ein spezielles Element auf.
*
* @param controllerName Name des aufzurufenden Controllers
* @param id Id der Aufzurufenden Zeile
* @param bezahlt TODO Warum ist das hier?
* @param controllerName
* @param id
* @param bezahlt
*/
@Override
public void get(String controllerName, int id, boolean bezahlt) {
@ -116,11 +123,8 @@ public class RestApiClient implements IRestAPI{
}
/**
* Methode für einen Put-Aufruf. Aktualisiert einen Eintrag.
*
* @param controllerName Name des aufzurufenden Controllers.
* @param id Id des zu änderenden Eintrags.
* @param jsonData JsonString mit den neuen Daten.
* @param controllerName
* @param id
*/
@Override
public void put(String controllerName, int id, String jsonData) {
@ -146,10 +150,7 @@ public class RestApiClient implements IRestAPI{
}
/**
* 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.
* @param controllerName
*/
@Override
public void post(String controllerName, String jsonData) {
@ -176,33 +177,12 @@ public class RestApiClient implements IRestAPI{
}
/**
* Methode für einen Delete-Aufruf. Löscht einen Eintrag mit einer Id.
*
* @param controllerName Name des aufzurufenden Controllers
* @param id Id des zu löschenden Eintrags.
* @param controllerName
* @param id
*/
@Override
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();
}
}
}