Fixed event/all and event/del endpoints
This commit is contained in:
parent
7a119a8aed
commit
78505097db
@ -13,26 +13,32 @@ public class MainApplication extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml"));
|
System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170");
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
// Load login-scene
|
||||||
FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml"));
|
FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml"));
|
||||||
Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500);
|
Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500);
|
||||||
sceneLogin.getStylesheets().add(Objects.requireNonNull(
|
sceneLogin.getStylesheets().add(Objects.requireNonNull(
|
||||||
MainApplication.class.getResource("../users/login.css")).toExternalForm());
|
MainApplication.class.getResource("../users/login.css")).toExternalForm()
|
||||||
|
);
|
||||||
Stage stageLogin = new Stage();
|
Stage stageLogin = new Stage();
|
||||||
stageLogin.setTitle("Anmelden");
|
stageLogin.setTitle("Anmelden");
|
||||||
stageLogin.setScene(sceneLogin);
|
stageLogin.setScene(sceneLogin);
|
||||||
stageLogin.showAndWait();
|
stageLogin.showAndWait();
|
||||||
|
|
||||||
if (DataController.USER_ID >= 0) {
|
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();
|
stage.show();
|
||||||
|
|
||||||
|
System.out.println("Logged in...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class MainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataController dataController = new DataController();
|
DataController dataController = new DataController();
|
||||||
ArrayList<Event> eventList = dataController.getAllVisibleEvents();
|
ArrayList<Event> eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7));
|
||||||
|
|
||||||
for (Event event : eventList) {
|
for (Event event : eventList) {
|
||||||
addEvent(event);
|
addEvent(event);
|
||||||
@ -143,7 +143,7 @@ public class MainController {
|
|||||||
deleteBtn.setTextValue(" X ");
|
deleteBtn.setTextValue(" X ");
|
||||||
deleteBtn.setOnAction(e -> {
|
deleteBtn.setOnAction(e -> {
|
||||||
DataController dataController = new DataController();
|
DataController dataController = new DataController();
|
||||||
dataController.deleteEvent(event.getId());
|
dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate());
|
||||||
updateEvents();
|
updateEvents();
|
||||||
});
|
});
|
||||||
Button editBtn = new Button();
|
Button editBtn = new Button();
|
||||||
|
@ -7,4 +7,5 @@ dependencies {
|
|||||||
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
||||||
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
||||||
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
|
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
|
||||||
|
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package res;
|
package res;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import helper.Tuple;
|
import helper.Tuple;
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ import java.io.OutputStream;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class DataController {
|
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 {
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Event> getAllVisibleEvents() {
|
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) {
|
||||||
ArrayList<Event> eventList = new ArrayList<>();
|
ArrayList<Event> eventList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
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();
|
String jsonResponse = response.getValue();
|
||||||
System.out.println(jsonResponse);
|
System.out.println(jsonResponse);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package res;
|
|||||||
|
|
||||||
import com.sun.jdi.event.StepEvent;
|
import com.sun.jdi.event.StepEvent;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@ -43,6 +44,10 @@ public class Event {
|
|||||||
u.name AS uname
|
u.name AS uname
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public Event() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Event(ArrayList<Object> arr) {
|
public Event(ArrayList<Object> arr) {
|
||||||
id = (int) arr.get(0);
|
id = (int) arr.get(0);
|
||||||
name = (String) arr.get(1);
|
name = (String) arr.get(1);
|
||||||
@ -59,6 +64,33 @@ public class Event {
|
|||||||
ownerName = arr.get(8) + " " + arr.get(9);
|
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,
|
public Event(String name,
|
||||||
int priority,
|
int priority,
|
||||||
boolean isFullDay,
|
boolean isFullDay,
|
||||||
@ -174,8 +206,9 @@ public class Event {
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(LocalDateTime date) {
|
public void setDate(String date) {
|
||||||
this.date = date;
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||||
|
this.date = LocalDateTime.parse(date + " 00:00", formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOwnerId() {
|
public int getOwnerId() {
|
||||||
|
Loading…
Reference in New Issue
Block a user