diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..494318c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..90fdf05 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/de/antco/projekt/ConsoleUi.java b/src/main/java/de/antco/projekt/ConsoleUi.java index 9e19e3a..255d4f1 100644 --- a/src/main/java/de/antco/projekt/ConsoleUi.java +++ b/src/main/java/de/antco/projekt/ConsoleUi.java @@ -8,12 +8,10 @@ import de.antco.projekt.model.WorkOrderItem; import de.antco.projekt.service.WorkshopService; import java.sql.SQLException; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; +import java.util.*; public class ConsoleUi { + private final WorkshopService service; private final Scanner scanner = new Scanner(System.in); @@ -23,168 +21,235 @@ public class ConsoleUi { public void start() { boolean running = true; + while (running) { - printMenu(); - String input = scanner.nextLine(); + showMenu(); + String choice = scanner.nextLine().trim(); + try { - switch (input) { + switch (choice) { case "1" -> addPerson(); - case "2" -> listPersons(); + case "2" -> showPersons(); case "3" -> addVehicle(); - case "4" -> listVehiclesOfPerson(); + case "4" -> showVehiclesOfPerson(); case "5" -> createWorkOrder(); - case "6" -> listWorkOrders(); + case "6" -> showWorkOrders(); case "0" -> running = false; - default -> System.out.println("Unbekannte Auswahl"); + default -> System.out.println("Ungültige Eingabe."); } } catch (SQLException e) { - System.out.println("Fehler: " + e.getMessage()); + System.out.println("Ein Fehler ist aufgetreten: " + e.getMessage()); } } - System.out.println("Bis dann"); + + System.out.println("Programm beendet."); } - private void printMenu() { - System.out.println(); - System.out.println("==== Werkstatt Menü ===="); + private void showMenu() { + System.out.println("\n=== Werkstatt Menü ==="); System.out.println("1) Kunde anlegen"); System.out.println("2) Kunden anzeigen"); System.out.println("3) Fahrzeug anlegen"); - System.out.println("4) Fahrzeuge einer Person"); + System.out.println("4) Fahrzeuge einer Person anzeigen"); System.out.println("5) Werkstattvorgang anlegen"); System.out.println("6) Vorgänge anzeigen"); - System.out.println("0) Ende"); + System.out.println("0) Beenden"); System.out.print("Auswahl: "); } - private void addPerson() throws SQLException { - System.out.print("Name: "); - String name = scanner.nextLine(); - System.out.print("Telefon: "); - String phone = scanner.nextLine(); - Person person = service.createPerson(name, phone); - System.out.println("Kunde gespeichert mit ID " + person.getId()); + private int readInt(String text) { + while (true) { + System.out.print(text); + String input = scanner.nextLine(); + + try { + return Integer.parseInt(input.trim()); + } catch (NumberFormatException e) { + System.out.println("Bitte eine gültige Zahl eingeben."); + } + } } - private void listPersons() throws SQLException { + private String readNonEmpty(String text) { + while (true) { + System.out.print(text); + String value = scanner.nextLine().trim(); + + if (!value.isEmpty()) { + return value; + } + + System.out.println("Eingabe darf nicht leer sein."); + } + } + + private String readValidName(String text) { + while (true) { + String name = readNonEmpty(text); + + if (name.matches("[a-zA-ZäöüÄÖÜß ]+")) { + return name; + } + + System.out.println("Der Name darf nur Buchstaben enthalten."); + } + } + + private String readPhoneNumber(String text) { + while (true) { + System.out.print(text); + String phone = scanner.nextLine().trim(); + + if (phone.matches("\\d+")) { + return phone; + } + + System.out.println("Telefonnummer darf nur Zahlen enthalten."); + } + } + + private void addPerson() throws SQLException { + String name = readValidName("Name: "); + String phone = readPhoneNumber("Telefonnummer: "); + + Person person = service.createPerson(name, phone); + System.out.println("Kunde gespeichert (ID: " + person.getId() + ")"); + } + + private void showPersons() throws SQLException { List persons = service.listPersons(); + if (persons.isEmpty()) { - System.out.println("Keine Personen da"); + System.out.println("Keine Kunden vorhanden."); return; } - persons.forEach(p -> System.out.println(p.toString())); + + System.out.println("\n--- Kundenliste ---"); + persons.forEach(System.out::println); } private void addVehicle() throws SQLException { - System.out.print("Personen ID: "); - int personId = parseInt(scanner.nextLine()); - Person owner = service.findPerson(personId); - if (owner == null) { - System.out.println("Person nicht gefunden"); + int personId = readInt("Personen-ID: "); + Person person = service.findPerson(personId); + + if (person == null) { + System.out.println("Person wurde nicht gefunden."); return; } - System.out.print("Hersteller: "); - String brand = scanner.nextLine(); - System.out.print("Modell: "); - String model = scanner.nextLine(); - System.out.print("Kennzeichen: "); - String plate = scanner.nextLine(); + + String brand = readNonEmpty("Hersteller: "); + String model = readNonEmpty("Modell: "); + String plate = readNonEmpty("Kennzeichen: "); + Vehicle vehicle = service.createVehicle(personId, brand, model, plate); - System.out.println("Fahrzeug gespeichert mit ID " + vehicle.getId()); + System.out.println("Fahrzeug angelegt (ID: " + vehicle.getId() + ")"); } - private void listVehiclesOfPerson() throws SQLException { - System.out.print("Personen ID: "); - int personId = parseInt(scanner.nextLine()); - Person owner = service.findPerson(personId); - if (owner == null) { - System.out.println("Person nicht gefunden"); + private void showVehiclesOfPerson() throws SQLException { + int personId = readInt("Personen-ID: "); + Person person = service.findPerson(personId); + + if (person == null) { + System.out.println("Person nicht gefunden."); return; } + List vehicles = service.listVehicles(personId); - System.out.println("Fahrzeuge von " + owner.getName() + ":"); + + System.out.println("Fahrzeuge von " + person.getName() + ":"); if (vehicles.isEmpty()) { - System.out.println("Keine Einträge"); - return; + System.out.println("Keine Fahrzeuge vorhanden."); + } else { + vehicles.forEach(System.out::println); } - vehicles.forEach(v -> System.out.println(v.toString())); } private void createWorkOrder() throws SQLException { - System.out.print("Fahrzeug ID: "); - int vehicleId = parseInt(scanner.nextLine()); + int vehicleId = readInt("Fahrzeug-ID: "); Vehicle vehicle = service.findVehicle(vehicleId); + if (vehicle == null) { - System.out.println("Fahrzeug nicht gefunden"); + System.out.println("Fahrzeug nicht gefunden."); return; } - System.out.print("Notiz: "); - String note = scanner.nextLine(); + + String note = readNonEmpty("Notiz: "); + List catalog = service.listServiceItems(); - Map selected = new LinkedHashMap<>(); - boolean adding = true; - while (adding) { - showCatalog(catalog); - System.out.print("Service ID (leer = fertig): "); - String input = scanner.nextLine(); - if (input.isBlank()) { - adding = false; - } else { - int serviceId = parseInt(input); - ServiceItem item = catalog.stream().filter(s -> s.getId() == serviceId).findFirst().orElse(null); - if (item == null) { - System.out.println("Service gibt es nicht"); - continue; - } - System.out.print("Menge: "); - int qty = parseInt(scanner.nextLine()); - if (qty <= 0) { - System.out.println("Menge muss > 0 sein"); - continue; - } - selected.put(serviceId, selected.getOrDefault(serviceId, 0) + qty); + Map selectedItems = new LinkedHashMap<>(); + + while (true) { + System.out.println("\n--- Service-Katalog ---"); + catalog.forEach(System.out::println); + + System.out.print("Service-ID (leer = fertig): "); + String input = scanner.nextLine().trim(); + + if (input.isEmpty()) { + break; } + + int serviceId; + try { + serviceId = Integer.parseInt(input); + } catch (NumberFormatException e) { + System.out.println("Bitte eine gültige ID eingeben."); + continue; + } + + ServiceItem item = catalog.stream() + .filter(s -> s.getId() == serviceId) + .findFirst() + .orElse(null); + + if (item == null) { + System.out.println("Service nicht gefunden."); + continue; + } + + int qty = readInt("Menge: "); + if (qty <= 0) { + System.out.println("Menge muss größer als 0 sein."); + continue; + } + + selectedItems.merge(serviceId, qty, Integer::sum); } - if (selected.isEmpty()) { - System.out.println("Keine Positionen gespeichert"); + + if (selectedItems.isEmpty()) { + System.out.println("Keine Positionen ausgewählt."); return; } - int orderId = service.createWorkOrder(vehicleId, note, selected); - System.out.println("Vorgang angelegt mit ID " + orderId); + + int orderId = service.createWorkOrder(vehicleId, note, selectedItems); + System.out.println("Vorgang wurde angelegt (ID: " + orderId + ")"); } - private void showCatalog(List items) { - System.out.println("Katalog:"); - items.forEach(item -> System.out.println(item.toString())); - } - - private void listWorkOrders() throws SQLException { + private void showWorkOrders() throws SQLException { List orders = service.listWorkOrders(); + if (orders.isEmpty()) { - System.out.println("Keine Vorgänge gespeichert"); + System.out.println("Keine Vorgänge vorhanden."); return; } + for (WorkOrderDetails order : orders) { - System.out.println("--- Vorgang " + order.getOrderId() + " ---"); + System.out.println("\n--- Vorgang " + order.getOrderId() + " ---"); System.out.println("Kunde: " + order.getPersonName()); System.out.println("Fahrzeug: " + order.getVehicleText()); System.out.println("Datum: " + order.getCreatedAt()); + if (order.getNote() != null && !order.getNote().isBlank()) { System.out.println("Notiz: " + order.getNote()); } + for (WorkOrderItem item : order.getItems()) { - System.out.println(" * " + item.getServiceItem().getTitle() + " x" + item.getQuantity() + + System.out.println(" - " + item.getServiceItem().getTitle() + + " x" + item.getQuantity() + " = " + item.getTotalPrice() + " €"); } - System.out.println("Summe: " + order.getTotal() + " €"); - } - } - private int parseInt(String input) { - try { - return Integer.parseInt(input.trim()); - } catch (NumberFormatException e) { - return -1; + System.out.println("Gesamtsumme: " + order.getTotal() + " €"); } } -} +} \ No newline at end of file diff --git a/src/main/java/de/antco/projekt/Exporters/IExporter.java b/src/main/java/de/antco/projekt/Exporters/IExporter.java new file mode 100644 index 0000000..3352ea5 --- /dev/null +++ b/src/main/java/de/antco/projekt/Exporters/IExporter.java @@ -0,0 +1,4 @@ +package de.antco.projekt.Exporters; + +public interface IExporter { +} diff --git a/src/main/java/de/antco/projekt/Importers/IImporter.java b/src/main/java/de/antco/projekt/Importers/IImporter.java new file mode 100644 index 0000000..72bfb19 --- /dev/null +++ b/src/main/java/de/antco/projekt/Importers/IImporter.java @@ -0,0 +1,4 @@ +package de.antco.projekt.Importers; + +public interface IImporter { +} diff --git a/src/main/java/de/antco/projekt/loggers/ILogger.java b/src/main/java/de/antco/projekt/loggers/ILogger.java new file mode 100644 index 0000000..b30e02d --- /dev/null +++ b/src/main/java/de/antco/projekt/loggers/ILogger.java @@ -0,0 +1,5 @@ +package de.antco.projekt.loggers; + +public interface ILogger { + void Log(); +} diff --git a/target/classes/de/antco/projekt/ConsoleUi.class b/target/classes/de/antco/projekt/ConsoleUi.class index b1bd97c..fce8c12 100644 Binary files a/target/classes/de/antco/projekt/ConsoleUi.class and b/target/classes/de/antco/projekt/ConsoleUi.class differ diff --git a/target/classes/de/antco/projekt/Exporters/IExporter.class b/target/classes/de/antco/projekt/Exporters/IExporter.class new file mode 100644 index 0000000..06482d1 Binary files /dev/null and b/target/classes/de/antco/projekt/Exporters/IExporter.class differ diff --git a/target/classes/de/antco/projekt/Importers/IImporter.class b/target/classes/de/antco/projekt/Importers/IImporter.class new file mode 100644 index 0000000..12168a7 Binary files /dev/null and b/target/classes/de/antco/projekt/Importers/IImporter.class differ diff --git a/target/classes/de/antco/projekt/loggers/ILogger.class b/target/classes/de/antco/projekt/loggers/ILogger.class new file mode 100644 index 0000000..bcf6529 Binary files /dev/null and b/target/classes/de/antco/projekt/loggers/ILogger.class differ