Added delete event functionality

This commit is contained in:
Marc Beyer 2021-11-28 18:22:36 +01:00
parent e8c7fb8a08
commit 1a8bbbfce7
3 changed files with 15 additions and 9 deletions

View File

@ -11,9 +11,6 @@ import javafx.stage.Stage;
import res.DataController; import res.DataController;
import res.Event; import res.Event;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class CreateEventController { public class CreateEventController {
@FXML @FXML
@ -57,7 +54,7 @@ public class CreateEventController {
System.out.println(event.getAsUrlParam()); System.out.println(event.getAsUrlParam());
DataController dataController = new DataController(); DataController dataController = new DataController();
dataController.CreateEvent(event); dataController.createEvent(event);
Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
stage.close(); stage.close();

View File

@ -122,9 +122,9 @@ public class MainController {
Button deleteBtn = new Button(); Button deleteBtn = new Button();
deleteBtn.setText(" X "); deleteBtn.setText(" X ");
deleteBtn.setOnAction(e -> { deleteBtn.setOnAction(e -> {
LocalDateTime eventDate = event.getDate(); DataController dataController = new DataController();
int day = (int)Duration.between(weekStartDateTime.toLocalDate().atStartOfDay(), eventDate.toLocalDate().atStartOfDay()).toDays(); dataController.deleteEvent(event.getId());
dayVBoxes[day].getChildren().remove(vBox); updateEvents();
}); });
Button editBtn = new Button(); Button editBtn = new Button();
editBtn.setText("edit"); editBtn.setText("edit");

View File

@ -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_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 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 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(){ public DataController(){
httpRequest = new HttpRequest(); httpRequest = new HttpRequest();
} }
public void CreateEvent(Event event){ public void createEvent(Event event){
try { try {
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam())); System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
} catch (Exception e) { } 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<Event> getAllVisibleEvents() { public ArrayList<Event> getAllVisibleEvents() {
ArrayList<Event> eventList = new ArrayList<>(); ArrayList<Event> eventList = new ArrayList<>();