From 22030e754136b2b4fba78e60566cbf40973ca5fb Mon Sep 17 00:00:00 2001 From: benzgar Date: Wed, 30 Dec 2020 23:13:05 -0500 Subject: [PATCH] Changed validation result type from std::unordered_map to std::map Closes #179 - Changed type - Changed map insert to merge --- core/domain/customermgmt/customermgmtcontroller.cpp | 4 ++-- core/domain/customermgmt/customermgmtcontroller.hpp | 2 +- core/domain/employeemgmt/employeecontroller.cpp | 12 ++++++------ core/domain/inventory/inventorycontroller.cpp | 2 +- core/validator/validator.hpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/domain/customermgmt/customermgmtcontroller.cpp b/core/domain/customermgmt/customermgmtcontroller.cpp index c9fa6a90..a406dff5 100644 --- a/core/domain/customermgmt/customermgmtcontroller.cpp +++ b/core/domain/customermgmt/customermgmtcontroller.cpp @@ -37,7 +37,7 @@ CustomerManagementController::CustomerManagementController( } std::vector CustomerManagementController::list() { - LOG_DEBUG("Getting the list of products"); + LOG_DEBUG("Getting the list of customers"); return mCachedList; } @@ -59,7 +59,7 @@ CUSTOMERMGMTAPISTATUS CustomerManagementController::save(const entity::Customer& { LOG_DEBUG("Validating fields"); entity::validator::PersonValidator validator(customer); - validationResult->insert(validator.result().begin(), validator.result().end()); + validationResult->merge(validator.result()); } if (!validationResult->empty()) { LOG_WARN("Entity contains invalid data. Returning validation results."); diff --git a/core/domain/customermgmt/customermgmtcontroller.hpp b/core/domain/customermgmt/customermgmtcontroller.hpp index 41d414de..8a403236 100644 --- a/core/domain/customermgmt/customermgmtcontroller.hpp +++ b/core/domain/customermgmt/customermgmtcontroller.hpp @@ -53,7 +53,7 @@ class CustomerManagementController : public CustomerManagementControlInterface { CustomerMgmtDataPtr mDataProvider; CustomerMgmtViewPtr mView; - std::vector mCachedList; // List of products + std::vector mCachedList; // List of customers }; } // namespace customermgmt diff --git a/core/domain/employeemgmt/employeecontroller.cpp b/core/domain/employeemgmt/employeecontroller.cpp index 08c99882..523a6778 100644 --- a/core/domain/employeemgmt/employeecontroller.cpp +++ b/core/domain/employeemgmt/employeecontroller.cpp @@ -148,7 +148,7 @@ EMPLMGMTSTATUS EmployeeMgmtController::save(const SaveEmployeeData& employeeData entity::validator::UserValidator validator( entity::User("Proxy", "Proxy", employeeData.PIN, "2020/10/10 10:10:10", "Proxy")); - employeeData.validationResult->insert(validator.result().begin(), validator.result().end()); + employeeData.validationResult->merge(validator.result()); } if (!employeeData.validationResult->empty()) { LOG_WARN("Entity contains invalid data. Returning validation results."); @@ -208,28 +208,28 @@ ValidationErrors EmployeeMgmtController::validateDetails(const entity::Employee& // validate key employee data { entity::validator::EmployeeValidator validator(employee); - validationErrors.insert(validator.result().begin(), validator.result().end()); + validationErrors.merge(validator.result()); } // validate basic information { entity::validator::PersonValidator validator(employee); - validationErrors.insert(validator.result().begin(), validator.result().end()); + validationErrors.merge(validator.result()); } // validate address { entity::validator::AddressValidator validator(employee.address()); - validationErrors.insert(validator.result().begin(), validator.result().end()); + validationErrors.merge(validator.result()); } // validate contact information { entity::validator::ContactDetailsValidator validator(employee.contactDetails()); - validationErrors.insert(validator.result().begin(), validator.result().end()); + validationErrors.merge(validator.result()); } // validate ID { for (const entity::PersonalId& personalId : employee.personalIds()) { entity::validator::PersonalIDValidator validator(personalId); - validationErrors.insert(validator.result().begin(), validator.result().end()); + validationErrors.merge(validator.result()); } } return validationErrors; diff --git a/core/domain/inventory/inventorycontroller.cpp b/core/domain/inventory/inventorycontroller.cpp index aba9aa4e..d5336dda 100644 --- a/core/domain/inventory/inventorycontroller.cpp +++ b/core/domain/inventory/inventorycontroller.cpp @@ -73,7 +73,7 @@ INVENTORYAPISTATUS InventoryController::save(const entity::Product& product, { LOG_DEBUG("Validating fields"); entity::validator::ProductValidator validator(product); - validationResult->insert(validator.result().begin(), validator.result().end()); + validationResult->merge(validator.result()); } if (!validationResult->empty()) { LOG_WARN("Entity contains invalid data. Returning validation results."); diff --git a/core/validator/validator.hpp b/core/validator/validator.hpp index ed5e23dd..23b4a2cd 100644 --- a/core/validator/validator.hpp +++ b/core/validator/validator.hpp @@ -22,7 +22,7 @@ #define CORE_VALIDATOR_VALIDATOR_HPP_ #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ enum ValidationStatus { }; // map [field that failed, error message to display] -typedef std::unordered_map Errors; +typedef std::map Errors; class Validator { public: