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.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();

View File

@ -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");

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_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<Event> getAllVisibleEvents() {
ArrayList<Event> eventList = new ArrayList<>();