diff --git a/app/mourne_application.cpp b/app/mourne_application.cpp index 916a268..a74cee7 100644 --- a/app/mourne_application.cpp +++ b/app/mourne_application.cpp @@ -17,6 +17,8 @@ #include "modules/users/user.h" #include "modules/users/user_controller.h" +#include "village/village_initializer.h" + bool MourneApplication::is_logged_in(Request *request) { if (!request->session) { return false; @@ -233,6 +235,11 @@ void MourneApplication::setup_middleware() { } void MourneApplication::migrate() { + VillageController::get_singleton()->migrate(); +} + +void MourneApplication::add_default_data() { + VillageController::get_singleton()->add_default_data(); } void MourneApplication::compile_menu() { @@ -263,10 +270,14 @@ void MourneApplication::compile_menu() { MourneApplication::MourneApplication() : DWebApplication() { + VillageInitializer::allocate_all(); + compile_menu(); } MourneApplication::~MourneApplication() { + + VillageInitializer::free_all(); } std::string MourneApplication::menu_head = ""; diff --git a/app/mourne_application.h b/app/mourne_application.h index 9f33a84..d32917c 100644 --- a/app/mourne_application.h +++ b/app/mourne_application.h @@ -50,6 +50,7 @@ public: virtual void setup_middleware(); virtual void migrate(); + virtual void add_default_data(); void compile_menu(); diff --git a/app/village/village_controller.cpp b/app/village/village_controller.cpp index 1d33485..34bccdf 100644 --- a/app/village/village_controller.cpp +++ b/app/village/village_controller.cpp @@ -7,10 +7,18 @@ #include "core/http/request.h" #include "core/http/session_manager.h" +#include "village_model.h" void VillageController::handle_request_default(Request *request) { } +void VillageController::migrate() { + VillageModel::get_singleton()->migrate(); +} +void VillageController::add_default_data() { + VillageModel::get_singleton()->add_default_data(); +} + VillageController *VillageController::get_singleton() { return _self; } diff --git a/app/village/village_controller.h b/app/village/village_controller.h index 454d4e2..b719f9e 100644 --- a/app/village/village_controller.h +++ b/app/village/village_controller.h @@ -15,6 +15,9 @@ class VillageController : public Object { RCPP_OBJECT(VillageController, Object); public: + void migrate(); + virtual void add_default_data(); + virtual void handle_request_default(Request *request); static VillageController *get_singleton(); diff --git a/main.cpp b/main.cpp index 4ed1f96..5a0582a 100644 --- a/main.cpp +++ b/main.cpp @@ -14,8 +14,6 @@ #include "core/http/session_manager.h" -#define MAIN_CLASS MourneApplication - #include "modules/drogon/web_application.h" //Backends @@ -67,7 +65,7 @@ int main(int argc, char **argv, char **envp) { create_databases(); - DWebApplication *app = new MAIN_CLASS(); + MourneApplication *app = new MourneApplication(); app->load_settings(); app->setup_routes(); @@ -95,6 +93,11 @@ int main(int argc, char **argv, char **envp) { } app->migrate(); + + if (Platform::get_singleton()->arg_parser.has_arg("-d")) { + printf("Adding data.\n"); + app->add_default_data(); + } } delete app;