Refactor
This commit is contained in:
parent
30e0afb86c
commit
dc78d69a00
@ -20,23 +20,23 @@ import java.util.Locale;
|
|||||||
public class CreateEventController {
|
public class CreateEventController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public GridPane mainGrid;
|
private GridPane mainGrid;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXDatePicker datePickerDate;
|
protected JFXDatePicker datePickerDate;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXTextField textName;
|
protected JFXTextField textName;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXComboBox<String> ComboBoxPriotity;
|
protected JFXComboBox<String> comboBoxPriority;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXToggleButton toggleBtnIsFullDay;
|
private JFXToggleButton toggleBtnIsFullDay;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXToggleButton toggleBtnIsPrivate;
|
private JFXToggleButton toggleBtnIsPrivate;
|
||||||
@FXML
|
@FXML
|
||||||
public Label labelError;
|
private Label labelError;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXTimePicker timeStart;
|
private JFXTimePicker timeStart;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXTimePicker timeEnd;
|
private JFXTimePicker timeEnd;
|
||||||
|
|
||||||
|
|
||||||
public CreateEventController() {
|
public CreateEventController() {
|
||||||
@ -64,7 +64,7 @@ public class CreateEventController {
|
|||||||
|
|
||||||
Event event = new Event(
|
Event event = new Event(
|
||||||
textName.getText(),
|
textName.getText(),
|
||||||
ComboBoxPriotity.getSelectionModel().getSelectedIndex(),
|
comboBoxPriority.getSelectionModel().getSelectedIndex(),
|
||||||
toggleBtnIsFullDay.isSelected(),
|
toggleBtnIsFullDay.isSelected(),
|
||||||
toggleBtnIsPrivate.isSelected(),
|
toggleBtnIsPrivate.isSelected(),
|
||||||
timeStart.getValue(),
|
timeStart.getValue(),
|
||||||
|
@ -17,7 +17,7 @@ public class EditEventController extends CreateEventController{
|
|||||||
|
|
||||||
textName.setText(currentEvent.getName());
|
textName.setText(currentEvent.getName());
|
||||||
datePickerDate.setValue(currentEvent.getDate().toLocalDate());
|
datePickerDate.setValue(currentEvent.getDate().toLocalDate());
|
||||||
ComboBoxPriotity.getSelectionModel().select(currentEvent.getPriority());
|
comboBoxPriority.getSelectionModel().select(currentEvent.getPriority());
|
||||||
|
|
||||||
//timeEnd.setValue(currentEvent.getEnd());
|
//timeEnd.setValue(currentEvent.getEnd());
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,13 @@ package main;
|
|||||||
|
|
||||||
import config.Config;
|
import config.Config;
|
||||||
import config.ConfigLoader;
|
import config.ConfigLoader;
|
||||||
import helper.Tuple;
|
import container.DataController;
|
||||||
|
import container.HttpRequest;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import container.DataController;
|
|
||||||
import container.HttpRequest;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -41,6 +38,9 @@ public class MainApplication extends Application {
|
|||||||
config.setToken(HttpRequest.TOKEN);
|
config.setToken(HttpRequest.TOKEN);
|
||||||
ConfigLoader.save(config);
|
ConfigLoader.save(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataController.SERVER_URL = config.toServerUrl();
|
||||||
|
|
||||||
// Load main-scene
|
// Load main-scene
|
||||||
loadMainScene(stage);
|
loadMainScene(stage);
|
||||||
|
|
||||||
@ -60,22 +60,30 @@ public class MainApplication extends Application {
|
|||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadLoginScene() throws IOException {
|
private void loadLoginScene() {
|
||||||
FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml"));
|
loadScene(
|
||||||
Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500);
|
"Anmelden",
|
||||||
sceneLogin.getStylesheets().add(Objects.requireNonNull(
|
"../users/login.fxml",
|
||||||
MainApplication.class.getResource("../users/login.css")).toExternalForm()
|
"../users/login.css",
|
||||||
|
650,
|
||||||
|
500
|
||||||
);
|
);
|
||||||
Stage stageLogin = new Stage();
|
|
||||||
stageLogin.setTitle("Anmelden");
|
|
||||||
stageLogin.setScene(sceneLogin);
|
|
||||||
stageLogin.showAndWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch();
|
launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadScene(
|
||||||
|
String title,
|
||||||
|
String fxml,
|
||||||
|
String css,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
) {
|
||||||
|
loadScene(title, fxml, css, width, height, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadScene(
|
public static void loadScene(
|
||||||
String title,
|
String title,
|
||||||
String fxml,
|
String fxml,
|
||||||
|
@ -2,45 +2,40 @@ package main;
|
|||||||
|
|
||||||
import config.Config;
|
import config.Config;
|
||||||
import config.ConfigLoader;
|
import config.ConfigLoader;
|
||||||
|
import container.DataController;
|
||||||
|
import container.Event;
|
||||||
|
import container.HttpRequest;
|
||||||
import events.EditEventController;
|
import events.EditEventController;
|
||||||
import ui.DayPane;
|
|
||||||
import ui.EventPane;
|
|
||||||
import ui.SvgBtnCreator;
|
|
||||||
import helper.HttpRequestException;
|
import helper.HttpRequestException;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Modality;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import container.DataController;
|
import ui.DayPane;
|
||||||
import container.Event;
|
import ui.EventPane;
|
||||||
|
import ui.SvgBtnCreator;
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import container.HttpRequest;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MainController {
|
public class MainController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public VBox leftNav;
|
private VBox leftNav;
|
||||||
@FXML
|
@FXML
|
||||||
public GridPane mainGridPane;
|
private GridPane mainGridPane;
|
||||||
@FXML
|
@FXML
|
||||||
public HBox buttonBox;
|
private HBox buttonBox;
|
||||||
@FXML
|
@FXML
|
||||||
private GridPane calendarGrid;
|
private GridPane calendarGrid;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private javafx.scene.control.Label LabelMonth;
|
private javafx.scene.control.Label LabelMonth;
|
||||||
|
|
||||||
@ -110,8 +105,7 @@ public class MainController {
|
|||||||
"create-event.fxml",
|
"create-event.fxml",
|
||||||
"create-event.css",
|
"create-event.css",
|
||||||
650,
|
650,
|
||||||
650,
|
650
|
||||||
null
|
|
||||||
);
|
);
|
||||||
updateEvents();
|
updateEvents();
|
||||||
}
|
}
|
||||||
@ -122,8 +116,7 @@ public class MainController {
|
|||||||
"option-view.fxml",
|
"option-view.fxml",
|
||||||
"option-view.css",
|
"option-view.css",
|
||||||
650,
|
650,
|
||||||
600,
|
600
|
||||||
null
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,17 +27,17 @@ import java.util.Optional;
|
|||||||
public class OptionController {
|
public class OptionController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public JFXButton updateUserBtn;
|
private JFXButton updateUserBtn;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXButton deleteUserBtn;
|
private JFXButton deleteUserBtn;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXButton createUserBtn;
|
private JFXButton createUserBtn;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXToggleButton saveLoginTBtn;
|
private JFXToggleButton saveLoginTBtn;
|
||||||
@FXML
|
@FXML
|
||||||
public Label labelError;
|
private Label labelError;
|
||||||
@FXML
|
@FXML
|
||||||
public GridPane mainGrid;
|
private GridPane mainGrid;
|
||||||
|
|
||||||
private JFXComboBox<String> comboBox;
|
private JFXComboBox<String> comboBox;
|
||||||
private DataController dataController;
|
private DataController dataController;
|
||||||
@ -79,8 +79,7 @@ public class OptionController {
|
|||||||
"../users/create-user.fxml",
|
"../users/create-user.fxml",
|
||||||
"../users/create-user.css",
|
"../users/create-user.css",
|
||||||
800,
|
800,
|
||||||
650,
|
650
|
||||||
null
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,12 @@
|
|||||||
package ui;
|
package ui;
|
||||||
|
|
||||||
import container.DataController;
|
|
||||||
import container.Event;
|
import container.Event;
|
||||||
import events.EditEventController;
|
|
||||||
import helper.HttpRequestException;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Modality;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import main.MainApplication;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class EventPane extends VBox {
|
public class EventPane extends VBox {
|
||||||
|
|
||||||
|
@ -16,40 +16,24 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class CreateUserController {
|
public class CreateUserController {
|
||||||
|
|
||||||
public TextField textName;
|
@FXML
|
||||||
public PasswordField textPassword;
|
protected TextField textName;
|
||||||
public PasswordField textPasswordSecond;
|
@FXML
|
||||||
public ToggleButton checkButtonIsAdmin;
|
protected PasswordField textPassword;
|
||||||
public TextField textLogin;
|
@FXML
|
||||||
public TextField textForename;
|
protected PasswordField textPasswordSecond;
|
||||||
public Label labelError;
|
@FXML
|
||||||
|
protected ToggleButton checkButtonIsAdmin;
|
||||||
|
@FXML
|
||||||
|
protected TextField textLogin;
|
||||||
|
@FXML
|
||||||
|
protected TextField textForename;
|
||||||
|
@FXML
|
||||||
|
protected Label labelError;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void createUser(ActionEvent event) {
|
protected void createUser(ActionEvent event) {
|
||||||
if (textLogin.getText().trim().isEmpty()){
|
if (validateNameAndLogin() || validatePassword()) return;
|
||||||
labelError.setText("Bitte Login Namen angeben");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textForename.getText().trim().isEmpty()) {
|
|
||||||
labelError.setText("Bitte Vornamen eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textName.getText().trim().isEmpty()) {
|
|
||||||
labelError.setText("Bitte Nachnamen eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textPassword.getText().trim().isEmpty()) {
|
|
||||||
labelError.setText("Bitte Passwort eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textPassword.getText().trim().length() < 8) {
|
|
||||||
labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){
|
|
||||||
labelError.setText("Passwörter stimmen nicht überein!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setLogin(textLogin.getText().trim());
|
user.setLogin(textLogin.getText().trim());
|
||||||
@ -69,6 +53,38 @@ public class CreateUserController {
|
|||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean validatePassword() {
|
||||||
|
if (textPassword.getText().trim().isEmpty()) {
|
||||||
|
labelError.setText("Bitte Passwort eingeben!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (textPassword.getText().trim().length() < 8) {
|
||||||
|
labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){
|
||||||
|
labelError.setText("Passwörter stimmen nicht überein!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean validateNameAndLogin() {
|
||||||
|
if (textLogin.getText().trim().isEmpty()){
|
||||||
|
labelError.setText("Bitte Login Namen angeben");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (textForename.getText().trim().isEmpty()) {
|
||||||
|
labelError.setText("Bitte Vornamen eingeben!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (textName.getText().trim().isEmpty()) {
|
||||||
|
labelError.setText("Bitte Nachnamen eingeben!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendHttpRequest(User user) throws HttpRequestException {
|
protected void sendHttpRequest(User user) throws HttpRequestException {
|
||||||
DataController dataController = new DataController();
|
DataController dataController = new DataController();
|
||||||
dataController.createUser(user);
|
dataController.createUser(user);
|
||||||
|
@ -8,8 +8,6 @@ import javafx.scene.Node;
|
|||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class EditUserController extends CreateUserController{
|
public class EditUserController extends CreateUserController{
|
||||||
private User currentUser;
|
private User currentUser;
|
||||||
|
|
||||||
@ -28,34 +26,12 @@ public class EditUserController extends CreateUserController{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createUser(ActionEvent event){
|
protected void createUser(ActionEvent event){
|
||||||
if (textLogin.getText().trim().isEmpty()){
|
if (validateNameAndLogin()) return;
|
||||||
labelError.setText("Bitte Login Namen angeben");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textForename.getText().trim().isEmpty()) {
|
|
||||||
labelError.setText("Bitte Vornamen eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textName.getText().trim().isEmpty()) {
|
|
||||||
labelError.setText("Bitte Nachnamen eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
|
||||||
if(!textPassword.getText().trim().isEmpty() || !textPasswordSecond.getText().trim().isEmpty()){
|
if(!textPassword.getText().trim().isEmpty() || !textPasswordSecond.getText().trim().isEmpty()){
|
||||||
if (textPassword.getText().trim().isEmpty()) {
|
if (validatePassword()) return;
|
||||||
labelError.setText("Bitte Passwort eingeben!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (textPassword.getText().trim().length() < 8) {
|
|
||||||
labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){
|
|
||||||
labelError.setText("Passwörter stimmen nicht überein!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
user.setPassword(textPassword.getText().trim());
|
user.setPassword(textPassword.getText().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ import container.DataController;
|
|||||||
|
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
@FXML
|
@FXML
|
||||||
public JFXTextField userField;
|
private JFXTextField userField;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXPasswordField passField;
|
private JFXPasswordField passField;
|
||||||
@FXML
|
@FXML
|
||||||
public Label userErrLabel;
|
private Label userErrLabel;
|
||||||
@FXML
|
@FXML
|
||||||
public Label passErrLabel;
|
private Label passErrLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void login(ActionEvent event) {
|
protected void login(ActionEvent event) {
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<JFXTimePicker styleClass="timePicker" fx:id="timeStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="200" minWidth="200"/>
|
<JFXTimePicker styleClass="timePicker" fx:id="timeStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="200" minWidth="200"/>
|
||||||
<JFXTimePicker styleClass="timePicker" fx:id="timeEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="200" minWidth="200"/>
|
<JFXTimePicker styleClass="timePicker" fx:id="timeEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="200" minWidth="200"/>
|
||||||
|
|
||||||
<JFXComboBox fx:id="ComboBoxPriotity" styleClass="comboBox" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
<JFXComboBox fx:id="comboBoxPriority" styleClass="comboBox" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
||||||
<items>
|
<items>
|
||||||
<FXCollections fx:factory="observableArrayList">
|
<FXCollections fx:factory="observableArrayList">
|
||||||
<String fx:value="gering"/>
|
<String fx:value="gering"/>
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<JFXTimePicker styleClass="timePicker" fx:id="timeStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="200" minWidth="200"/>
|
<JFXTimePicker styleClass="timePicker" fx:id="timeStart" GridPane.columnIndex="1" GridPane.rowIndex="3" maxWidth="200" minWidth="200"/>
|
||||||
<JFXTimePicker styleClass="timePicker" fx:id="timeEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="200" minWidth="200"/>
|
<JFXTimePicker styleClass="timePicker" fx:id="timeEnd" GridPane.columnIndex="1" GridPane.rowIndex="4" maxWidth="200" minWidth="200"/>
|
||||||
|
|
||||||
<JFXComboBox fx:id="ComboBoxPriotity" styleClass="comboBox" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
<JFXComboBox fx:id="comboBoxPriority" styleClass="comboBox" GridPane.columnIndex="1" GridPane.rowIndex="5" maxWidth="200" minWidth="200">
|
||||||
<items>
|
<items>
|
||||||
<FXCollections fx:factory="observableArrayList">
|
<FXCollections fx:factory="observableArrayList">
|
||||||
<String fx:value="gering"/>
|
<String fx:value="gering"/>
|
||||||
|
@ -4,15 +4,26 @@ public class Config {
|
|||||||
private boolean saveLogin;
|
private boolean saveLogin;
|
||||||
private long id;
|
private long id;
|
||||||
private String token;
|
private String token;
|
||||||
|
private String connectionMethod;
|
||||||
|
private String hostAddress;
|
||||||
|
private int port;
|
||||||
|
|
||||||
public Config(){
|
public Config(){
|
||||||
|
saveLogin = false;
|
||||||
|
id = -1;
|
||||||
|
token = "";
|
||||||
|
connectionMethod = "http";
|
||||||
|
hostAddress = "localhost";
|
||||||
|
port = 8080;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config(boolean saveLogin, long id, String token) {
|
public Config(boolean saveLogin, long id, String token) {
|
||||||
this.saveLogin = saveLogin;
|
this.saveLogin = saveLogin;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
connectionMethod = "http";
|
||||||
|
hostAddress = "localhost";
|
||||||
|
port = 8080;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaveLogin() {
|
public boolean isSaveLogin() {
|
||||||
@ -38,4 +49,32 @@ public class Config {
|
|||||||
public void setToken(String token) {
|
public void setToken(String token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getConnectionMethod() {
|
||||||
|
return connectionMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionMethod(String connectionMethod) {
|
||||||
|
this.connectionMethod = connectionMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostAddress() {
|
||||||
|
return hostAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostAddress(String hostAddress) {
|
||||||
|
this.hostAddress = hostAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toServerUrl(){
|
||||||
|
return getConnectionMethod() + "://" + getHostAddress() + ":" + getPort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,12 @@ public class ConfigLoader {
|
|||||||
objectMapper.findAndRegisterModules();
|
objectMapper.findAndRegisterModules();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.writeString(Paths.get(
|
Files.writeString(
|
||||||
"config.json"),
|
Paths.get("config.json"),
|
||||||
objectMapper.writeValueAsString(config)
|
objectMapper.writeValueAsString(config)
|
||||||
|
.replace(",", ",\n\t")
|
||||||
|
.replace("{", "{\n\t")
|
||||||
|
.replace("}", "\n}")
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -12,20 +12,21 @@ import java.util.*;
|
|||||||
public class DataController {
|
public class DataController {
|
||||||
|
|
||||||
public static long USER_ID = -1;
|
public static long USER_ID = -1;
|
||||||
|
public static String SERVER_URL = "http://localhost:8080";
|
||||||
|
|
||||||
private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all";
|
private static final String ALL_EVENTS_ENDPOINT = "/event/all";
|
||||||
private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add";
|
private static final String ADD_EVENT_ENDPOINT = "/event/add";
|
||||||
private static final String DELETE_EVENT_ENDPOINT = "http://localhost:8080/event/del";
|
private static final String DELETE_EVENT_ENDPOINT = "/event/del";
|
||||||
private static final String EDIT_EVENT_ENDPOINT = "http://localhost:8080/event/edit";
|
private static final String EDIT_EVENT_ENDPOINT = "/event/edit";
|
||||||
|
|
||||||
private static final String ALL_USER_ENDPOINT = "http://localhost:8080/user/all";
|
private static final String ALL_USER_ENDPOINT = "/user/all";
|
||||||
private static final String ADD_USER_ENDPOINT = "http://localhost:8080/user/add";
|
private static final String ADD_USER_ENDPOINT = "/user/add";
|
||||||
private static final String DELETE_USER_ENDPOINT = "http://localhost:8080/user/del";
|
private static final String DELETE_USER_ENDPOINT = "/user/del";
|
||||||
private static final String EDIT_USER_ENDPOINT = "http://localhost:8080/user/edit";
|
private static final String EDIT_USER_ENDPOINT = "/user/edit";
|
||||||
|
|
||||||
private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login";
|
private static final String LOGIN_ENDPOINT = "/user/login";
|
||||||
private static final String LOGIN_WITH_TOKEN_ENDPOINT = "http://localhost:8080/user/login-with-token";
|
private static final String LOGIN_WITH_TOKEN_ENDPOINT = "/user/login-with-token";
|
||||||
private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test";
|
private static final String HEADER_TEST_ENDPOINT = "/vpr/header-test";
|
||||||
|
|
||||||
private final HttpRequest httpRequest;
|
private final HttpRequest httpRequest;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ public class DataController {
|
|||||||
public boolean login(String username, String password) {
|
public boolean login(String username, String password) {
|
||||||
try {
|
try {
|
||||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||||
LOGIN_ENDPOINT,
|
SERVER_URL + LOGIN_ENDPOINT,
|
||||||
"login=" + username
|
"login=" + username
|
||||||
+ "&password=" + password,
|
+ "&password=" + password,
|
||||||
false
|
false
|
||||||
@ -57,7 +58,7 @@ public class DataController {
|
|||||||
try {
|
try {
|
||||||
HttpRequest.TOKEN = token;
|
HttpRequest.TOKEN = token;
|
||||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||||
LOGIN_WITH_TOKEN_ENDPOINT,
|
SERVER_URL + LOGIN_WITH_TOKEN_ENDPOINT,
|
||||||
"userId=" + userId,
|
"userId=" + userId,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -79,7 +80,7 @@ public class DataController {
|
|||||||
*********/
|
*********/
|
||||||
public void createEvent(Event event) throws HttpRequestException {
|
public void createEvent(Event event) throws HttpRequestException {
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
ADD_EVENT_ENDPOINT,
|
SERVER_URL + ADD_EVENT_ENDPOINT,
|
||||||
event.getAsUrlParam(),
|
event.getAsUrlParam(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -87,7 +88,7 @@ public class DataController {
|
|||||||
|
|
||||||
public void deleteEvent(int userId, int eventId, LocalDateTime date) throws HttpRequestException {
|
public void deleteEvent(int userId, int eventId, LocalDateTime date) throws HttpRequestException {
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
DELETE_EVENT_ENDPOINT,
|
SERVER_URL + DELETE_EVENT_ENDPOINT,
|
||||||
"userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(),
|
"userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -95,7 +96,7 @@ public class DataController {
|
|||||||
|
|
||||||
public void editEvent(Event oldEvent, Event event) throws HttpRequestException {
|
public void editEvent(Event oldEvent, Event event) throws HttpRequestException {
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
EDIT_EVENT_ENDPOINT,
|
SERVER_URL + EDIT_EVENT_ENDPOINT,
|
||||||
"eventId=" + oldEvent.getId() +
|
"eventId=" + oldEvent.getId() +
|
||||||
"&userId=" + oldEvent.getOwnerId() +
|
"&userId=" + oldEvent.getOwnerId() +
|
||||||
"&date=" + oldEvent.getDate().toLocalDate() +
|
"&date=" + oldEvent.getDate().toLocalDate() +
|
||||||
@ -113,7 +114,7 @@ public class DataController {
|
|||||||
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException {
|
public ArrayList<Event> getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException {
|
||||||
try {
|
try {
|
||||||
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
Tuple<Integer, String> response = httpRequest.sendPostRequest(
|
||||||
ALL_EVENTS_ENDPOINT,
|
SERVER_URL + ALL_EVENTS_ENDPOINT,
|
||||||
"userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(),
|
"userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -141,7 +142,7 @@ public class DataController {
|
|||||||
|
|
||||||
public List<User> getAllUser() throws HttpRequestException {
|
public List<User> getAllUser() throws HttpRequestException {
|
||||||
String userJSON = sendBasicHttpRequest(
|
String userJSON = sendBasicHttpRequest(
|
||||||
ALL_USER_ENDPOINT,
|
SERVER_URL + ALL_USER_ENDPOINT,
|
||||||
"",
|
"",
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -164,7 +165,7 @@ public class DataController {
|
|||||||
|
|
||||||
public void createUser(User user) throws HttpRequestException {
|
public void createUser(User user) throws HttpRequestException {
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
ADD_USER_ENDPOINT,
|
SERVER_URL + ADD_USER_ENDPOINT,
|
||||||
"name=" + user.getName() +
|
"name=" + user.getName() +
|
||||||
"&forename=" + user.getForename() +
|
"&forename=" + user.getForename() +
|
||||||
"&login=" + user.getLogin() +
|
"&login=" + user.getLogin() +
|
||||||
@ -176,7 +177,7 @@ public class DataController {
|
|||||||
|
|
||||||
public void deleteUser(User user) throws HttpRequestException {
|
public void deleteUser(User user) throws HttpRequestException {
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
DELETE_USER_ENDPOINT,
|
SERVER_URL + DELETE_USER_ENDPOINT,
|
||||||
"userId=" + user.getUserId(),
|
"userId=" + user.getUserId(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@ -192,7 +193,7 @@ public class DataController {
|
|||||||
|
|
||||||
System.out.println(urlParam);
|
System.out.println(urlParam);
|
||||||
sendBasicHttpRequest(
|
sendBasicHttpRequest(
|
||||||
EDIT_USER_ENDPOINT,
|
SERVER_URL + EDIT_USER_ENDPOINT,
|
||||||
urlParam,
|
urlParam,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user