From 4cddf0af17641ecfdbf60bee8772c75b5ba58364 Mon Sep 17 00:00:00 2001 From: benzgar Date: Wed, 13 Jan 2021 19:37:35 -0500 Subject: [PATCH] - Moved corecontroller instance to the base class --- .../customermgmt/customermgmtcontroller.cpp | 2 +- .../customermgmt/interface/customermgmtiface.hpp | 4 ++-- .../screen/backoffice/customermgmtscreen.hpp | 3 +-- .../screen/backoffice/dashboardscreen.cpp | 8 ++++---- .../screen/backoffice/dashboardscreen.hpp | 4 ++-- .../screen/backoffice/empmgmtscreen.cpp | 16 ++++++++-------- .../screen/backoffice/empmgmtscreen.hpp | 3 +-- .../screen/backoffice/inventoryscreen.cpp | 10 +++++----- .../screen/backoffice/inventoryscreen.hpp | 3 +-- .../application/screen/login/loginscreen.cpp | 9 +++------ .../application/screen/login/loginscreen.hpp | 5 ++++- orchestra/application/screen/screenbase.hpp | 4 ++++ 12 files changed, 36 insertions(+), 35 deletions(-) diff --git a/core/domain/customermgmt/customermgmtcontroller.cpp b/core/domain/customermgmt/customermgmtcontroller.cpp index 55decb5d..3588061d 100644 --- a/core/domain/customermgmt/customermgmtcontroller.cpp +++ b/core/domain/customermgmt/customermgmtcontroller.cpp @@ -164,7 +164,7 @@ CUSTOMERMGMTAPISTATUS CustomerManagementController::remove(const std::string& id return CUSTOMERMGMTAPISTATUS::SUCCESS; } -CustomerMgmtControllerPtr createCustomerMgmtModule( +CustomerMgmtCtrlPtr createCustomerMgmtModule( const CustomerMgmtDataPtr& data, const CustomerMgmtViewPtr& view) { return std::make_unique(data, view); diff --git a/core/domain/customermgmt/interface/customermgmtiface.hpp b/core/domain/customermgmt/interface/customermgmtiface.hpp index 7976cd92..1f89af0d 100644 --- a/core/domain/customermgmt/interface/customermgmtiface.hpp +++ b/core/domain/customermgmt/interface/customermgmtiface.hpp @@ -70,10 +70,10 @@ class CustomerManagementControlInterface { typedef std::shared_ptr CustomerMgmtDataPtr; typedef std::shared_ptr CustomerMgmtViewPtr; -typedef std::unique_ptr CustomerMgmtControllerPtr; +typedef std::unique_ptr CustomerMgmtCtrlPtr; // Lib APIs -extern "C" CORE_API CustomerMgmtControllerPtr createCustomerMgmtModule +extern "C" CORE_API CustomerMgmtCtrlPtr createCustomerMgmtModule (const CustomerMgmtDataPtr& data, const CustomerMgmtViewPtr& view); } // namespace customermgmt diff --git a/orchestra/application/screen/backoffice/customermgmtscreen.hpp b/orchestra/application/screen/backoffice/customermgmtscreen.hpp index 3cec9268..537c49b9 100644 --- a/orchestra/application/screen/backoffice/customermgmtscreen.hpp +++ b/orchestra/application/screen/backoffice/customermgmtscreen.hpp @@ -35,7 +35,7 @@ namespace screen { namespace backoffice { -class CustomerMgmtScreen : public screen::ScreenBase, +class CustomerMgmtScreen : public screen::ScreenBase, public domain::customermgmt::CustomerManagementViewInterface { public: CustomerMgmtScreen(); @@ -78,7 +78,6 @@ class CustomerMgmtScreen : public screen::ScreenBase, void fillCustomerInformation(entity::Customer* customer, const std::vector& requiredFields) const; - domain::customermgmt::CustomerMgmtControllerPtr mCoreController; app::utility::TableHelper mTableHelper; bool isShowingDetailsScreen; static const std::vector domainFields; diff --git a/orchestra/application/screen/backoffice/dashboardscreen.cpp b/orchestra/application/screen/backoffice/dashboardscreen.cpp index 00dc4b14..8a06d680 100644 --- a/orchestra/application/screen/backoffice/dashboardscreen.cpp +++ b/orchestra/application/screen/backoffice/dashboardscreen.cpp @@ -35,11 +35,11 @@ DashboardScreen::DashboardScreen(const std::string& userID) : mUserID(userID) { } void DashboardScreen::show(std::promise* promise) { - mCoreDashboard = domain::dashboard::createDashboardModule( + mCoreController = domain::dashboard::createDashboardModule( std::make_shared(), std::make_shared(mUserID)); - mCoreDashboard->setCurrentUserId(mUserID); - mCurrentUser = mCoreDashboard->getCurrentUser(); + mCoreController->setCurrentUserId(mUserID); + mCurrentUser = mCoreController->getCurrentUser(); if (!mCurrentUser.userID().empty()) { // Valid user, proceed to menu selection @@ -77,7 +77,7 @@ void DashboardScreen::showOptions() const { void DashboardScreen::showUserInformation() const { SCREENCOMMON().showTopBanner("User Information"); if (!mCurrentUser.employeeID().empty()) { - entity::Employee emp = mCoreDashboard->getUserDetails(mCurrentUser); + entity::Employee emp = mCoreController->getUserDetails(mCurrentUser); screen::InformationScreen userInfoScreen(emp); userInfoScreen.showBasicInformation(); userInfoScreen.showContactDetails(); diff --git a/orchestra/application/screen/backoffice/dashboardscreen.hpp b/orchestra/application/screen/backoffice/dashboardscreen.hpp index 7a61a6f7..6e6ce439 100644 --- a/orchestra/application/screen/backoffice/dashboardscreen.hpp +++ b/orchestra/application/screen/backoffice/dashboardscreen.hpp @@ -31,7 +31,8 @@ namespace screen { namespace backoffice { -class DashboardScreen : public ScreenBase, public domain::dashboard::DashboardViewInterface { +class DashboardScreen : public ScreenBase, + public domain::dashboard::DashboardViewInterface { public: explicit DashboardScreen(const std::string& userID); ~DashboardScreen() = default; @@ -68,7 +69,6 @@ class DashboardScreen : public ScreenBase, public domain::dashboard::DashboardVi void invalidOptionSelected() const; Options getUserSelection() const; bool action(Options option, std::promise* nextScreen) const; - domain::dashboard::DashboardControllerPtr mCoreDashboard; }; } // namespace backoffice diff --git a/orchestra/application/screen/backoffice/empmgmtscreen.cpp b/orchestra/application/screen/backoffice/empmgmtscreen.cpp index d240bd91..af442cbb 100644 --- a/orchestra/application/screen/backoffice/empmgmtscreen.cpp +++ b/orchestra/application/screen/backoffice/empmgmtscreen.cpp @@ -60,7 +60,7 @@ EmployeeMgmtScreen::EmployeeMgmtScreen() &entity::Employee::position }), isShowingDetailsScreen(false) {} void EmployeeMgmtScreen::show(std::promise* promise) { - mCoreEmployeeMgmt = domain::empmgmt::createEmployeeMgmtModule( + mCoreController = domain::empmgmt::createEmployeeMgmtModule( std::make_shared(), std::make_shared()); // Get the employees from Core then cache the list @@ -81,7 +81,7 @@ void EmployeeMgmtScreen::showLandingScreen() const { } void EmployeeMgmtScreen::queryEmployeesList() { - mTableHelper.setData(mCoreEmployeeMgmt->list()); + mTableHelper.setData(mCoreController->list()); } void EmployeeMgmtScreen::showEmployees() const { @@ -102,7 +102,7 @@ void EmployeeMgmtScreen::showEmployeeInformation(bool showIndex) const { * Note: mSelectedEmployeeIndex is a 1-based index but vector is zero-based (hence minus 1) */ const std::string& employeeID = mTableHelper.getSelectedData().ID(); - const entity::Employee& selectedEmployee = mCoreEmployeeMgmt->getEmployee(employeeID); + const entity::Employee& selectedEmployee = mCoreController->getEmployee(employeeID); if (!selectedEmployee.ID().empty()) { // Valid employee, show the information screen! SCREENCOMMON().showTopBanner("Employee Information"); @@ -119,7 +119,7 @@ void EmployeeMgmtScreen::showEmployeeInformation(bool showIndex) const { // Show user data if (selectedEmployee.isSystemUser()) { - const entity::User& userdata = mCoreEmployeeMgmt->getUser(employeeID); + const entity::User& userdata = mCoreController->getUser(employeeID); screen::InformationScreen userDataScreen(userdata); userDataScreen.showBasicInformation(); } @@ -130,7 +130,7 @@ void EmployeeMgmtScreen::showEmployeeInformation(bool showIndex) const { } void EmployeeMgmtScreen::removeEmployee() { - if (mCoreEmployeeMgmt->remove(mTableHelper.getSelectedData().ID()) + if (mCoreController->remove(mTableHelper.getSelectedData().ID()) == domain::empmgmt::EMPLMGMTSTATUS::SUCCESS) { // Remove the user form mTableHelper.deleteSelectedData(); @@ -242,13 +242,13 @@ void EmployeeMgmtScreen::createEmployee() { if (!isSystemUser) { // non-user, add the employee - return mCoreEmployeeMgmt->save({newEmployee, "", &validationResult}); + return mCoreController->save({newEmployee, "", &validationResult}); } else { // Employee is a system user newEmployee.setIsSystemUser(true); // User PIN const std::string pin = SCREENCOMMON().getInput("PIN"); - return mCoreEmployeeMgmt->save({newEmployee, pin, &validationResult}); + return mCoreController->save({newEmployee, pin, &validationResult}); } }(); @@ -287,7 +287,7 @@ void EmployeeMgmtScreen::updateEmployee() { fillEmployeeInformation(&updateEmployee, requiredFields); // Reset validation results validationResult.clear(); - if (mCoreEmployeeMgmt->save({updateEmployee, "", &validationResult}) != + if (mCoreController->save({updateEmployee, "", &validationResult}) != domain::empmgmt::EMPLMGMTSTATUS::SUCCESS) { requiredFields = app::util::extractMapKeys(validationResult); SCREENCOMMON().printErrorList(app::util::extractMapValues(validationResult)); diff --git a/orchestra/application/screen/backoffice/empmgmtscreen.hpp b/orchestra/application/screen/backoffice/empmgmtscreen.hpp index 5455450e..41c7e49f 100644 --- a/orchestra/application/screen/backoffice/empmgmtscreen.hpp +++ b/orchestra/application/screen/backoffice/empmgmtscreen.hpp @@ -35,7 +35,7 @@ namespace screen { namespace backoffice { -class EmployeeMgmtScreen : public ScreenBase, +class EmployeeMgmtScreen : public ScreenBase, public domain::empmgmt::EmployeeMgmtViewInterface { public: EmployeeMgmtScreen(); @@ -83,7 +83,6 @@ class EmployeeMgmtScreen : public ScreenBase, void fillEmployeeInformation(entity::Employee* employee, const std::vector& requiredFields = {}) const; - domain::empmgmt::EmpMgmtControllerPtr mCoreEmployeeMgmt; app::utility::TableHelper mTableHelper; bool isShowingDetailsScreen; static const std::vector employeeDomainFields; diff --git a/orchestra/application/screen/backoffice/inventoryscreen.cpp b/orchestra/application/screen/backoffice/inventoryscreen.cpp index 397a5570..65d16115 100644 --- a/orchestra/application/screen/backoffice/inventoryscreen.cpp +++ b/orchestra/application/screen/backoffice/inventoryscreen.cpp @@ -54,7 +54,7 @@ InventoryScreen::InventoryScreen() : mTableHelper({"Product", "Category", "Stock &entity::Product::sellPrice }), isShowingDetailsScreen(false) {} void InventoryScreen::show(std::promise* promise) { - mInventoryController = domain::inventory::createInventoryModule( + mCoreController = domain::inventory::createInventoryModule( std::make_shared(), std::make_shared()); // Get the products from Core then cache the list @@ -75,7 +75,7 @@ void InventoryScreen::showLandingScreen() const { } void InventoryScreen::queryProductsList() { - mTableHelper.setData(mInventoryController->list()); + mTableHelper.setData(mCoreController->list()); } void InventoryScreen::showProducts() const { @@ -100,7 +100,7 @@ void InventoryScreen::showProductDetails(bool showIndex) const { } void InventoryScreen::removeProduct() { - if (mInventoryController->remove(mTableHelper.getSelectedData().barcode()) + if (mCoreController->remove(mTableHelper.getSelectedData().barcode()) == domain::inventory::INVENTORYAPISTATUS::SUCCESS) { // Remove the product from our table mTableHelper.deleteSelectedData(); @@ -150,7 +150,7 @@ void InventoryScreen::createProduct() { requiredFields.clear(); std::map validationResult; - if (mInventoryController->save(newProduct, &validationResult) + if (mCoreController->save(newProduct, &validationResult) != domain::inventory::INVENTORYAPISTATUS::SUCCESS) { requiredFields = app::util::extractMapKeys(validationResult); SCREENCOMMON().printErrorList(app::util::extractMapValues(validationResult)); @@ -175,7 +175,7 @@ void InventoryScreen::updateProduct() { fillProductInformation(&product, requiredFields); // Reset validation results validationResult.clear(); - if (mInventoryController->save(product, &validationResult) + if (mCoreController->save(product, &validationResult) != domain::inventory::INVENTORYAPISTATUS::SUCCESS) { requiredFields = app::util::extractMapKeys(validationResult); SCREENCOMMON().printErrorList(app::util::extractMapValues(validationResult)); diff --git a/orchestra/application/screen/backoffice/inventoryscreen.hpp b/orchestra/application/screen/backoffice/inventoryscreen.hpp index 5a9108e4..18d93eec 100644 --- a/orchestra/application/screen/backoffice/inventoryscreen.hpp +++ b/orchestra/application/screen/backoffice/inventoryscreen.hpp @@ -35,7 +35,7 @@ namespace screen { namespace backoffice { -class InventoryScreen : public screen::ScreenBase, +class InventoryScreen : public screen::ScreenBase, public domain::inventory::InventoryViewInterface { public: InventoryScreen(); @@ -79,7 +79,6 @@ class InventoryScreen : public screen::ScreenBase, void fillProductInformation(entity::Product* product, const std::vector& requiredFields) const; - domain::inventory::InventoryControllerPtr mInventoryController; app::utility::TableHelper mTableHelper; bool isShowingDetailsScreen; static const std::vector productDomainFields; diff --git a/orchestra/application/screen/login/loginscreen.cpp b/orchestra/application/screen/login/loginscreen.cpp index 2c1ea1fd..a218ca9b 100644 --- a/orchestra/application/screen/login/loginscreen.cpp +++ b/orchestra/application/screen/login/loginscreen.cpp @@ -23,8 +23,6 @@ #include // view #include -// core -#include // data #include @@ -56,11 +54,10 @@ void LoginScreen::show(std::promise* promise) { } bool LoginScreen::onLogin(const std::string& id, const std::string& pin) { - domain::login::LoginControllerPtr auth - = domain::login::createLoginModule( + mCoreController = domain::login::createLoginModule( std::make_shared(), - std::make_shared(*this)); - return auth->authenticate(id, pin); + std::make_shared()); + return mCoreController->authenticate(id, pin); } std::string LoginScreen::getUserID() const { diff --git a/orchestra/application/screen/login/loginscreen.hpp b/orchestra/application/screen/login/loginscreen.hpp index 0278a60e..db220e9a 100644 --- a/orchestra/application/screen/login/loginscreen.hpp +++ b/orchestra/application/screen/login/loginscreen.hpp @@ -22,13 +22,16 @@ #define ORCHESTRA_APPLICATION_SCREEN_LOGIN_LOGINSCREEN_HPP_ #include #include +// core +#include #include #include namespace screen { namespace login { -class LoginScreen : public screen::ScreenBase, public domain::login::LoginViewIface { +class LoginScreen : public screen::ScreenBase, + public domain::login::LoginViewIface { public: LoginScreen() = default; ~LoginScreen() = default; diff --git a/orchestra/application/screen/screenbase.hpp b/orchestra/application/screen/screenbase.hpp index 7be6fa8d..c744a563 100644 --- a/orchestra/application/screen/screenbase.hpp +++ b/orchestra/application/screen/screenbase.hpp @@ -25,12 +25,16 @@ namespace screen { +template class ScreenBase { public: ScreenBase() = default; virtual ~ScreenBase() = default; virtual void show(std::promise* promise) = 0; + + protected: + ControllerType mCoreController; }; } // namespace screen