From cd8e4c9b3dd38323f4d53e627515061262bb10a1 Mon Sep 17 00:00:00 2001 From: Johannes Kantz <67144859+JohannesKantz@users.noreply.github.com> Date: Sat, 4 Feb 2023 18:49:22 +0100 Subject: [PATCH] add: create worker account on first launch --- .../essensbestellungsverwaltung/Parent.java | 15 +++++++++--- .../SingUpController.java | 24 ++++++++++++++----- .../StartViewApplication.java | 5 ++-- .../essensbestellungsverwaltung/Worker.java | 11 +++++++-- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/Parent.java b/src/main/java/com/bib/essensbestellungsverwaltung/Parent.java index 1f3f7df..8b9178b 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/Parent.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/Parent.java @@ -4,21 +4,30 @@ import java.util.ArrayList; import java.util.List; /** - * one constructor is used to create new parents the other is used to create existing parents from database + * one constructor is used to create new parents the other is used to create + * existing parents from database + * * @author Malte Schulze Hobeling */ -public class Parent extends User{ +public class Parent extends User { List children; - public Parent(long id, String name, String firstname, String password, String email, Address address, List children) { + public Parent(long id, String name, String firstname, String password, String email, Address address, + List children) { super(id, name, firstname, password, email, address); this.children = children; } + public Parent(String name, String firstname, String password, String email, Address address) { super(name, firstname, password, email, address); this.children = new ArrayList<>(); } + public Parent(User user) { + super(user.getId(), user.getName(), user.getFirstname(), user.getPassword(), user.getEmail(), user.getAddress()); + this.children = new ArrayList<>(); + } + public List getChildren() { return children; } diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/SingUpController.java b/src/main/java/com/bib/essensbestellungsverwaltung/SingUpController.java index 557012e..891eac6 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/SingUpController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/SingUpController.java @@ -4,14 +4,11 @@ package com.bib.essensbestellungsverwaltung; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import java.io.IOException; -import java.util.HashMap; public class SingUpController { @FXML @@ -74,9 +71,24 @@ public class SingUpController { }else { Address newAdresse = new Address(strasse,hausnummer,plz,stadt); User newUser = new User(name,vorname,passwort,email,newAdresse); - long creatNewUser = AccountMgr.createUser(newUser); - if (creatNewUser > 0){ - alert = new Alert(Alert.AlertType.CONFIRMATION,"Ihrer Daten wurde gespeichert."); + if(StartViewApplication.firstLaunch){ + long id = AccountMgr.createWorker(new Worker(newUser)); + if(id < 1) { + Alert a = new Alert(Alert.AlertType.ERROR,"Es ist ein Fehler bei der Erstellung Ihres Accounts aufgetreten."); + a.showAndWait(); + return; + } + alert = new Alert(Alert.AlertType.CONFIRMATION,"Mitarbeiter Account erfolgreich erstellt"); + alert.showAndWait(); + StartViewApplication.firstLaunch = false; + }else { + long id = AccountMgr.createParent(new Parent(newUser)); + if(id < 1) { + Alert a = new Alert(Alert.AlertType.ERROR,"Es ist ein Fehler bei der Erstellung Ihres Accounts aufgetreten."); + a.showAndWait(); + return; + } + alert = new Alert(Alert.AlertType.CONFIRMATION,"Eltern Account erfolgreich erstellt"); alert.showAndWait(); } tfName.setText(""); diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java b/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java index 911705f..3dae544 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java @@ -15,10 +15,11 @@ import java.io.IOException; public class StartViewApplication extends Application { public static Stage primary; + public static boolean firstLaunch; @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("login-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource((firstLaunch) ? "signUp-view.fxml" : "login-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 1300, 750); primary = stage; stage.setTitle("Essen Bestellung im Kindergarten"); @@ -29,7 +30,7 @@ public class StartViewApplication extends Application { } public static void main(String[] args) { - Database.init(); + firstLaunch = Database.init(); Database.createDb(); Database.fillDb(); //Database.printSampleQuery(); diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/Worker.java b/src/main/java/com/bib/essensbestellungsverwaltung/Worker.java index 45161f3..60f02f8 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/Worker.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/Worker.java @@ -1,14 +1,21 @@ package com.bib.essensbestellungsverwaltung; /** - * one constructor is used to create new worker the other is used to create existing worker from database + * one constructor is used to create new worker the other is used to create + * existing worker from database + * * @author Malte Schulze Hobeling */ -public class Worker extends User{ +public class Worker extends User { public Worker(long id, String name, String firstname, String password, String email, Address address) { super(id, name, firstname, password, email, address); } + public Worker(String name, String firstname, String password, String email, Address address) { super(name, firstname, password, email, address); } + + public Worker(User user) { + super(user.getId(), user.getName(), user.getFirstname(), user.getPassword(), user.getEmail(), user.getAddress()); + } }