Merge remote-tracking branch 'origin/merge' into merge

# Conflicts:
#	client/data/src/main/java/res/Event.java
This commit is contained in:
2022-01-10 13:24:42 +01:00
10 changed files with 80 additions and 70 deletions

View File

@@ -25,16 +25,16 @@ public class DataController {
private final HttpRequest httpRequest;
public DataController(){
public DataController() {
httpRequest = new HttpRequest();
}
public boolean login(String username, String password){
public boolean login(String username, String password) {
try {
USER_ID = Long.parseLong(httpRequest.sendPostRequest(
LOGIN_ENDPOINT,
"login=" + username
+ "&password=" + password
+ "&password=" + password
));
} catch (Exception e) {
e.printStackTrace();
@@ -43,7 +43,7 @@ public class DataController {
return USER_ID >= 0;
}
public void createEvent(Event event){
public void createEvent(Event event) {
try {
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
} catch (Exception e) {
@@ -51,7 +51,7 @@ public class DataController {
}
}
public void deleteEvent(int eventId){
public void deleteEvent(int eventId) {
try {
System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId));
} catch (Exception e) {
@@ -69,10 +69,10 @@ public class DataController {
ObjectMapper objectMapper = new ObjectMapper();
//String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }";
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)){
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
ArrayList<Object> list = new ArrayList<>();
if (obj.getClass().isArray()) {
list = (ArrayList<Object>) Arrays.asList((Object[])obj);
list = (ArrayList<Object>) Arrays.asList((Object[]) obj);
} else if (obj instanceof Collection) {
list = new ArrayList<>((Collection<?>) obj);
}

View File

@@ -9,7 +9,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class HttpRequest {
public String sendPostRequest(String urlString, String urlParameters) throws Exception{
public String sendPostRequest(String urlString, String urlParameters) throws Exception {
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
@@ -46,7 +46,7 @@ public class HttpRequest {
}
}
public String sendGetRequest(String urlString) throws Exception{
public String sendGetRequest(String urlString) throws Exception {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");