implement ConsoleMenu.java
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package dev.ui;
|
||||
|
||||
import dev.model.User;
|
||||
import dev.service.AuthService;
|
||||
import dev.service.MenuService;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ConsoleMenu {
|
||||
@@ -7,6 +11,8 @@ public class ConsoleMenu {
|
||||
private final Scanner scanner =
|
||||
new Scanner(System.in);
|
||||
|
||||
private AuthService authService = new AuthService();
|
||||
|
||||
public void start() {
|
||||
|
||||
while (true) {
|
||||
@@ -18,23 +24,50 @@ public class ConsoleMenu {
|
||||
System.out.println("3. Exit");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
|
||||
case 1:
|
||||
// TODO
|
||||
break;
|
||||
case 1: {
|
||||
System.out.print("Enter your username: ");
|
||||
String username = scanner.nextLine();
|
||||
System.out.print("Enter your password: ");
|
||||
String password = scanner.nextLine();
|
||||
|
||||
case 2:
|
||||
// TODO
|
||||
break;
|
||||
User user = authService.login(username, password);
|
||||
|
||||
case 3:
|
||||
if (user == null) {
|
||||
System.err.println("Unable to login.");
|
||||
continue;
|
||||
}
|
||||
|
||||
MenuService menuService = new MenuService();
|
||||
menuService.ShowPanel(user);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
System.out.print("Enter your username: ");
|
||||
String username = scanner.nextLine();
|
||||
System.out.print("Enter your password: ");
|
||||
String password = scanner.nextLine();
|
||||
System.out.print("Enter your email (optional): ");
|
||||
String tmp = scanner.nextLine();
|
||||
String email = tmp.isEmpty() ? null : tmp;
|
||||
|
||||
if (!authService.register(username, password, email)) {
|
||||
System.err.println("Registration failed.");
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("Registration successful!");
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
return;
|
||||
|
||||
default:
|
||||
System.out.println("Invalid choice");
|
||||
|
||||
}
|
||||
default: {
|
||||
System.out.println("Invalid choice enter a number between [1, 3]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user