Compare commits
No commits in common. "78ca0419d8117a7b3e4a666266082c5aef87acff" and "3832d5a3262f6c9f6b25182469fc10d6847584c9" have entirely different histories.
78ca0419d8
...
3832d5a326
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_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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -11,6 +11,7 @@ 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
|
||||||
|
|
||||||
@ -47,6 +48,8 @@ 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,6 +5,7 @@ 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;
|
||||||
@ -27,10 +28,20 @@ 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode für einen Get-Aufruf. Ruft alle Elemente einer Tabelle auf.
|
* @param controllerName
|
||||||
*
|
|
||||||
* @param controllerName Name des aufzurufenden Controllers
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void get(String controllerName) {
|
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
|
||||||
*
|
* @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) {
|
||||||
@ -88,11 +97,9 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode für einen Get-Aufruf. Ruft ein spezielles Element auf.
|
* @param controllerName
|
||||||
*
|
* @param id
|
||||||
* @param controllerName Name des aufzurufenden Controllers
|
* @param bezahlt
|
||||||
* @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) {
|
||||||
@ -116,11 +123,8 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode für einen Put-Aufruf. Aktualisiert einen Eintrag.
|
* @param controllerName
|
||||||
*
|
* @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) {
|
||||||
@ -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
|
||||||
*
|
|
||||||
* @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) {
|
||||||
@ -176,33 +177,12 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methode für einen Delete-Aufruf. Löscht einen Eintrag mit einer Id.
|
* @param controllerName
|
||||||
*
|
* @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…
x
Reference in New Issue
Block a user