Map user with JSON
This commit is contained in:
parent
4aafae9896
commit
f133257194
@ -118,7 +118,6 @@ public class DataController {
|
||||
}
|
||||
|
||||
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException {
|
||||
ArrayList<Event> eventList = new ArrayList<>();
|
||||
try {
|
||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||
ALL_EVENTS_ENDPOINT,
|
||||
@ -133,28 +132,40 @@ public class DataController {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.findAndRegisterModules();
|
||||
eventList = (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>() {
|
||||
});
|
||||
|
||||
return (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>() {});
|
||||
|
||||
} 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<User> getUser() throws HttpRequestException {
|
||||
String userJSON = sendBasicHttpRequest(
|
||||
ALL_USER_ENDPOINT,
|
||||
"",
|
||||
true
|
||||
);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.findAndRegisterModules();
|
||||
try {
|
||||
return objectMapper.readValue(userJSON, new TypeReference<List<User>>() {});
|
||||
} 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<Integer, String> 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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user