implement ConsoleMenu.java
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package dev.ui;
|
package dev.ui;
|
||||||
|
|
||||||
|
import dev.model.User;
|
||||||
|
import dev.service.AuthService;
|
||||||
|
import dev.service.MenuService;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ConsoleMenu {
|
public class ConsoleMenu {
|
||||||
@@ -7,6 +11,8 @@ public class ConsoleMenu {
|
|||||||
private final Scanner scanner =
|
private final Scanner scanner =
|
||||||
new Scanner(System.in);
|
new Scanner(System.in);
|
||||||
|
|
||||||
|
private AuthService authService = new AuthService();
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -18,23 +24,50 @@ public class ConsoleMenu {
|
|||||||
System.out.println("3. Exit");
|
System.out.println("3. Exit");
|
||||||
|
|
||||||
int choice = scanner.nextInt();
|
int choice = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
|
|
||||||
case 1:
|
case 1: {
|
||||||
// TODO
|
System.out.print("Enter your username: ");
|
||||||
break;
|
String username = scanner.nextLine();
|
||||||
|
System.out.print("Enter your password: ");
|
||||||
|
String password = scanner.nextLine();
|
||||||
|
|
||||||
case 2:
|
User user = authService.login(username, password);
|
||||||
// TODO
|
|
||||||
break;
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
|
}
|
||||||
default:
|
default: {
|
||||||
System.out.println("Invalid choice");
|
System.out.println("Invalid choice enter a number between [1, 3]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user