god knows what I did here
This commit is contained in:
@@ -5,9 +5,12 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import Logik.ElternAccount;
|
||||
import Logik.Kind;
|
||||
import Logik.Mahlzeit;
|
||||
import Logik.Tagesplan;
|
||||
import com.google.gson.*;
|
||||
|
||||
/**
|
||||
@@ -33,7 +36,10 @@ public class RestApiClient implements IRestAPI{
|
||||
RestApiClient client1 = new RestApiClient();
|
||||
|
||||
|
||||
System.out.println(client1.nextId("Benutzer"));
|
||||
Tagesplan t = client1.getGerichteOnTag("2023-12-17");
|
||||
|
||||
for(Mahlzeit m : t.getGerichte())
|
||||
System.out.println(m);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,7 +221,6 @@ public class RestApiClient implements IRestAPI{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int nextId(String controllerName){
|
||||
URI apiUri = URI.create(String.format("%s/%s/nextId", urlBase, controllerName));
|
||||
|
||||
@@ -245,4 +250,81 @@ public class RestApiClient implements IRestAPI{
|
||||
}
|
||||
}
|
||||
|
||||
public boolean anmeldeVersuch(String credentials){
|
||||
|
||||
JsonObject json = gson.fromJson(credentials, JsonObject.class);
|
||||
String benutzer = json.get("Benutzername").toString();
|
||||
benutzer = benutzer.substring(1, benutzer.length()-1);
|
||||
|
||||
String passwort = json.get("passwort").toString();
|
||||
passwort = passwort.substring(1, passwort.length()-1);
|
||||
|
||||
URI apiUri = URI.create(String.format("%s/Benutzer/anmeldeVersuch?Benutzername=%s&passwort=%s", urlBase, benutzer, passwort));
|
||||
System.out.println(apiUri);
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||
.uri(apiUri)
|
||||
.header("Content-Type", "application/json")
|
||||
.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());
|
||||
if(httpResponse.body().equals("true"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Tagesplan getGerichteOnTag(String datum){
|
||||
|
||||
URI apiUri = URI.create(String.format("%s/Tagesplan/getGerichteOnTag?datum=%s", urlBase, datum));
|
||||
System.out.println(apiUri);
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
||||
.uri(apiUri)
|
||||
.header("Content-Type", "application/json")
|
||||
.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());
|
||||
|
||||
Tagesplan t = new Tagesplan(datum);
|
||||
|
||||
JsonElement jsonElement = JsonParser.parseString(httpResponse.body());
|
||||
|
||||
JsonArray json = jsonElement.getAsJsonArray();
|
||||
|
||||
for(int i = 0; i< json.size(); i++){
|
||||
|
||||
JsonObject o = json.get(i).getAsJsonObject();
|
||||
String name = o.get("name").getAsString();
|
||||
float preis = o.get("preis").getAsFloat();
|
||||
String beschreibung = o.get("beschreibung").getAsString();
|
||||
|
||||
t.getGerichte().add(new Mahlzeit(name, preis, beschreibung));
|
||||
|
||||
}
|
||||
|
||||
return t;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user