complete Restaurant Database Management System implementation

This commit is contained in:
Fatemesadat Mirabootalebi
2026-06-22 08:48:12 -07:00
parent 00f990c653
commit 7ef862c5e1
18 changed files with 656 additions and 26 deletions
+93
View File
@@ -1,11 +1,22 @@
package dev.ui;
import java.util.Scanner;
import dev.model.User;
import dev.service.AuthService;
import dev.service.MenuService;
import dev.service.OrderService;
import java.lang.reflect.Field;
public class ConsoleMenu {
private final Scanner scanner =
new Scanner(System.in);
private final AuthService authService =
new AuthService();
private final MenuService menuService =
new MenuService();
private final OrderService orderService =
new OrderService();
public void start() {
@@ -18,18 +29,22 @@ public class ConsoleMenu {
System.out.println("3. Exit");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
// TODO
handleLogin();
break;
case 2:
// TODO
handleRegister();
break;
case 3:
System.out.println("Goodbye!");
return;
default:
@@ -40,5 +55,83 @@ public class ConsoleMenu {
}
}
private void handleLogin(){
System.out.println("\n[Login]");
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
User loggedInUser = authService.login(username, password);
if (loggedInUser != null){
System.out.println("Login successful! Welcome, " + username + ".");
showUserMenu(loggedInUser);
}
else{
System.out.println("Error: Invalid username or password.");
}
}
private void handleRegister(){
System.out.println("\n[Register New Account]");
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
System.out.print("Enter email (optional, press enter to skip): ");
String email = scanner.nextLine();
if (email.trim().isEmpty()){
email = null;
}
if (authService.register(username, password, email)){
System.out.println("Registration successful! You can now log in.");
}
else{
System.out.println("Registration failed.");
}
}
private void showUserMenu(User user){
try {
Field idField = User.class.getDeclaredField("id");
idField.setAccessible(true);
int userId = (int) idField.get(user);
while (true){
System.out.println("\n=======================================");
System.out.println(" 🍽️ MAIN MENU 🍽️");
System.out.println("=======================================");
System.out.println("1. View Menu");
System.out.println("2. Place a New Order");
System.out.println("3. View Order History");
System.out.println("4. Logout");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice){
case 1:
menuService.showMenu();
break;
case 2:
menuService.showMenu();
orderService.placeOrder(userId);
break;
case 3:
orderService.showOrderHistory(userId);
break;
case 4:
System.out.println("Logged out successfully.");
return;
default:
System.out.println("Invalid choice.");
}
}
}
catch (Exception ex){
ex.printStackTrace();
}
}
}