Complete ConsoleMenu
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
Generated
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="WS-10-Database" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
Generated
+20
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://mirror-maven.runflare.com/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,44 +1,117 @@
|
|||||||
package dev.ui;
|
package dev.ui;
|
||||||
|
|
||||||
|
import dev.model.User;
|
||||||
|
import dev.service.AuthService;
|
||||||
|
import dev.service.MenuService;
|
||||||
|
import dev.service.OrderService;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ConsoleMenu {
|
public class ConsoleMenu {
|
||||||
|
|
||||||
private final Scanner scanner =
|
private final Scanner scanner = new Scanner(System.in);
|
||||||
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() {
|
public void start() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("===== JAVA PIZZERIA =====");
|
System.out.println("===== RESTAURANT SYSTEM =====");
|
||||||
System.out.println("1. Login");
|
System.out.println("1. Register");
|
||||||
System.out.println("2. Register");
|
System.out.println("2. Login");
|
||||||
System.out.println("3. Exit");
|
System.out.println("0. Exit");
|
||||||
|
System.out.print("Choose: ");
|
||||||
|
|
||||||
int choice = scanner.nextInt();
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
switch (choice) {
|
if (choice == 1) {
|
||||||
|
register();
|
||||||
case 1:
|
} else if (choice == 2) {
|
||||||
// TODO
|
login();
|
||||||
break;
|
} else if (choice == 0) {
|
||||||
|
System.out.println("Goodbye!");
|
||||||
case 2:
|
return;
|
||||||
// TODO
|
} else {
|
||||||
break;
|
System.out.println("Invalid choice.");
|
||||||
|
|
||||||
case 3:
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
|
||||||
System.out.println("Invalid choice");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void register() {
|
||||||
|
|
||||||
|
System.out.print("Username: ");
|
||||||
|
String username = scanner.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Password: ");
|
||||||
|
String password = scanner.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Email: ");
|
||||||
|
String email = scanner.nextLine();
|
||||||
|
|
||||||
|
boolean success = authService.register(username, password, email);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
System.out.println("Registration successful.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Registration failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void login() {
|
||||||
|
|
||||||
|
System.out.print("Username: ");
|
||||||
|
String username = scanner.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Password: ");
|
||||||
|
String password = scanner.nextLine();
|
||||||
|
|
||||||
|
User user = authService.login(username, password);
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
System.out.println("Invalid username or password.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Login successful. Welcome " + user.getUsername());
|
||||||
|
|
||||||
|
userMenu(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void userMenu(User user) {
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("===== USER MENU =====");
|
||||||
|
System.out.println("1. View Menu");
|
||||||
|
System.out.println("2. Place Order");
|
||||||
|
System.out.println("3. Order History");
|
||||||
|
System.out.println("0. Logout");
|
||||||
|
System.out.print("Choose: ");
|
||||||
|
|
||||||
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
|
if (choice == 1) {
|
||||||
|
menuService.showMenu();
|
||||||
|
} else if (choice == 2) {
|
||||||
|
menuService.showMenu();
|
||||||
|
orderService.placeOrder(user.getId());
|
||||||
|
} else if (choice == 3) {
|
||||||
|
orderService.showOrderHistory(user.getId());
|
||||||
|
} else if (choice == 0) {
|
||||||
|
System.out.println("Logged out.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid choice.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user