diff --git a/hellofx/app/src/main/java/client/CreateEventController.java b/hellofx/app/src/main/java/client/CreateEventController.java index c2096ec..82d40a0 100644 --- a/hellofx/app/src/main/java/client/CreateEventController.java +++ b/hellofx/app/src/main/java/client/CreateEventController.java @@ -11,9 +11,6 @@ import javafx.stage.Stage; import res.DataController; import res.Event; -import java.time.LocalDateTime; -import java.util.ArrayList; - public class CreateEventController { @FXML @@ -57,7 +54,7 @@ public class CreateEventController { System.out.println(event.getAsUrlParam()); DataController dataController = new DataController(); - dataController.CreateEvent(event); + dataController.createEvent(event); Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stage.close(); diff --git a/hellofx/app/src/main/java/client/MainController.java b/hellofx/app/src/main/java/client/MainController.java index b49f8ff..542acc9 100644 --- a/hellofx/app/src/main/java/client/MainController.java +++ b/hellofx/app/src/main/java/client/MainController.java @@ -122,9 +122,9 @@ public class MainController { Button deleteBtn = new Button(); deleteBtn.setText(" X "); deleteBtn.setOnAction(e -> { - LocalDateTime eventDate = event.getDate(); - int day = (int)Duration.between(weekStartDateTime.toLocalDate().atStartOfDay(), eventDate.toLocalDate().atStartOfDay()).toDays(); - dayVBoxes[day].getChildren().remove(vBox); + DataController dataController = new DataController(); + dataController.deleteEvent(event.getId()); + updateEvents(); }); Button editBtn = new Button(); editBtn.setText("edit"); diff --git a/hellofx/data/src/main/java/res/DataController.java b/hellofx/data/src/main/java/res/DataController.java index 0318fcc..ddc826d 100644 --- a/hellofx/data/src/main/java/res/DataController.java +++ b/hellofx/data/src/main/java/res/DataController.java @@ -17,14 +17,15 @@ public class DataController { private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/vpr/all-events"; private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/vpr/all-users"; private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/vpr/add-event"; + private static final String DELETE_EVENT_ENDPOINT = "http://localhost:8080/vpr/del-event"; - private HttpRequest httpRequest; + private final HttpRequest httpRequest; public DataController(){ httpRequest = new HttpRequest(); } - public void CreateEvent(Event event){ + public void createEvent(Event event){ try { System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam())); } catch (Exception e) { @@ -32,6 +33,14 @@ public class DataController { } } + public void deleteEvent(int eventId){ + try { + System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId)); + } catch (Exception e) { + e.printStackTrace(); + } + } + public ArrayList getAllVisibleEvents() { ArrayList eventList = new ArrayList<>();