samu_masken #10
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -8,7 +8,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</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>
|
@ -11,7 +11,6 @@ public class Kind {
|
|||||||
private String vorname;
|
private String vorname;
|
||||||
private int bid;
|
private int bid;
|
||||||
|
|
||||||
// TODO Zutat implementieren!
|
|
||||||
private ArrayList<Zutat> filter;
|
private ArrayList<Zutat> filter;
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@ -48,8 +47,6 @@ public class Kind {
|
|||||||
this.bid = bid;
|
this.bid = bid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Zutat implementieren!
|
|
||||||
|
|
||||||
public ArrayList<Zutat> getFilter() {
|
public ArrayList<Zutat> getFilter() {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ 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 java.nio.file.WatchEvent;
|
|
||||||
|
|
||||||
import Logik.Kind;
|
import Logik.Kind;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@ -28,20 +27,10 @@ public class RestApiClient implements IRestAPI{
|
|||||||
gson = new Gson();
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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) {
|
||||||
@ -67,8 +56,10 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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) {
|
||||||
@ -97,9 +88,11 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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) {
|
||||||
@ -123,8 +116,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) {
|
||||||
@ -150,7 +146,10 @@ 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) {
|
||||||
@ -177,12 +176,33 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user