Skip to content

Commit

Permalink
- Moved corecontroller instance to the base class
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenziv committed Jan 14, 2021
1 parent 183489a commit 4cddf0a
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion core/domain/customermgmt/customermgmtcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomerManagementController>(data, view);
Expand Down
4 changes: 2 additions & 2 deletions core/domain/customermgmt/interface/customermgmtiface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class CustomerManagementControlInterface {

typedef std::shared_ptr<CustomerManagementDataInterface> CustomerMgmtDataPtr;
typedef std::shared_ptr<CustomerManagementViewInterface> CustomerMgmtViewPtr;
typedef std::unique_ptr<CustomerManagementControlInterface> CustomerMgmtControllerPtr;
typedef std::unique_ptr<CustomerManagementControlInterface> CustomerMgmtCtrlPtr;

// Lib APIs
extern "C" CORE_API CustomerMgmtControllerPtr createCustomerMgmtModule
extern "C" CORE_API CustomerMgmtCtrlPtr createCustomerMgmtModule
(const CustomerMgmtDataPtr& data, const CustomerMgmtViewPtr& view);

} // namespace customermgmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace screen {
namespace backoffice {

class CustomerMgmtScreen : public screen::ScreenBase,
class CustomerMgmtScreen : public screen::ScreenBase<domain::customermgmt::CustomerMgmtCtrlPtr>,
public domain::customermgmt::CustomerManagementViewInterface {
public:
CustomerMgmtScreen();
Expand Down Expand Up @@ -78,7 +78,6 @@ class CustomerMgmtScreen : public screen::ScreenBase,
void fillCustomerInformation(entity::Customer* customer,
const std::vector<std::string>& requiredFields) const;

domain::customermgmt::CustomerMgmtControllerPtr mCoreController;
app::utility::TableHelper<entity::Customer> mTableHelper;
bool isShowingDetailsScreen;
static const std::vector<std::string> domainFields;
Expand Down
8 changes: 4 additions & 4 deletions orchestra/application/screen/backoffice/dashboardscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ DashboardScreen::DashboardScreen(const std::string& userID) : mUserID(userID) {
}

void DashboardScreen::show(std::promise<defines::display>* promise) {
mCoreDashboard = domain::dashboard::createDashboardModule(
mCoreController = domain::dashboard::createDashboardModule(
std::make_shared<dataprovider::dashboard::DashboardDataProvider>(),
std::make_shared<DashboardScreen>(mUserID));
mCoreDashboard->setCurrentUserId(mUserID);
mCurrentUser = mCoreDashboard->getCurrentUser();
mCoreController->setCurrentUserId(mUserID);
mCurrentUser = mCoreController->getCurrentUser();

if (!mCurrentUser.userID().empty()) {
// Valid user, proceed to menu selection
Expand Down Expand Up @@ -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<entity::Employee> userInfoScreen(emp);
userInfoScreen.showBasicInformation();
userInfoScreen.showContactDetails();
Expand Down
4 changes: 2 additions & 2 deletions orchestra/application/screen/backoffice/dashboardscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
namespace screen {
namespace backoffice {

class DashboardScreen : public ScreenBase, public domain::dashboard::DashboardViewInterface {
class DashboardScreen : public ScreenBase<domain::dashboard::DashboardControllerPtr>,
public domain::dashboard::DashboardViewInterface {
public:
explicit DashboardScreen(const std::string& userID);
~DashboardScreen() = default;
Expand Down Expand Up @@ -68,7 +69,6 @@ class DashboardScreen : public ScreenBase, public domain::dashboard::DashboardVi
void invalidOptionSelected() const;
Options getUserSelection() const;
bool action(Options option, std::promise<defines::display>* nextScreen) const;
domain::dashboard::DashboardControllerPtr mCoreDashboard;
};

} // namespace backoffice
Expand Down
16 changes: 8 additions & 8 deletions orchestra/application/screen/backoffice/empmgmtscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ EmployeeMgmtScreen::EmployeeMgmtScreen()
&entity::Employee::position }), isShowingDetailsScreen(false) {}

void EmployeeMgmtScreen::show(std::promise<defines::display>* promise) {
mCoreEmployeeMgmt = domain::empmgmt::createEmployeeMgmtModule(
mCoreController = domain::empmgmt::createEmployeeMgmtModule(
std::make_shared<dataprovider::empmgmt::EmployeeDataProvider>(),
std::make_shared<EmployeeMgmtScreen>());
// Get the employees from Core then cache the list
Expand All @@ -81,7 +81,7 @@ void EmployeeMgmtScreen::showLandingScreen() const {
}

void EmployeeMgmtScreen::queryEmployeesList() {
mTableHelper.setData(mCoreEmployeeMgmt->list());
mTableHelper.setData(mCoreController->list());
}

void EmployeeMgmtScreen::showEmployees() const {
Expand All @@ -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");
Expand All @@ -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<entity::User> userDataScreen(userdata);
userDataScreen.showBasicInformation();
}
Expand All @@ -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();
Expand Down Expand Up @@ -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});
}
}();

Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions orchestra/application/screen/backoffice/empmgmtscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace screen {
namespace backoffice {

class EmployeeMgmtScreen : public ScreenBase,
class EmployeeMgmtScreen : public ScreenBase<domain::empmgmt::EmpMgmtControllerPtr>,
public domain::empmgmt::EmployeeMgmtViewInterface {
public:
EmployeeMgmtScreen();
Expand Down Expand Up @@ -83,7 +83,6 @@ class EmployeeMgmtScreen : public ScreenBase,
void fillEmployeeInformation(entity::Employee* employee,
const std::vector<std::string>& requiredFields = {}) const;

domain::empmgmt::EmpMgmtControllerPtr mCoreEmployeeMgmt;
app::utility::TableHelper<entity::Employee> mTableHelper;
bool isShowingDetailsScreen;
static const std::vector<std::string> employeeDomainFields;
Expand Down
10 changes: 5 additions & 5 deletions orchestra/application/screen/backoffice/inventoryscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ InventoryScreen::InventoryScreen() : mTableHelper({"Product", "Category", "Stock
&entity::Product::sellPrice }), isShowingDetailsScreen(false) {}

void InventoryScreen::show(std::promise<defines::display>* promise) {
mInventoryController = domain::inventory::createInventoryModule(
mCoreController = domain::inventory::createInventoryModule(
std::make_shared<dataprovider::inventory::InventoryDataProvider>(),
std::make_shared<InventoryScreen>());
// Get the products from Core then cache the list
Expand All @@ -75,7 +75,7 @@ void InventoryScreen::showLandingScreen() const {
}

void InventoryScreen::queryProductsList() {
mTableHelper.setData(mInventoryController->list());
mTableHelper.setData(mCoreController->list());
}

void InventoryScreen::showProducts() const {
Expand All @@ -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();
Expand Down Expand Up @@ -150,7 +150,7 @@ void InventoryScreen::createProduct() {
requiredFields.clear();

std::map<std::string, std::string> 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));
Expand All @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions orchestra/application/screen/backoffice/inventoryscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace screen {
namespace backoffice {

class InventoryScreen : public screen::ScreenBase,
class InventoryScreen : public screen::ScreenBase<domain::inventory::InventoryControllerPtr>,
public domain::inventory::InventoryViewInterface {
public:
InventoryScreen();
Expand Down Expand Up @@ -79,7 +79,6 @@ class InventoryScreen : public screen::ScreenBase,
void fillProductInformation(entity::Product* product,
const std::vector<std::string>& requiredFields) const;

domain::inventory::InventoryControllerPtr mInventoryController;
app::utility::TableHelper<entity::Product> mTableHelper;
bool isShowingDetailsScreen;
static const std::vector<std::string> productDomainFields;
Expand Down
9 changes: 3 additions & 6 deletions orchestra/application/screen/login/loginscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <memory>
// view
#include <screencommon.hpp>
// core
#include <domain/userlogin/interface/loginiface.hpp>
// data
#include <logindata.hpp>

Expand Down Expand Up @@ -56,11 +54,10 @@ void LoginScreen::show(std::promise<defines::display>* 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<dataprovider::login::LoginDataProvider>(),
std::make_shared<LoginScreen>(*this));
return auth->authenticate(id, pin);
std::make_shared<LoginScreen>());
return mCoreController->authenticate(id, pin);
}

std::string LoginScreen::getUserID() const {
Expand Down
5 changes: 4 additions & 1 deletion orchestra/application/screen/login/loginscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
#define ORCHESTRA_APPLICATION_SCREEN_LOGIN_LOGINSCREEN_HPP_
#include <string>
#include <future>
// core
#include <domain/userlogin/interface/loginiface.hpp>
#include <domain/userlogin/interface/loginviewif.hpp>
#include <screenbase.hpp>

namespace screen {
namespace login {

class LoginScreen : public screen::ScreenBase, public domain::login::LoginViewIface {
class LoginScreen : public screen::ScreenBase<domain::login::LoginControllerPtr>,
public domain::login::LoginViewIface {
public:
LoginScreen() = default;
~LoginScreen() = default;
Expand Down
4 changes: 4 additions & 0 deletions orchestra/application/screen/screenbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

namespace screen {

template <class ControllerType>
class ScreenBase {
public:
ScreenBase() = default;
virtual ~ScreenBase() = default;

virtual void show(std::promise<defines::display>* promise) = 0;

protected:
ControllerType mCoreController;
};

} // namespace screen
Expand Down

0 comments on commit 4cddf0a

Please sign in to comment.