diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index 58d1ea6..ad81707 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -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); } } diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index f920bac..90640d3 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -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 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 getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { ArrayList eventList = new ArrayList<>(); try { diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index efabe57..179f622 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -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 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,