Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed validation result type from std::unordered_map to std::map #180

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/domain/customermgmt/customermgmtcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CustomerManagementController::CustomerManagementController(
}

std::vector<entity::Customer> CustomerManagementController::list() {
LOG_DEBUG("Getting the list of products");
LOG_DEBUG("Getting the list of customers");
return mCachedList;
}

Expand All @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion core/domain/customermgmt/customermgmtcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CustomerManagementController : public CustomerManagementControlInterface {

CustomerMgmtDataPtr mDataProvider;
CustomerMgmtViewPtr mView;
std::vector<entity::Customer> mCachedList; // List of products
std::vector<entity::Customer> mCachedList; // List of customers
};

} // namespace customermgmt
Expand Down
12 changes: 6 additions & 6 deletions core/domain/employeemgmt/employeecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/domain/inventory/inventorycontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
4 changes: 2 additions & 2 deletions core/validator/validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define CORE_VALIDATOR_VALIDATOR_HPP_
#include <functional>
#include <string>
#include <unordered_map>
#include <map>
#include <utility>
#include <vector>

Expand All @@ -38,7 +38,7 @@ enum ValidationStatus {
};

// map [field that failed, error message to display]
typedef std::unordered_map<std::string, std::string> Errors;
typedef std::map<std::string, std::string> Errors;

class Validator {
public:
Expand Down