Compare commits
No commits in common. "0f52f19fc7c16cd49f74474d23d3dbcc4d46e46c" and "0a8d4e47ac7abb99c8cae9da51d5861d175e0a29" have entirely different histories.
0f52f19fc7
...
0a8d4e47ac
@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
|
|
||||||
import Logik.ElternAccount;
|
import Logik.ElternAccount;
|
||||||
import Logik.Kind;
|
import Logik.Kind;
|
||||||
import com.google.gson.*;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* noch nicht getestet
|
* noch nicht getestet
|
||||||
@ -32,8 +32,8 @@ public class RestApiClient implements IRestAPI{
|
|||||||
|
|
||||||
RestApiClient client1 = new RestApiClient();
|
RestApiClient client1 = new RestApiClient();
|
||||||
|
|
||||||
|
client1.post("Gericht", "{\"name\" : \"Svens Beine\", \"69.69\", \"beschreibung\" : \"Muss net schmegge, muss wirge\"}");
|
||||||
|
|
||||||
System.out.println(client1.nextId("Benutzer"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,9 +54,11 @@ 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();
|
||||||
}
|
}
|
||||||
@ -208,34 +210,4 @@ public class RestApiClient implements IRestAPI{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int nextId(String controllerName){
|
|
||||||
URI apiUri = URI.create(String.format("%s/%s/nextId", urlBase, controllerName));
|
|
||||||
|
|
||||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
||||||
.uri(apiUri)
|
|
||||||
.GET()
|
|
||||||
.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());
|
|
||||||
|
|
||||||
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
|
||||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
|
||||||
|
|
||||||
JsonObject json = jsonArray.get(0).getAsJsonObject();
|
|
||||||
|
|
||||||
return json.get("auto_increment").getAsInt();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user