Added user methods
This commit is contained in:
parent
c4e24549d5
commit
2147ca1ad8
@ -52,13 +52,6 @@ public class DataController {
|
||||
|
||||
USER_ID = Long.parseLong(data[1]);
|
||||
HttpRequest.TOKEN = data[0];
|
||||
|
||||
Tuple<Integer, String> auth = httpRequest.sendPostRequest(
|
||||
HEADER_TEST_ENDPOINT,
|
||||
"",
|
||||
true
|
||||
);
|
||||
System.out.println("auth " + auth);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@ -88,40 +81,27 @@ public class DataController {
|
||||
return USER_ID >= 0;
|
||||
}
|
||||
|
||||
/*********
|
||||
* Event *
|
||||
*********/
|
||||
public void createEvent(Event event) throws HttpRequestException {
|
||||
try {
|
||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam(), true);
|
||||
if(response.getKey() != 200){
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
}catch (HttpRequestException e){
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600);
|
||||
}
|
||||
sendBasicHttpRequest(
|
||||
ADD_EVENT_ENDPOINT,
|
||||
event.getAsUrlParam(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public void deleteEvent(int userId, int eventId, LocalDateTime date) throws HttpRequestException {
|
||||
try {
|
||||
System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate());
|
||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||
sendBasicHttpRequest(
|
||||
DELETE_EVENT_ENDPOINT,
|
||||
"userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(),
|
||||
true
|
||||
);
|
||||
if(response.getKey() != 200){
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
}catch (HttpRequestException e){
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600);
|
||||
}
|
||||
}
|
||||
|
||||
public void editEvent(Event oldEvent, Event event) throws HttpRequestException {
|
||||
try {
|
||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||
sendBasicHttpRequest(
|
||||
EDIT_EVENT_ENDPOINT,
|
||||
"eventId=" + oldEvent.getId() +
|
||||
"&userId=" + oldEvent.getOwnerId() +
|
||||
@ -135,14 +115,6 @@ public class DataController {
|
||||
"&newIsPrivate=" + event.isPrivate(),
|
||||
true
|
||||
);
|
||||
if(response.getKey() != 200){
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
}catch (HttpRequestException e){
|
||||
throw e;
|
||||
}catch (Exception e) {
|
||||
throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException {
|
||||
@ -161,7 +133,8 @@ public class DataController {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.findAndRegisterModules();
|
||||
eventList = (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>(){});
|
||||
eventList = (ArrayList<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>() {
|
||||
});
|
||||
|
||||
|
||||
} catch (HttpRequestException e) {
|
||||
@ -173,5 +146,50 @@ public class DataController {
|
||||
return eventList;
|
||||
}
|
||||
|
||||
/********
|
||||
* User *
|
||||
********/
|
||||
|
||||
/*
|
||||
public void createUser(User user) throws HttpRequestException {
|
||||
sendBasicHttpRequest(
|
||||
ADD_USER_ENDPOINT,
|
||||
user.getAsUrlParam(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public void deleteUser(User user) throws HttpRequestException {
|
||||
sendBasicHttpRequest(
|
||||
DELETE_USER_ENDPOINT,
|
||||
user.getAsUrlParam(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
try {
|
||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||
urlString,
|
||||
urlParameters,
|
||||
sendAuth
|
||||
);
|
||||
if (response.getKey() != 200) {
|
||||
throw new HttpRequestException(response);
|
||||
}
|
||||
} catch (HttpRequestException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user