Send a POST request to create an event in DB
This commit is contained in:
parent
0043e7f1bd
commit
e8c7fb8a08
@ -3,10 +3,37 @@ package client;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.DatePicker;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import res.DataController;
|
||||
import res.Event;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CreateEventController {
|
||||
|
||||
@FXML
|
||||
public DatePicker datePickerDate;
|
||||
@FXML
|
||||
public TextField textName;
|
||||
@FXML
|
||||
public TextField textStart;
|
||||
@FXML
|
||||
public TextField textEnd;
|
||||
@FXML
|
||||
public ComboBox<String> ComboBoxTyp;
|
||||
@FXML
|
||||
public ComboBox<String> ComboBoxPriotity;
|
||||
@FXML
|
||||
public CheckBox checkBoxIsFullDay;
|
||||
@FXML
|
||||
public CheckBox checkBoxIsPrivate;
|
||||
|
||||
|
||||
public CreateEventController(){}
|
||||
|
||||
@FXML
|
||||
@ -14,8 +41,25 @@ public class CreateEventController {
|
||||
|
||||
|
||||
@FXML
|
||||
protected void createBtnClick(ActionEvent event){
|
||||
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||
protected void createBtnClick(ActionEvent actionEvent){
|
||||
|
||||
Event event = new Event(
|
||||
textName.getText(),
|
||||
ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
|
||||
checkBoxIsFullDay.isSelected(),
|
||||
checkBoxIsPrivate.isSelected(),
|
||||
textStart.getText(),
|
||||
textEnd.getText(),
|
||||
datePickerDate.getValue().atStartOfDay(),
|
||||
1
|
||||
);
|
||||
|
||||
System.out.println(event.getAsUrlParam());
|
||||
|
||||
DataController dataController = new DataController();
|
||||
dataController.CreateEvent(event);
|
||||
|
||||
Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,14 @@ public class MainController {
|
||||
createWeek();
|
||||
setDates();
|
||||
|
||||
updateEvents();
|
||||
}
|
||||
|
||||
private void updateEvents() {
|
||||
for(VBox vBox : dayVBoxes){
|
||||
vBox.getChildren().clear();
|
||||
}
|
||||
|
||||
DataController dataController = new DataController();
|
||||
ArrayList<Event> eventList = dataController.getAllVisibleEvents();
|
||||
|
||||
@ -74,6 +82,7 @@ public class MainController {
|
||||
catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
updateEvents();
|
||||
}
|
||||
|
||||
private void createWeek(){
|
||||
|
@ -3,6 +3,8 @@
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.collections.FXCollections?>
|
||||
<?import java.lang.String?>
|
||||
<GridPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.CreateEventController">
|
||||
|
||||
<columnConstraints>
|
||||
@ -19,25 +21,38 @@
|
||||
<RowConstraints vgrow="ALWAYS" />
|
||||
<RowConstraints vgrow="ALWAYS" />
|
||||
<RowConstraints vgrow="ALWAYS" />
|
||||
<RowConstraints vgrow="ALWAYS" />
|
||||
</rowConstraints>
|
||||
|
||||
<Label styleClass="mainLabel">Termin anlegen</Label>
|
||||
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="1">Datum:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="2">Titel:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="3">Zeit:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="4">Typ:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="5">Priorität:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="6">Ganztägig:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="3">Von:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="4">Bis:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="5">Typ:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="6">Priorität:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="7">Ganztägig:</Label>
|
||||
<Label styleClass="inputLabel" GridPane.rowIndex="8">Privat:</Label>
|
||||
|
||||
<DatePicker GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||
<DatePicker GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="400" minWidth="400"/>
|
||||
<ComboBox GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="400" minWidth="400"/>
|
||||
<ComboBox GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200"/>
|
||||
<CheckBox GridPane.columnIndex="1" GridPane.rowIndex="6"/>
|
||||
<DatePicker fx:id="datePickerDate" GridPane.columnIndex="1" GridPane.rowIndex="1" maxWidth="400" minWidth="400"/>
|
||||
<TextField fx:id="textName" GridPane.columnIndex="1" GridPane.rowIndex="2" maxWidth="400" minWidth="400"/>
|
||||
<TextField fx:id="textStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="400" minWidth="400"/>
|
||||
<TextField fx:id="textEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="400" minWidth="400"/>
|
||||
<ComboBox fx:id="ComboBoxTyp" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="400" minWidth="400"/>
|
||||
<ComboBox fx:id="ComboBoxPriotity" GridPane.columnIndex="1" GridPane.rowIndex="6" maxWidth="200" minWidth="200">
|
||||
<items>
|
||||
<FXCollections fx:factory="observableArrayList">
|
||||
<String fx:value="gering" />
|
||||
<String fx:value="mittel" />
|
||||
<String fx:value="hoch" />
|
||||
</FXCollections>
|
||||
</items>
|
||||
</ComboBox>
|
||||
<CheckBox fx:id="checkBoxIsFullDay" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
||||
<CheckBox fx:id="checkBoxIsPrivate" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
|
||||
|
||||
<HBox GridPane.columnIndex="1" GridPane.rowIndex="7" GridPane.columnSpan="2" alignment="CENTER_RIGHT">
|
||||
<HBox GridPane.columnIndex="1" GridPane.rowIndex="9" GridPane.columnSpan="2" alignment="CENTER_RIGHT">
|
||||
<Button onAction="#abortBtnClick" maxWidth="150" minWidth="150" >Abbrechen</Button>
|
||||
<Button styleClass="mainButton" onAction="#createBtnClick" maxWidth="150" minWidth="150">Anlegen</Button>
|
||||
</HBox>
|
||||
|
@ -16,6 +16,7 @@ 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 HttpRequest httpRequest;
|
||||
|
||||
@ -23,6 +24,13 @@ public class DataController {
|
||||
httpRequest = new HttpRequest();
|
||||
}
|
||||
|
||||
public void CreateEvent(Event event){
|
||||
try {
|
||||
System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Event> getAllVisibleEvents() {
|
||||
ArrayList<Event> eventList = new ArrayList<>();
|
||||
|
@ -12,6 +12,7 @@ public class Event {
|
||||
private String name;
|
||||
private int priority;
|
||||
private boolean isFullDay;
|
||||
private boolean isPrivate;
|
||||
private String start;
|
||||
private String end;
|
||||
|
||||
@ -37,21 +38,39 @@ public class Event {
|
||||
*/
|
||||
|
||||
public Event(ArrayList<Object> arr) {
|
||||
id = (int)arr.get(0);
|
||||
name = (String)arr.get(1);
|
||||
start = (String)arr.get(2);
|
||||
end = (String)arr.get(3);
|
||||
priority = (int)arr.get(4);
|
||||
isFullDay = (Boolean)arr.get(5); //((String)arr.get(5)).equals("true");
|
||||
id = (int) arr.get(0);
|
||||
name = (String) arr.get(1);
|
||||
start = (String) arr.get(2);
|
||||
end = (String) arr.get(3);
|
||||
priority = (int) arr.get(4);
|
||||
isFullDay = (Boolean) arr.get(5); //((String)arr.get(5)).equals("true");
|
||||
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
date = LocalDateTime.parse(arr.get(6) + " 00:00", formatter);
|
||||
|
||||
ownerId = (int)arr.get(7);
|
||||
ownerId = (int) arr.get(7);
|
||||
ownerName = arr.get(8) + " " + arr.get(9);
|
||||
}
|
||||
|
||||
public Event(String name,
|
||||
int priority,
|
||||
boolean isFullDay,
|
||||
boolean isPrivate,
|
||||
String start,
|
||||
String end,
|
||||
LocalDateTime date,
|
||||
int ownerId
|
||||
) {
|
||||
this.name = name;
|
||||
this.priority = priority;
|
||||
this.isFullDay = isFullDay;
|
||||
this.isPrivate = isPrivate;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.date = date;
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -85,6 +104,14 @@ public class Event {
|
||||
isFullDay = fullDay;
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
return isPrivate;
|
||||
}
|
||||
|
||||
public void setPrivate(boolean aPrivate) {
|
||||
isPrivate = aPrivate;
|
||||
}
|
||||
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
@ -133,4 +160,15 @@ public class Event {
|
||||
(isFullDay ? "\nDen ganzen Tag lang" : "");
|
||||
|
||||
}
|
||||
|
||||
public String getAsUrlParam() {
|
||||
return "userId=" + getOwnerId() +
|
||||
"&date=" + getDate().toLocalDate() +
|
||||
"&name=" + getName() +
|
||||
"&start=" + getStart() +
|
||||
"&end=" + getEnd() +
|
||||
"&prority=" + getPriority() +
|
||||
"&isFullDay=" + isFullDay() +
|
||||
"&isPrivate=" + isPrivate();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user