diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index b42152a..99a75eb 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -118,7 +118,6 @@ public class DataController { } public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { - ArrayList eventList = new ArrayList<>(); try { Tuple response = httpRequest.sendPostRequest( ALL_EVENTS_ENDPOINT, @@ -133,28 +132,40 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); - eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>() { - }); - + return (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>() {}); } catch (HttpRequestException e) { throw e; } catch (Exception e) { throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } - - return eventList; } /******** * User * ********/ - /* + public List getUser() throws HttpRequestException { + String userJSON = sendBasicHttpRequest( + ALL_USER_ENDPOINT, + "", + true + ); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + try { + return objectMapper.readValue(userJSON, new TypeReference>() {}); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return new ArrayList<>(); + } + public void createUser(User user) throws HttpRequestException { sendBasicHttpRequest( ADD_USER_ENDPOINT, - user.getAsUrlParam(), + "", true ); } @@ -162,7 +173,7 @@ public class DataController { public void deleteUser(User user) throws HttpRequestException { sendBasicHttpRequest( DELETE_USER_ENDPOINT, - user.getAsUrlParam(), + "userId=" + user.getUserId(), true ); } @@ -170,13 +181,12 @@ public class DataController { public void editUser(User oldUser, User user) throws HttpRequestException { sendBasicHttpRequest( EDIT_USER_ENDPOINT, - user.getAsUrlParam(), + "", true ); } - */ - private void sendBasicHttpRequest(String urlString, String urlParameters, boolean sendAuth) throws HttpRequestException { + private String sendBasicHttpRequest(String urlString, String urlParameters, boolean sendAuth) throws HttpRequestException { try { Tuple response = httpRequest.sendPostRequest( urlString, @@ -186,6 +196,8 @@ public class DataController { if (response.getKey() != 200) { throw new HttpRequestException(response); } + + return response.getValue(); } catch (HttpRequestException e) { throw e; } catch (Exception e) { diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/res/User.java index 5ff062d..c917e7e 100644 --- a/client/data/src/main/java/res/User.java +++ b/client/data/src/main/java/res/User.java @@ -2,28 +2,28 @@ package res; public class User { - private int id; - private String loginName; + private int userId; + private String login; private String forename; private String name; + private boolean isAdmin; - public User(){ + public User(){} + + public int getUserId() { + return userId; } - public int getId() { - return id; + public void setUserId(int userId) { + this.userId = userId; } - public void setId(int id) { - this.id = id; + public String getLogin() { + return login; } - public String getLoginName() { - return loginName; - } - - public void setLoginName(String loginName) { - this.loginName = loginName; + public void setLogin(String login) { + this.login = login; } public String getForename() { @@ -41,4 +41,12 @@ public class User { public void setName(String name) { this.name = name; } + + public boolean isAdmin() { + return isAdmin; + } + + public void setAdmin(boolean admin) { + isAdmin = admin; + } }