From 78505097dbcedb6b74d0ce90c43e3f94b9030979 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Wed, 19 Jan 2022 00:16:23 +0100 Subject: [PATCH] Fixed event/all and event/del endpoints --- .../src/main/java/main/MainApplication.java | 24 +++++++----- .../src/main/java/main/MainController.java | 4 +- client/data/build.gradle.kts | 1 + .../src/main/java/res/DataController.java | 31 +++++++++------- client/data/src/main/java/res/Event.java | 37 ++++++++++++++++++- 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index e0cbbdd..6108243 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -13,26 +13,32 @@ public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); - - Scene scene = new Scene(fxmlLoader.load(), 1200, 700); - scene.getStylesheets().add(Objects.requireNonNull( - - MainApplication.class.getResource("main-view.css")).toExternalForm()); - stage.setTitle("SharePlaner"); - stage.setScene(scene); + System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); + // Load login-scene FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml")); Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500); sceneLogin.getStylesheets().add(Objects.requireNonNull( - MainApplication.class.getResource("../users/login.css")).toExternalForm()); + MainApplication.class.getResource("../users/login.css")).toExternalForm() + ); Stage stageLogin = new Stage(); stageLogin.setTitle("Anmelden"); stageLogin.setScene(sceneLogin); stageLogin.showAndWait(); if (DataController.USER_ID >= 0) { + // Load main-scene + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); + + Scene scene = new Scene(fxmlLoader.load(), 1200, 700); + scene.getStylesheets().add(Objects.requireNonNull( + MainApplication.class.getResource("main-view.css")).toExternalForm() + ); + stage.setTitle("SharePlaner"); + stage.setScene(scene); stage.show(); + + System.out.println("Logged in..."); } } diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 983b955..dbdcce6 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -56,7 +56,7 @@ public class MainController { } DataController dataController = new DataController(); - ArrayList eventList = dataController.getAllVisibleEvents(); + ArrayList eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7)); for (Event event : eventList) { addEvent(event); @@ -143,7 +143,7 @@ public class MainController { deleteBtn.setTextValue(" X "); deleteBtn.setOnAction(e -> { DataController dataController = new DataController(); - dataController.deleteEvent(event.getId()); + dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate()); updateEvents(); }); Button editBtn = new Button(); diff --git a/client/data/build.gradle.kts b/client/data/build.gradle.kts index 5b07f24..147ec02 100644 --- a/client/data/build.gradle.kts +++ b/client/data/build.gradle.kts @@ -7,4 +7,5 @@ dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") } diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 8d3444b..2937b9b 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -1,6 +1,7 @@ package res; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import helper.Tuple; @@ -11,6 +12,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; import java.util.*; public class DataController { @@ -66,34 +68,35 @@ public class DataController { } } - public void deleteEvent(int eventId) { + public void deleteEvent(int userId, int eventId, LocalDateTime date) { try { - System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId, true)); + System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate()); + System.out.println(httpRequest.sendPostRequest( + DELETE_EVENT_ENDPOINT, + "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(), + true + )); } catch (Exception e) { e.printStackTrace(); } } - public ArrayList getAllVisibleEvents() { + public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) { ArrayList eventList = new ArrayList<>(); - try { - Tuple response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true); + Tuple response = httpRequest.sendPostRequest( + ALL_EVENTS_ENDPOINT, + "userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(), + true + ); String jsonResponse = response.getValue(); System.out.println(jsonResponse); ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>(){}); - for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) { - ArrayList list = new ArrayList<>(); - if (obj.getClass().isArray()) { - list = (ArrayList) Arrays.asList((Object[]) obj); - } else if (obj instanceof Collection) { - list = new ArrayList<>((Collection) obj); - } - eventList.add(new Event(list)); - } } catch (Exception e) { e.printStackTrace(); } diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 90e9d41..5a51d2a 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -2,6 +2,7 @@ package res; import com.sun.jdi.event.StepEvent; +import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDate; @@ -43,6 +44,10 @@ public class Event { u.name AS uname */ + public Event() { + + } + public Event(ArrayList arr) { id = (int) arr.get(0); name = (String) arr.get(1); @@ -59,6 +64,33 @@ public class Event { 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(String name, int priority, boolean isFullDay, @@ -174,8 +206,9 @@ public class Event { return date; } - public void setDate(LocalDateTime date) { - this.date = date; + public void setDate(String date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + this.date = LocalDateTime.parse(date + " 00:00", formatter); } public int getOwnerId() {