Renamed package;

Implemented create user
This commit is contained in:
Marc Beyer 2022-01-29 12:03:09 +01:00
parent 72fdce471b
commit 245314a887
12 changed files with 49 additions and 20 deletions

View File

@ -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;

View File

@ -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{

View File

@ -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;

View File

@ -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;

View File

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

View File

@ -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();

View File

@ -1,6 +1,6 @@
package users;
import res.User;
import container.User;
public class EditUserController extends CreateUserController{
private User currentUser;

View File

@ -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

View File

@ -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<User>)objectMapper.readValue(userJSON, new TypeReference<List<User>>() {});
return objectMapper.readValue(userJSON, new TypeReference<>() {});
} catch (JsonProcessingException e) {
e.printStackTrace();
}

View File

@ -1,4 +1,4 @@
package res;
package container;
import java.time.Duration;
import java.time.LocalDateTime;

View File

@ -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 = "";

View File

@ -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;
}