-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (44 loc) · 1.95 KB
/
Main.java
File metadata and controls
56 lines (44 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.example;
import com.example.cli.*;
import com.example.repository.*;
import com.example.service.*;
/**
* Entry point for the Moon Mission application.
*
* <p>
* Initializes the development database if dev mode is enabled, sets up repositories,
* services, and CLI components, handles user login, and shows the main menu.
* </p>
*/
public class Main {
/**
* Starts the application.
*
* @param args Command-line arguments. Supports "--dev" to enable dev mode.
*/
public static void main(String[] args) {
if (ConfigUtils.isDevMode(args)) {
DevDatabaseInitializer.start();
}
String jdbcUrl = ConfigUtils.resolveConfig("APP_JDBC_URL", "APP_JDBC_URL");
String dbUser = ConfigUtils.resolveConfig("APP_DB_USER", "APP_DB_USER");
String dbPass = ConfigUtils.resolveConfig("APP_DB_PASS", "APP_DB_PASS");
if (jdbcUrl == null || dbUser == null || dbPass == null) {
throw new IllegalStateException("Missing DB configuration.");
}
SimpleDriverManagerDataSource dataSource = new SimpleDriverManagerDataSource(jdbcUrl, dbUser, dbPass);
boolean devMode = ConfigUtils.isDevMode(args);
AccountRepositoryJdbc accountRepo = new AccountRepositoryJdbc(dataSource, devMode);
MoonMissionRepositoryJdbc missionRepo = new MoonMissionRepositoryJdbc(dataSource, devMode);
AccountService accountService = new AccountService(accountRepo);
MoonMissionService missionService = new MoonMissionService(missionRepo);
InputReader input = new InputReader();
AccountCLI accountCLI = new AccountCLI(accountService, input);
MoonMissionCLI missionCLI = new MoonMissionCLI(missionService, input);
MenuCLI menu = new MenuCLI(accountCLI, missionCLI, input);
LoginManager loginManager = new LoginManager(accountService, input);
if (loginManager.login()) {
menu.showMainMenu();
}
}
}