Added base classes
This commit is contained in:
+1
-1
@@ -43,4 +43,4 @@ bin/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
/logs
|
/logs
|
||||||
config.toml
|
/config
|
||||||
|
|||||||
Generated
+31
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitToolBoxProjectSettings">
|
||||||
|
<option name="autoFetchEnabledOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="autoFetchIntervalMinutesOverride">
|
||||||
|
<IntValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
<option name="value" value="15" />
|
||||||
|
</IntValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="autoFetchOnBranchSwitchOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageIssueKeyValidationOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageValidationEnabledOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,6 +1,61 @@
|
|||||||
package dev.coph.flightscore.backend;
|
package dev.coph.flightscore.backend;
|
||||||
|
|
||||||
public class Backend {
|
import dev.coph.flightscore.backend.config.Config;
|
||||||
|
import dev.coph.simplelogger.Logger;
|
||||||
|
import dev.coph.simplerequest.server.WebServer;
|
||||||
|
import dev.coph.simplesql.adapter.DatabaseAdapter;
|
||||||
|
import dev.coph.simplesql.driver.DriverType;
|
||||||
|
import dev.coph.simpleutilities.config.ConfigurationManager;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public class Backend {
|
||||||
|
private final Logger logger = Logger.of("Backend");
|
||||||
|
private final ConfigurationManager configurationManager;
|
||||||
|
private final DatabaseAdapter databaseAdapter;
|
||||||
|
private final WebServer webServer;
|
||||||
|
|
||||||
|
|
||||||
|
public Backend() {
|
||||||
|
logger.info("Loading configuration...");
|
||||||
|
this.configurationManager = new ConfigurationManager();
|
||||||
|
Config configuration = configurationManager.configuration(Config.class);
|
||||||
|
logger.success("Configuration loaded!");
|
||||||
|
logger.info("Preparing database...");
|
||||||
|
this.databaseAdapter = new DatabaseAdapter.Builder()
|
||||||
|
.driverType(DriverType.MARIADB)
|
||||||
|
.host(configuration.database_url())
|
||||||
|
.port(configuration.database_port())
|
||||||
|
.database(configuration.database_databaseName())
|
||||||
|
.user(configuration.database_username())
|
||||||
|
.password(configuration.database_password())
|
||||||
|
.build();
|
||||||
|
logger.success("Database ready!");
|
||||||
|
logger.info("Preparing web server...");
|
||||||
|
this.webServer = new WebServer(configuration.server_port());
|
||||||
|
logger.success("Web server ready!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
logger.info("Loading routes...");
|
||||||
|
|
||||||
|
logger.success("Routes loaded!");
|
||||||
|
|
||||||
|
logger.info("Starting database...");
|
||||||
|
databaseAdapter.connect();
|
||||||
|
logger.success("Database started!");
|
||||||
|
|
||||||
|
logger.info("Starting web server...");
|
||||||
|
webServer.start();
|
||||||
|
logger.success("Web server started!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
logger.info("Stopping services...");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
package dev.coph.flightscore.backend;
|
package dev.coph.flightscore.backend;
|
||||||
|
|
||||||
|
import dev.coph.simplelogger.GenericLogger;
|
||||||
|
import dev.coph.simplelogger.LogLevel;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
private static Backend backend;
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
|
GenericLogger.instance().consoleLogLevel(LogLevel.DEBUG);
|
||||||
|
GenericLogger.instance().fileLogLevel(LogLevel.INFO);
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
|
if (backend != null) backend.onDisable();
|
||||||
|
}));
|
||||||
|
|
||||||
|
GenericLogger.info("Preparing backend...");
|
||||||
|
backend = new Backend();
|
||||||
|
GenericLogger.success("Backend ready!");
|
||||||
|
GenericLogger.info("Starting backend...");
|
||||||
|
backend.onEnable();
|
||||||
|
GenericLogger.success("Backend started!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package dev.coph.flightscore.backend.action.result;
|
||||||
|
|
||||||
|
import dev.coph.flightscore.backend.user.User;
|
||||||
|
|
||||||
|
public class LoginActionResult {
|
||||||
|
|
||||||
|
private User user;
|
||||||
|
private String accessToken;
|
||||||
|
private String refreshToken;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package dev.coph.flightscore.backend.config;
|
||||||
|
|
||||||
|
import dev.coph.simpleutilities.config.AbstractConfiguration;
|
||||||
|
import dev.coph.simpleutilities.config.ConfigurationFile;
|
||||||
|
import dev.coph.simpleutilities.config.DefaultValue;
|
||||||
|
import dev.coph.simpleutilities.config.provider.TomlConfigurationProvider;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
@ConfigurationFile(
|
||||||
|
description = "This is the configuration of the FlightScore backend. Only change if you know what you do.",
|
||||||
|
path = "config/backend.yaml",
|
||||||
|
type = TomlConfigurationProvider.class
|
||||||
|
)
|
||||||
|
public class Config extends AbstractConfiguration {
|
||||||
|
|
||||||
|
@DefaultValue("8080")
|
||||||
|
private int server_port;
|
||||||
|
|
||||||
|
@DefaultValue("127.0.0.1")
|
||||||
|
private String database_url;
|
||||||
|
@DefaultValue("3306")
|
||||||
|
private int database_port;
|
||||||
|
@DefaultValue("flightscore")
|
||||||
|
private String database_databaseName;
|
||||||
|
@DefaultValue("root")
|
||||||
|
private String database_password;
|
||||||
|
@DefaultValue("root")
|
||||||
|
private String database_username;
|
||||||
|
|
||||||
|
@DefaultValue("7a0c878e20c039349ef3fc5e0bebcedeb1441c123c118b243ee196dc6246cfd7")
|
||||||
|
private String jwt_secret;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.coph.flightscore.backend.user;
|
||||||
|
|
||||||
|
import dev.coph.flightscore.backend.user.role.Role;
|
||||||
|
import dev.coph.simpleutilities.ulid.ULID;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private ULID id;
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private String email;
|
||||||
|
private String phoneNumber;
|
||||||
|
private Role role;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package dev.coph.flightscore.backend.user;
|
||||||
|
|
||||||
|
import dev.coph.flightscore.backend.Backend;
|
||||||
|
import dev.coph.flightscore.backend.action.result.LoginActionResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserProvider {
|
||||||
|
private final Backend backend;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public LoginActionResult login(String email, String password) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package dev.coph.flightscore.backend.user.permission;
|
||||||
|
|
||||||
|
import dev.coph.simpleutilities.ulid.ULID;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public class Permission {
|
||||||
|
|
||||||
|
private ULID id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.coph.flightscore.backend.user.role;
|
||||||
|
|
||||||
|
import dev.coph.flightscore.backend.user.permission.Permission;
|
||||||
|
import dev.coph.simpleutilities.ulid.ULID;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public class Role {
|
||||||
|
|
||||||
|
private ULID id;
|
||||||
|
private String name;
|
||||||
|
private HashSet<Permission> permissions = new HashSet<>();
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user