Use edit-event-endpoint to edit events

This commit is contained in:
Marc Beyer 2022-01-25 19:37:49 +01:00
parent 5e9a09fc7d
commit c4e24549d5
3 changed files with 34 additions and 68 deletions

View File

@ -30,13 +30,9 @@ public class EditEventController extends CreateEventController{
//timeEnd.setValue(currentEvent.getEnd());
}
@Override
protected void sendHttpRequest(Event event) throws HttpRequestException {
DataController dataController = new DataController();
dataController.deleteEvent(currentEvent.getOwnerId(), currentEvent.getId(), currentEvent.getDate());
dataController.createEvent(event);
dataController.editEvent(currentEvent, event);
}
}

View File

@ -23,10 +23,15 @@ public class DataController {
private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all";
private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add";
private static final String DELETE_EVENT_ENDPOINT = "http://localhost:8080/event/del";
private static final String EDIT_EVENT_ENDPOINT = "http://localhost:8080/event/edit";
private static final String ALL_USER_ENDPOINT = "http://localhost:8080/user/all";
private static final String ADD_USER_ENDPOINT = "http://localhost:8080/user/add";
private static final String DELETE_USER_ENDPOINT = "http://localhost:8080/user/del";
private static final String EDIT_USER_ENDPOINT = "http://localhost:8080/user/edit";
private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login";
private static final String LOGIN_WITH_TOKEN_ENDPOINT = "http://localhost:8080/user/login-with-token";
private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all";
private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test";
private final HttpRequest httpRequest;
@ -114,6 +119,32 @@ public class DataController {
}
}
public void editEvent(Event oldEvent, Event event) throws HttpRequestException {
try {
Tuple<Integer, String> response = httpRequest.sendPostRequest(
EDIT_EVENT_ENDPOINT,
"eventId=" + oldEvent.getId() +
"&userId=" + oldEvent.getOwnerId() +
"&date=" + oldEvent.getDate().toLocalDate() +
"&newDate=" + event.getDate().toLocalDate() +
"&newName=" + event.getName() +
"&newStart=" + event.getStart() +
"&newEnd=" + event.getEnd() +
"&newPriority=" + event.getPriority() +
"&newIsFullDay=" + event.isFullDay() +
"&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 {
ArrayList<Event> eventList = new ArrayList<>();
try {

View File

@ -30,68 +30,7 @@ public class Event {
private int ownerId;
private String ownerName;
/*
Constructor for SELECT:
e.id AS eid,
e.name AS ename,
e.start,
e.end,
e.priority,
e.is_full_day,
ue.date,
u.id AS uid,
u.forename,
u.name AS uname
*/
public Event() {
}
public Event(ArrayList<Object> arr) {
id = (int) arr.get(0);
name = (String) arr.get(1);
start = (String) arr.get(2);
end = (String) arr.get(3);
priority = (int) arr.get(4);
isFullDay = (Boolean) arr.get(5); //((String)arr.get(5)).equals("true");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
date = LocalDateTime.parse(arr.get(6) + " 00:00", formatter);
ownerId = (int) arr.get(7);
ownerName = arr.get(8) + " " + arr.get(9);
}
public Event(
int id,
String name,
int priority,
boolean isFullDay,
boolean isPrivate,
String start,
String end,
String date,
int ownerId,
String ownerName
) {
this.ownerId = ownerId;
this.ownerName = ownerName;
this.id = id;
this.name = name;
this.start = start;
this.end = end;
this.priority = priority;
this.isFullDay = isFullDay;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
this.date = LocalDateTime.parse(date + " 00:00", formatter);
}
public Event() {}
public Event(String name,
int priority,