Skip to content

Commit

Permalink
Created customer entity (#176)
Browse files Browse the repository at this point in the history
* Created customer entity

Closes #158

- Added customer entity
- Implemented ID generator
- Added new table item struct
  • Loading branch information
gbenziv authored Dec 31, 2020
1 parent a933054 commit d078027
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/entity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ add_library (
# Entities
address.hpp
contactdetails.hpp
customer.hpp
customer.cpp
employee.hpp
employee.cpp
person.hpp
Expand Down
36 changes: 36 additions & 0 deletions core/entity/customer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**************************************************************************************************
* PSCORE *
* Copyright (C) 2020 Pointon Software *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
* Ben Ziv <[email protected]> *
* *
**************************************************************************************************/
#include "customer.hpp"
#include <string>

namespace entity {

Customer::Customer(const std::string& id,
const std::string& firstname,
const std::string& middlename,
const std::string& lastname,
const std::string& birthdate,
const std::string& gender)
: Person{firstname, middlename, lastname, birthdate, gender}, mID(id) {
// Empty for now
}

} // namespace entity
52 changes: 52 additions & 0 deletions core/entity/customer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************************************
* PSCORE *
* Copyright (C) 2020 Pointon Software *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
* Ben Ziv <[email protected]> *
* *
**************************************************************************************************/
#ifndef CORE_ENTITY_CUSTOMER_HPP_
#define CORE_ENTITY_CUSTOMER_HPP_

#include <string>
#include "person.hpp"

namespace entity {

// Fields
constexpr char FIELD_CUSID[] = "Customer.ID";

class Customer : public Person {
public:
Customer(const std::string& id,
const std::string& firstname,
const std::string& middlename,
const std::string& lastname,
const std::string& birthdate,
const std::string& gender);
Customer() = default;
~Customer() = default;

inline std::string ID() const {
return mID;
}

private:
std::string mID;
};

} // namespace entity
#endif // CORE_ENTITY_CUSTOMER_HPP_
3 changes: 0 additions & 3 deletions core/entity/employee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
* *
**************************************************************************************************/
#include "employee.hpp"
#include <chrono>
#include <ctime>
#include <random>
#include <string>

namespace entity {
Expand Down
2 changes: 1 addition & 1 deletion core/entity/employee.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Employee : public Person {
return mStatus;
}

protected:
private:
std::string mID;
std::string mPosition;
std::string mStatus;
Expand Down
15 changes: 15 additions & 0 deletions orchestra/migration/storage/stackdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ class StackDB {
std::string supplier_code;
};

struct CustomerTableItem {
std::string customerID;
std::string firstname;
std::string middlename;
std::string lastname;
std::string birthdate;
std::string gender;
};

inline std::vector<EmployeeTableItem>& SELECT_EMPLOYEES_TABLE() const {
return EMPLOYEES_TABLE;
}
Expand All @@ -123,6 +132,10 @@ class StackDB {
return PRODUCT_TABLE;
}

inline std::vector<CustomerTableItem>& SELECT_CUSTOMER_TABLE() const {
return CUSTOMER_TABLE;
}

private:
StackDB();
// employees storage
Expand All @@ -137,6 +150,8 @@ class StackDB {
static std::vector<PersonalIdTableItem> PERSONAL_ID_TABLE;
// product storage
static std::vector<ProductTableItem> PRODUCT_TABLE;
// customer storage
static std::vector<CustomerTableItem> CUSTOMER_TABLE;
void populateEmployees();
void populateProducts();
};
Expand Down
28 changes: 28 additions & 0 deletions utility/generator/chargenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
**************************************************************************************************/
#include "chargenerator.hpp"
#include <random>
#include <string>
#include <general.hpp>

Expand All @@ -30,5 +31,32 @@ std::string generateUID(const std::string& p1, const std::string& p2) {
return toUpper(p1.at(0) + p2.substr(0, 2) + std::to_string(randomNumber(100, 999)));
}

std::string generateCustomerID(const std::string& p1, const std::string& p2) {
// CM + first-letter-of-param1 + first-letter-of-param2 + eight-alphanumeric-chars
return toUpper("CM" + p1.at(0) + p2.at(0) + generateChars(8));
}

/**
* Code based-from StackOverflow by Galik
* Author profile: https://stackoverflow.com/users/3807729/galik
*
* Original question: https://stackoverflow.com/q/440133/3975468
* Answer: https://stackoverflow.com/a/24586587/3975468
*/
std::string generateChars(const uint8_t len) {
static auto& chrs = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
thread_local static std::mt19937 rg {std::random_device {}()};
thread_local static
std::uniform_int_distribution<std::string::size_type> pick(0, sizeof(chrs) - 2);

std::string temp;
temp.reserve(len);
for (int i = 0; i < len; ++i) {
temp += chrs[pick(rg)];
}
return temp;
}

} // namespace chargenerator
} // namespace utility
13 changes: 13 additions & 0 deletions utility/generator/chargenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ namespace chargenerator {
* result = JDOE123
*/
extern std::string generateUID(const std::string& p1, const std::string& p2);
/*!
* Generates the customer ID
* Format - CM[first-letter-of-param1][first-letter-of-param2][eight-alphanumeric-chars]
* e.g.
* p1 = John
* p2 = Doe
* result = CMJD12AB56CD
*/
extern std::string generateCustomerID(const std::string& p1, const std::string& p2);
/*!
* Generates random alphanumeric strings
*/
extern std::string generateChars(const uint8_t len);
} // namespace chargenerator
} // namespace utility
#endif // UTILITY_GENERATOR_CHARGENERATOR_HPP_

0 comments on commit d078027

Please sign in to comment.