Added employee persistence, serialization, and file loading support

<SRS>SRS02 : Employee Management </SRS>

<Changes>
 - Implemented serialization and deserialization for Employee and GeneralEmployee models
 - Added FileManager integration to load employees from CSV files
 - Introduced ApplicationConfig entries for employee file paths
 - Updated Employee ID handling (getEmployeeId → getId) across project
 - Modified FileIO to auto-create file if not found instead of throwing exception
 - Added constructors for all employee types to support deserialization
 - Implemented loadEmployees in service and loadStates in controller
 - Ensured default admin creation if none exists during load
 - Added StringHelper utility for extracting numeric IDs
 - Extended Enums with string conversion and parsing utilities
 - Added initial CSV files for Employee and GeneralEmployee data
 - Improved login error message formatting and minor cleanup
 - Setup gitignore to not track csv files
</Changes>
This commit is contained in:
2026-04-10 13:17:50 +05:30
parent d29e38ef75
commit 451ed4fec2
26 changed files with 549 additions and 23 deletions
+3
View File
@@ -426,3 +426,6 @@ FodyWeavers.xsd
*.msix *.msix
*.msm *.msm
*.msp *.msp
# CSV Files
*.csv
@@ -5,14 +5,14 @@ std::vector<std::string> FileIO::readAllLines(const std::string& path)
{ {
std::ifstream file(path); std::ifstream file(path);
if (!file.is_open()) if (!file.is_open())
throw std::runtime_error("Failed to open file " + path); {
std::ofstream newFile(path);
std::vector<std::string> lines; newFile.close();
file.open(path);
} std::vector<std::string> lines;
std::string line; std::string line;
while (std::getline(file, line)) while (std::getline(file, line))
lines.push_back(line); lines.push_back(line);
return lines; return lines;
} }
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "FileIO.h" #include "FileIO.h"
template <typename T> using objects = std::map<int, std::shared_ptr<T>>; template <typename T> using objects = std::map<std::string, std::shared_ptr<T>>;
template <typename T> template <typename T>
class FileManager class FileManager
@@ -1,4 +1,5 @@
#include "UserInterface.h" #include "UserInterface.h"
#include "FileManager.h"
int main() int main()
{ {
UserInterface userInterFace; UserInterface userInterFace;
@@ -177,6 +177,7 @@
<ClCompile Include="utilities\Enums.cpp" /> <ClCompile Include="utilities\Enums.cpp" />
<ClCompile Include="utilities\InputHelper.cpp" /> <ClCompile Include="utilities\InputHelper.cpp" />
<ClCompile Include="utilities\OutputHelper.cpp" /> <ClCompile Include="utilities\OutputHelper.cpp" />
<ClCompile Include="utilities\StringHelper.cpp" />
<ClCompile Include="utilities\Timestamp.cpp" /> <ClCompile Include="utilities\Timestamp.cpp" />
<ClCompile Include="utilities\Validator.cpp" /> <ClCompile Include="utilities\Validator.cpp" />
<ClCompile Include="views\AdminMenu.cpp" /> <ClCompile Include="views\AdminMenu.cpp" />
@@ -229,6 +230,7 @@
<ClInclude Include="utilities\Enums.h" /> <ClInclude Include="utilities\Enums.h" />
<ClInclude Include="utilities\InputHelper.h" /> <ClInclude Include="utilities\InputHelper.h" />
<ClInclude Include="utilities\OutputHelper.h" /> <ClInclude Include="utilities\OutputHelper.h" />
<ClInclude Include="utilities\StringHelper.h" />
<ClInclude Include="utilities\Timestamp.h" /> <ClInclude Include="utilities\Timestamp.h" />
<ClInclude Include="utilities\Validator.h" /> <ClInclude Include="utilities\Validator.h" />
<ClInclude Include="views\AdminMenu.h" /> <ClInclude Include="views\AdminMenu.h" />
@@ -198,6 +198,9 @@
<ClCompile Include="utilities\AuthorizationHelper.cpp"> <ClCompile Include="utilities\AuthorizationHelper.cpp">
<Filter>Services</Filter> <Filter>Services</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="utilities\StringHelper.cpp">
<Filter>Utilities</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="services\AuthenticationManagementService.h"> <ClInclude Include="services\AuthenticationManagementService.h">
@@ -350,6 +353,9 @@
<ClInclude Include="utilities\AuthorizationHelper.h"> <ClInclude Include="utilities\AuthorizationHelper.h">
<Filter>Services</Filter> <Filter>Services</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="utilities\StringHelper.h">
<Filter>Utilities</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="models\Employee.h"> <ClInclude Include="models\Employee.h">
@@ -46,3 +46,8 @@ Employees ZenvyController::getEmployees()
{ {
return m_employeeManagementService->getEmployees(); return m_employeeManagementService->getEmployees();
} }
void ZenvyController::loadStates()
{
m_employeeManagementService->loadEmployees();
}
@@ -53,4 +53,7 @@ public:
//Payslip management //Payslip management
void updateSalary(const std::string&, double, double, double, double, double); void updateSalary(const std::string&, double, double, double, double, double);
//File Management
void loadStates();
}; };
+18 -1
View File
@@ -10,6 +10,23 @@ public:
const std::string& phone, const std::string& phone,
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll std::shared_ptr<Payroll> payroll
) :Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll) {}; ) :Employee(name, phone, email, Enums::EmployeeType::ADMIN, payroll) {};
Admin(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::ADMIN,
accountStatus) {}
~Admin() = default; ~Admin() = default;
}; };
+134 -1
View File
@@ -1,8 +1,45 @@
#include <sstream>
#include "Employee.h" #include "Employee.h"
#include "Factory.h"
#include "StringHelper.h"
#include "Admin.h"
#include "HRManager.h"
#include "ITExecutive.h"
#include "TalentExecutive.h"
#include "TeamExecutive.h"
#include "FinanceExecutive.h"
#include "GeneralEmployee.h"
int Employee::m_uid = 0; int Employee::m_uid = 0;
const std::string& Employee::getEmployeeId() const Employee::Employee(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::EmployeeType employeeType,
Enums::AccountStatus accountStatus)
: m_id(id),
m_password(password),
m_name(name),
m_phone(phone),
m_email(email),
m_accountStatus(accountStatus),
m_teamStatus(teamStatus),
m_teamId(teamId),
m_employeeType(employeeType),
m_payroll()
{
int idNumber = util::extractNumber(m_id);
if (idNumber > m_uid)
{
m_uid = idNumber;
}
}
const std::string& Employee::getId() const
{ {
return m_id; return m_id;
} }
@@ -130,3 +167,99 @@ Enums::EmployeeType Employee::getEmployeeType() const
{ {
return m_employeeType; return m_employeeType;
} }
std::string Employee::serialize() const
{
std::ostringstream serializedEmployee;
serializedEmployee << m_id << ','
<< m_email << ','
<< m_name << ','
<< m_phone << ','
<< m_password << ','
<< m_teamId << ','
<< Enums::getTeamStatusString(m_teamStatus) << ','
<< Enums::getAccountStatusString(m_accountStatus) << ','
<< Enums::getEmployeeTypeString(m_employeeType);
return serializedEmployee.str();
}
std::shared_ptr<Employee> Employee::deserialize(const std::string& record)
{
std::string id, name, phone, password, email;
std::string teamId, teamStatusString, accountStatusString, employeeTypeString;
std::istringstream serializedEmployee(record);
getline(serializedEmployee, id, ',');
getline(serializedEmployee, email, ',');
getline(serializedEmployee, name, ',');
getline(serializedEmployee, phone, ',');
getline(serializedEmployee, password, ',');
getline(serializedEmployee, teamId, ',');
getline(serializedEmployee, teamStatusString, ',');
getline(serializedEmployee, accountStatusString, ',');
getline(serializedEmployee, employeeTypeString, ',');
Enums::TeamStatus teamStatus = Enums::getTeamStatus(teamStatusString);
Enums::AccountStatus accountStatus = Enums::getAccountStatus(accountStatusString);
Enums::EmployeeType employeeType = Enums::getEmployeeType(employeeTypeString);
switch (employeeType)
{
case Enums::EmployeeType::IT:
return Factory::getObject<ITExecutive>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
accountStatus
);
case Enums::EmployeeType::FINANCE:
return Factory::getObject<FinanceExecutive>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
accountStatus
);
case Enums::EmployeeType::HR:
return Factory::getObject<HRManager>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
accountStatus
);
case Enums::EmployeeType::TEAM:
return Factory::getObject<TeamExecutive>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
accountStatus
);
case Enums::EmployeeType::ADMIN:
return Factory::getObject<Admin>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
accountStatus
);
case Enums::EmployeeType::GENERAL:
throw std::runtime_error("Cannot deserialize GeneralEmployee!");
default:
return nullptr;
}
}
+33 -4
View File
@@ -14,7 +14,7 @@ using leaveMap = std::map<std::string, std::shared_ptr<Leave>>;
class Employee class Employee
{ {
private: protected:
static int m_uid; static int m_uid;
std::string m_id; std::string m_id;
std::string m_password; std::string m_password;
@@ -30,14 +30,41 @@ private:
leaveMap m_leaves; leaveMap m_leaves;
Enums::EmployeeType m_employeeType; Enums::EmployeeType m_employeeType;
public: public:
Employee() : m_id("EMP" + std::to_string(++m_uid)), m_password(Config::Authentication::DEFAULT_PASSWORD), m_name(""), m_phone(""), m_email(""), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(""), m_employeeType(Enums::EmployeeType::GENERAL) {} Employee()
: m_id("EMP" + std::to_string(++m_uid)),
m_password(Config::Authentication::DEFAULT_PASSWORD),
m_name(""),
m_phone(""),
m_email(""),
m_accountStatus(Enums::AccountStatus::ACTIVE),
m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM),
m_teamId(""),
m_employeeType(Enums::EmployeeType::GENERAL) {}
Employee(const std::string& name, Employee(const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& email, const std::string& email,
Enums::EmployeeType employeeType, Enums::EmployeeType employeeType,
std::shared_ptr<Payroll> payroll) std::shared_ptr<Payroll> payroll)
: m_id("EMP" + std::to_string(++m_uid)), m_password(Config::Authentication::DEFAULT_PASSWORD), m_name(name), m_phone(phone), m_email(email), m_accountStatus(Enums::AccountStatus::ACTIVE), m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM), m_teamId(""), m_employeeType(employeeType), m_payroll(payroll) { } : m_id("EMP" + std::to_string(++m_uid)),
const std::string& getEmployeeId() const; m_password(Config::Authentication::DEFAULT_PASSWORD),
m_name(name),
m_phone(phone),
m_email(email),
m_accountStatus(Enums::AccountStatus::ACTIVE),
m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM),
m_teamId(""),
m_employeeType(employeeType),
m_payroll(payroll) {}
Employee(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::EmployeeType employeeType,
Enums::AccountStatus accountStatus);
const std::string& getId() const;
const std::string& getEmployeePassword() const; const std::string& getEmployeePassword() const;
const std::string& getEmployeeName() const; const std::string& getEmployeeName() const;
const std::string& getEmployeePhone() const; const std::string& getEmployeePhone() const;
@@ -61,5 +88,7 @@ public:
void addAttendance(std::shared_ptr<Attendance> attendance); void addAttendance(std::shared_ptr<Attendance> attendance);
void addLeave(std::shared_ptr<Leave> leave); void addLeave(std::shared_ptr<Leave> leave);
Enums::EmployeeType getEmployeeType() const; Enums::EmployeeType getEmployeeType() const;
virtual std::string serialize() const;
static std::shared_ptr<Employee> deserialize(const std::string&);
virtual ~Employee() = default; virtual ~Employee() = default;
}; };
@@ -1,5 +1,4 @@
#pragma once #pragma once
#include<string>
#include "Employee.h" #include "Employee.h"
class FinanceExecutive : public Employee class FinanceExecutive : public Employee
@@ -12,6 +11,23 @@ public:
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll std::shared_ptr<Payroll> payroll
) :Employee(name, phone, email, Enums::EmployeeType::FINANCE, payroll) {}; ) :Employee(name, phone, email, Enums::EmployeeType::FINANCE, payroll) {};
FinanceExecutive(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::FINANCE,
accountStatus) {}
~FinanceExecutive() = default; ~FinanceExecutive() = default;
}; };
@@ -1,4 +1,6 @@
#include <sstream>
#include "GeneralEmployee.h" #include "GeneralEmployee.h"
#include "Factory.h"
Enums::EmployeeDesignation GeneralEmployee::getDesignation() const Enums::EmployeeDesignation GeneralEmployee::getDesignation() const
{ {
@@ -8,4 +10,52 @@ Enums::EmployeeDesignation GeneralEmployee::getDesignation() const
void GeneralEmployee::setDesignation(Enums::EmployeeDesignation designation) void GeneralEmployee::setDesignation(Enums::EmployeeDesignation designation)
{ {
m_designation = designation; m_designation = designation;
}
std::string GeneralEmployee::serialize() const
{
std::ostringstream serializedEmployee;
serializedEmployee << m_id << ','
<< m_email << ','
<< m_name << ','
<< m_phone << ','
<< m_password << ','
<< m_teamId << ','
<< Enums::getTeamStatusString(m_teamStatus) << ','
<< Enums::getAccountStatusString(m_accountStatus) << ','
<< Enums::getEmployeeTypeString(m_employeeType) << ','
<< Enums::getEmployeeDesignationString(m_designation);
return serializedEmployee.str();
}
std::shared_ptr<GeneralEmployee> GeneralEmployee::deserialize(const std::string& record)
{
std::string id, name, phone, password, email;
std::string teamId, teamStatusString, accountStatusString, employeeTypeString, employeeDesignationString;
std::istringstream serializedEmployee(record);
getline(serializedEmployee, id, ',');
getline(serializedEmployee, email, ',');
getline(serializedEmployee, name, ',');
getline(serializedEmployee, phone, ',');
getline(serializedEmployee, password, ',');
getline(serializedEmployee, teamId, ',');
getline(serializedEmployee, teamStatusString, ',');
getline(serializedEmployee, accountStatusString, ',');
getline(serializedEmployee, employeeTypeString, ',');
getline(serializedEmployee, employeeDesignationString, ',');
Enums::TeamStatus teamStatus = Enums::getTeamStatus(teamStatusString);
Enums::AccountStatus accountStatus = Enums::getAccountStatus(accountStatusString);
Enums::EmployeeType employeeType = Enums::getEmployeeType(employeeTypeString);
Enums::EmployeeDesignation employeeDesignation = Enums::getEmployeeDesignation(employeeDesignationString);
return Factory::getObject<GeneralEmployee>(
id,
name,
phone,
password,
email,
teamId,
teamStatus,
employeeDesignation,
accountStatus
);
} }
@@ -7,13 +7,41 @@ class GeneralEmployee : public Employee
private: private:
Enums::EmployeeDesignation m_designation; Enums::EmployeeDesignation m_designation;
public: public:
GeneralEmployee() : m_designation(Enums::EmployeeDesignation::JUNIOR) {} GeneralEmployee()
: m_designation(Enums::EmployeeDesignation::JUNIOR) {}
GeneralEmployee(const std::string& name, GeneralEmployee(const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll, std::shared_ptr<Payroll> payroll,
Enums::EmployeeDesignation designation) : Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll), m_designation(designation) {} Enums::EmployeeDesignation designation)
: Employee(name,
phone,
email,
Enums::EmployeeType::GENERAL,
payroll),
m_designation(designation) {}
GeneralEmployee(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::EmployeeDesignation employeeDesignation,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::GENERAL,
accountStatus),
m_designation(employeeDesignation) {}
Enums::EmployeeDesignation getDesignation() const; Enums::EmployeeDesignation getDesignation() const;
void setDesignation(Enums::EmployeeDesignation designation); void setDesignation(Enums::EmployeeDesignation designation);
std::string serialize() const override;
static std::shared_ptr<GeneralEmployee> deserialize(const std::string&);
~GeneralEmployee() = default; ~GeneralEmployee() = default;
}; };
@@ -11,6 +11,23 @@ public:
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll std::shared_ptr<Payroll> payroll
) :Employee(name, phone, email, Enums::EmployeeType::HR, payroll) {}; ) :Employee(name, phone, email, Enums::EmployeeType::HR, payroll) {};
HRManager(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::HR,
accountStatus) {}
~HRManager() = default; ~HRManager() = default;
}; };
@@ -10,7 +10,24 @@ public:
const std::string& phone, const std::string& phone,
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll std::shared_ptr<Payroll> payroll
) :Employee(name, phone, email, Enums::EmployeeType::GENERAL, payroll) {}; ) :Employee(name, phone, email, Enums::EmployeeType::IT, payroll) {};
ITExecutive(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::IT,
accountStatus) {}
~ITExecutive() = default; ~ITExecutive() = default;
}; };
@@ -11,6 +11,23 @@ public:
const std::string& email, const std::string& email,
std::shared_ptr<Payroll> payroll std::shared_ptr<Payroll> payroll
) :Employee(name, phone, email, Enums::EmployeeType::TEAM, payroll) {}; ) :Employee(name, phone, email, Enums::EmployeeType::TEAM, payroll) {};
TeamExecutive(const std::string& id,
const std::string& name,
const std::string& phone,
const std::string& password,
const std::string& email,
const std::string& teamId,
Enums::TeamStatus teamStatus,
Enums::AccountStatus accountStatus)
: Employee(id,
name,
phone,
password,
email,
teamId,
teamStatus,
Enums::EmployeeType::TEAM,
accountStatus) {}
~TeamExecutive() = default; ~TeamExecutive() = default;
}; };
@@ -30,4 +30,10 @@ namespace Config
constexpr double EXECUTIVE_EMPLOYEE_PF_CONTRIBUTION = 0.0; constexpr double EXECUTIVE_EMPLOYEE_PF_CONTRIBUTION = 0.0;
constexpr double EXECUTIVE_EMPLOYER_PF_CONTRIBUTION = 0.0; constexpr double EXECUTIVE_EMPLOYER_PF_CONTRIBUTION = 0.0;
} }
namespace File
{
constexpr const char* EMPLOYEES_FILE = "files/Employee.csv";
constexpr const char* GENERAL_EMPLOYEES_FILE = "files/GeneralEmployee.csv";
}
} }
@@ -10,6 +10,8 @@
#include "TeamExecutive.h" #include "TeamExecutive.h"
#include "FinanceExecutive.h" #include "FinanceExecutive.h"
#include "GeneralEmployee.h" #include "GeneralEmployee.h"
#include "FileManager.h"
#include "ApplicationConfig.h"
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone) void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
{ {
@@ -93,7 +95,7 @@ void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType,
default: default:
throw std::runtime_error("Invalid Employee Type"); throw std::runtime_error("Invalid Employee Type");
} }
m_dataStore.getEmployees().emplace(std::make_pair(employee->getEmployeeId(), employee)); m_dataStore.getEmployees().emplace(std::make_pair(employee->getId(), employee));
} }
bool EmployeeManagementService::deactivateEmployee(const std::string& id) bool EmployeeManagementService::deactivateEmployee(const std::string& id)
@@ -142,4 +144,29 @@ void EmployeeManagementService::updateProfile(const std::string& name,const std:
std::shared_ptr<Employee> employee = m_dataStore.getAuthenticatedEmployee(); std::shared_ptr<Employee> employee = m_dataStore.getAuthenticatedEmployee();
employee->setEmployeeName(name); employee->setEmployeeName(name);
employee->setEmployeePhone(phone); employee->setEmployeePhone(phone);
} }
void EmployeeManagementService::loadEmployees()
{
FileManager<Employee> employeeFileManager(Config::File::EMPLOYEES_FILE);
FileManager<GeneralEmployee> generalEmployeeFileManager(Config::File::GENERAL_EMPLOYEES_FILE);
bool isAdminFound = false;
auto& employees = m_dataStore.getEmployees();
auto employeesMap = employeeFileManager.load();
auto generalEmployeesMap = generalEmployeeFileManager.load();
employees.insert(employeesMap.begin(), employeesMap.end());
employees.insert(generalEmployeesMap.begin(), generalEmployeesMap.end());
for (auto& employeePair : employees)
{
if (employeePair.second->getEmployeeType() == Enums::EmployeeType::ADMIN)
{
isAdminFound = true;
break;
}
}
if (!isAdminFound)
{
auto admin = Factory::getObject<Admin>("Admin", "", "admin@trenser.com", nullptr);
employees.emplace(std::make_pair(admin->getId(), admin));
}
}
@@ -17,4 +17,5 @@ public:
Employees getEmployees(); Employees getEmployees();
void updateProfile(const std::string&,const std::string&); void updateProfile(const std::string&,const std::string&);
std::shared_ptr<const Employee> getCurrentEmployee(); std::shared_ptr<const Employee> getCurrentEmployee();
void loadEmployees();
}; };
@@ -1,4 +1,5 @@
#pragma once #pragma once
#include <string>
namespace Enums { namespace Enums {
@@ -89,4 +90,120 @@ namespace Enums {
USER_NOT_FOUND, USER_NOT_FOUND,
INVALID_PASSWORD INVALID_PASSWORD
}; };
inline std::string getAccountStatusString(AccountStatus status)
{
switch (status)
{
case AccountStatus::ACTIVE:
return "ACTIVE";
case AccountStatus::INACTIVE:
return "INACTIVE";
default:
return "UNKNOWN";
}
}
inline std::string getEmployeeTypeString(EmployeeType type)
{
switch (type)
{
case EmployeeType::GENERAL:
return "GENERAL";
case EmployeeType::IT:
return "IT";
case EmployeeType::FINANCE:
return "FINANCE";
case EmployeeType::TAG:
return "TAG";
case EmployeeType::HR:
return "HR";
case EmployeeType::TEAM:
return "TEAM";
case EmployeeType::ADMIN:
return "ADMIN";
case EmployeeType::INVALID:
return "INVALID";
default:
return "UNKNOWN";
}
}
inline std::string getTeamStatusString(TeamStatus status)
{
switch (status)
{
case TeamStatus::IN_TEAM:
return "IN_TEAM";
case TeamStatus::NOT_IN_TEAM:
return "NOT_IN_TEAM";
default:
return "UNKNOWN";
}
}
inline std::string getEmployeeDesignationString(EmployeeDesignation designation)
{
switch (designation)
{
case EmployeeDesignation::JUNIOR:
return "JUNIOR";
case EmployeeDesignation::SENIOR:
return "SENIOR";
case EmployeeDesignation::TEAM_LEAD:
return "TEAM_LEAD";
case EmployeeDesignation::INVALID:
return "INVALID";
default:
return "UNKNOWN";
}
}
inline AccountStatus getAccountStatus(const std::string& input)
{
if (input == "ACTIVE")
return AccountStatus::ACTIVE;
if (input == "INACTIVE")
return AccountStatus::INACTIVE;
return AccountStatus::INACTIVE;
}
inline EmployeeType getEmployeeType(const std::string& input)
{
if (input == "GENERAL")
return EmployeeType::GENERAL;
if (input == "IT")
return EmployeeType::IT;
if (input == "FINANCE")
return EmployeeType::FINANCE;
if (input == "TAG")
return EmployeeType::TAG;
if (input == "HR")
return EmployeeType::HR;
if (input == "TEAM")
return EmployeeType::TEAM;
if (input == "ADMIN")
return EmployeeType::ADMIN;
return EmployeeType::INVALID;
}
inline TeamStatus getTeamStatus(const std::string& str)
{
if (str == "IN_TEAM")
return TeamStatus::IN_TEAM;
if (str == "NOT_IN_TEAM")
return TeamStatus::NOT_IN_TEAM;
return TeamStatus::NOT_IN_TEAM;
}
inline EmployeeDesignation getEmployeeDesignation(const std::string& input)
{
if (input == "JUNIOR")
return EmployeeDesignation::JUNIOR;
if (input == "SENIOR")
return EmployeeDesignation::SENIOR;
if (input == "TEAM_LEAD")
return EmployeeDesignation::TEAM_LEAD;
return EmployeeDesignation::INVALID;
}
} }
@@ -0,0 +1,15 @@
#include "StringHelper.h"
#include <cctype>
int util::extractNumber(const std::string& input)
{
int result = 0;
for (char character : input)
{
if (std::isdigit(static_cast<unsigned char>(character)))
{
result = result * 10 + (character - '0');
}
}
return result;
}
@@ -0,0 +1,7 @@
#pragma once
#include <string>
namespace util
{
int extractNumber(const std::string&);
}
@@ -49,7 +49,7 @@ std::string FinanceExecutiveMenu::getSelectedUserId()
for (const auto& employee : employeeList) for (const auto& employee : employeeList)
{ {
std::cout << std::left << std::setw(6) << employee.first std::cout << std::left << std::setw(6) << employee.first
<< std::setw(15) << employee.second->getEmployeeId() << std::setw(15) << employee.second->getId()
<< std::setw(25) << employee.second->getEmployeeName() << std::setw(25) << employee.second->getEmployeeName()
<< std::endl; << std::endl;
} }
@@ -58,7 +58,7 @@ std::string FinanceExecutiveMenu::getSelectedUserId()
auto employeeIterator = employeeList.find(choice); auto employeeIterator = employeeList.find(choice);
if (employeeIterator != employeeList.end()) if (employeeIterator != employeeList.end())
{ {
return (employeeIterator->second->getEmployeeId()); return (employeeIterator->second->getId());
} }
else else
{ {
@@ -63,7 +63,7 @@ inline std::map<int, std::shared_ptr<const Employee>> listEmployees(const std::s
{ {
std::cout << std::left std::cout << std::left
<< std::setw(5) << index << std::setw(5) << index
<< std::setw(15) << activeEmployees->getEmployeeId() << std::setw(15) << activeEmployees->getId()
<< std::setw(25) << activeEmployees->getEmployeeName() << std::setw(25) << activeEmployees->getEmployeeName()
<< "\n"; << "\n";
employeeList[index] = activeEmployees; employeeList[index] = activeEmployees;
@@ -90,7 +90,7 @@ inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controlle
auto iterator = employeeList.find(choice); auto iterator = employeeList.find(choice);
if (iterator != employeeList.end()) if (iterator != employeeList.end())
{ {
std::string id = iterator->second->getEmployeeId(); std::string id = iterator->second->getId();
bool success = controller->deactivateEmployee(id); bool success = controller->deactivateEmployee(id);
if (success) if (success)
{ {
@@ -19,6 +19,15 @@
void UserInterface::run() void UserInterface::run()
{ {
bool isMenuActive = true; bool isMenuActive = true;
try
{
m_controller->loadStates();
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return;
}
while (isMenuActive) while (isMenuActive)
{ {
try try
@@ -94,7 +103,7 @@ void UserInterface::login()
} }
else else
{ {
std::cout << "\nInvalid Password"; std::cout << "Error: Invalid Password\n";
util::pressEnter(); util::pressEnter();
return; return;
} }