From 245314a887a04e9069fb972158376abfb4e1b0da Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 12:03:09 +0100 Subject: [PATCH] Renamed package; Implemented create user --- .../main/java/main/CreateEventController.java | 4 ++-- .../main/java/main/EditEventController.java | 4 ++-- .../src/main/java/main/MainApplication.java | 4 ++-- .../src/main/java/main/MainController.java | 6 ++--- .../src/main/java/main/OptionController.java | 10 +++++--- .../main/java/users/CreateUserController.java | 24 +++++++++++++++++++ .../main/java/users/EditUserController.java | 2 +- .../src/main/java/users/LoginController.java | 2 +- .../{res => container}/DataController.java | 4 ++-- .../main/java/{res => container}/Event.java | 2 +- .../java/{res => container}/HttpRequest.java | 3 +-- .../main/java/{res => container}/User.java | 4 +++- 12 files changed, 49 insertions(+), 20 deletions(-) rename client/data/src/main/java/{res => container}/DataController.java (98%) rename client/data/src/main/java/{res => container}/Event.java (99%) rename client/data/src/main/java/{res => container}/HttpRequest.java (98%) rename client/data/src/main/java/{res => container}/User.java (98%) diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index 999bd19..ed86f69 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -10,8 +10,8 @@ import javafx.scene.layout.GridPane; import javafx.stage.Stage; import javafx.util.StringConverter; import javafx.util.converter.LocalTimeStringConverter; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; import java.time.LocalTime; import java.time.format.FormatStyle; diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index a6f811f..cce82d9 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -1,8 +1,8 @@ package main; import helper.HttpRequestException; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; public class EditEventController extends CreateEventController{ diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index 09274f4..4e514f0 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -6,8 +6,8 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import res.DataController; -import res.HttpRequest; +import container.DataController; +import container.HttpRequest; import java.io.IOException; import java.util.Objects; diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 02b80e3..cca56f8 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -16,11 +16,11 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Modality; import javafx.stage.Stage; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; import javafx.event.ActionEvent; -import res.HttpRequest; +import container.HttpRequest; import java.io.IOException; import java.time.Duration; diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index aefd27a..bca3c9f 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -15,8 +15,8 @@ import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Modality; import javafx.stage.Stage; -import res.DataController; -import res.User; +import container.DataController; +import container.User; import java.io.IOException; import java.util.ArrayList; @@ -79,12 +79,16 @@ public class OptionController { Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Wirklich löschen?"); Optional result = alert.showAndWait(); if(result.isPresent() && result.get() == ButtonType.OK){ + int removeIndex = comboBox.getSelectionModel().getSelectedIndex(); try { - dataController.deleteUser(users.get(comboBox.getSelectionModel().getSelectedIndex())); + dataController.deleteUser(users.get(removeIndex)); } catch (HttpRequestException e) { Alert alert1 = new Alert(Alert.AlertType.ERROR, e.getMessage()); alert1.showAndWait(); + return; } + comboBox.getItems().remove(removeIndex); + users.remove(removeIndex); } } diff --git a/client/app/src/main/java/users/CreateUserController.java b/client/app/src/main/java/users/CreateUserController.java index 3f54a46..bfce642 100644 --- a/client/app/src/main/java/users/CreateUserController.java +++ b/client/app/src/main/java/users/CreateUserController.java @@ -1,5 +1,6 @@ package users; +import helper.HttpRequestException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; @@ -8,6 +9,8 @@ import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.control.ToggleButton; import javafx.stage.Stage; +import container.DataController; +import container.User; import java.util.Objects; @@ -39,15 +42,36 @@ public class CreateUserController { 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.setLogin(textLogin.getText().trim()); + user.setForename(textForename.getText().trim()); + user.setName(textName.getText().trim()); + user.setPassword(textPassword.getText().trim()); + + try { + sendHttpRequest(user); + } catch (HttpRequestException e) { + labelError.setText(e.getMessage()); + } + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); stage.close(); } + protected void sendHttpRequest(User user) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.createUser(user); + } + @FXML protected void abortBtnClick(ActionEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java index e51ffbc..6063a59 100644 --- a/client/app/src/main/java/users/EditUserController.java +++ b/client/app/src/main/java/users/EditUserController.java @@ -1,6 +1,6 @@ package users; -import res.User; +import container.User; public class EditUserController extends CreateUserController{ private User currentUser; diff --git a/client/app/src/main/java/users/LoginController.java b/client/app/src/main/java/users/LoginController.java index 3bce950..37da4be 100644 --- a/client/app/src/main/java/users/LoginController.java +++ b/client/app/src/main/java/users/LoginController.java @@ -6,7 +6,7 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.stage.Stage; -import res.DataController; +import container.DataController; public class LoginController { @FXML diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/container/DataController.java similarity index 98% rename from client/data/src/main/java/res/DataController.java rename to client/data/src/main/java/container/DataController.java index 2a4fb2f..52c2a95 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/container/DataController.java @@ -1,4 +1,4 @@ -package res; +package container; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -148,7 +148,7 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); try { - return (List)objectMapper.readValue(userJSON, new TypeReference>() {}); + return objectMapper.readValue(userJSON, new TypeReference<>() {}); } catch (JsonProcessingException e) { e.printStackTrace(); } diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/container/Event.java similarity index 99% rename from client/data/src/main/java/res/Event.java rename to client/data/src/main/java/container/Event.java index 0520e06..35c1d35 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/container/Event.java @@ -1,4 +1,4 @@ -package res; +package container; import java.time.Duration; import java.time.LocalDateTime; diff --git a/client/data/src/main/java/res/HttpRequest.java b/client/data/src/main/java/container/HttpRequest.java similarity index 98% rename from client/data/src/main/java/res/HttpRequest.java rename to client/data/src/main/java/container/HttpRequest.java index 7dba427..8ddf2d2 100644 --- a/client/data/src/main/java/res/HttpRequest.java +++ b/client/data/src/main/java/container/HttpRequest.java @@ -1,4 +1,4 @@ -package res; +package container; import helper.Tuple; @@ -9,7 +9,6 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; public class HttpRequest { public static String TOKEN = ""; diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/container/User.java similarity index 98% rename from client/data/src/main/java/res/User.java rename to client/data/src/main/java/container/User.java index d58461b..c77b320 100644 --- a/client/data/src/main/java/res/User.java +++ b/client/data/src/main/java/container/User.java @@ -1,4 +1,4 @@ -package res; +package container; public class User { @@ -11,6 +11,8 @@ public class User { public User(){} + + public int getUserId() { return userId; }