Fixed event/all and event/del endpoints

This commit is contained in:
Marc Beyer 2022-01-19 00:16:23 +01:00
parent 7a119a8aed
commit 78505097db
5 changed files with 70 additions and 27 deletions

View File

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

View File

@ -56,7 +56,7 @@ public class MainController {
}
DataController dataController = new DataController();
ArrayList<Event> eventList = dataController.getAllVisibleEvents();
ArrayList<Event> 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();

View File

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

View File

@ -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<Event> getAllVisibleEvents() {
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) {
ArrayList<Event> eventList = new ArrayList<>();
try {
Tuple<Integer, String> response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true);
Tuple<Integer, String> 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<Event>) objectMapper.readValue(jsonResponse, new TypeReference<List<Event>>(){});
for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) {
ArrayList<Object> list = new ArrayList<>();
if (obj.getClass().isArray()) {
list = (ArrayList<Object>) Arrays.asList((Object[]) obj);
} else if (obj instanceof Collection) {
list = new ArrayList<>((Collection<?>) obj);
}
eventList.add(new Event(list));
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -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<Object> 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() {