Refactor employee fetch with type filter and login check
<SRS> SRS02 : Employee Management </SRS> <Changes> - Removed old getEmployees() implementation - Added templated getEmployees(...) for filtering by employee type - Default now skips admin and returns only active employees - Blocked login for inactive employees with proper error </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -47,11 +47,6 @@ std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
|
|||||||
return m_employeeManagementService->getCurrentEmployee();
|
return m_employeeManagementService->getCurrentEmployee();
|
||||||
}
|
}
|
||||||
|
|
||||||
Employees ZenvyController::getEmployees()
|
|
||||||
{
|
|
||||||
return m_employeeManagementService->getEmployees();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZenvyController::loadStates()
|
void ZenvyController::loadStates()
|
||||||
{
|
{
|
||||||
m_employeeManagementService->loadEmployees();
|
m_employeeManagementService->loadEmployees();
|
||||||
|
|||||||
@@ -47,11 +47,16 @@ public:
|
|||||||
//Employee Management
|
//Employee Management
|
||||||
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
||||||
bool deactivateEmployee(const std::string&);
|
bool deactivateEmployee(const std::string&);
|
||||||
Employees getEmployees();
|
|
||||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||||
void updateProfile(const std::string&,const std::string&);
|
void updateProfile(const std::string&,const std::string&);
|
||||||
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
|
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
|
||||||
|
|
||||||
|
template <typename ...Types>
|
||||||
|
Employees getEmployees(Types ...types)
|
||||||
|
{
|
||||||
|
return m_employeeManagementService->getEmployees(types...);
|
||||||
|
}
|
||||||
|
|
||||||
//Payslip management
|
//Payslip management
|
||||||
void updateSalary(const std::string&, double, double, double, double, double);
|
void updateSalary(const std::string&, double, double, double, double, double);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ AuthenticationDTO AuthenticationManagementService::login(const std::string& emai
|
|||||||
{
|
{
|
||||||
if (employee.second->getEmployeePassword() == password)
|
if (employee.second->getEmployeePassword() == password)
|
||||||
{
|
{
|
||||||
|
if (employee.second->getEmployeeAccountStatus() == Enums::AccountStatus::INACTIVE)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Your account has been disabled! Please contact your Administrator.");
|
||||||
|
}
|
||||||
if (password == Config::Authentication::DEFAULT_PASSWORD)
|
if (password == Config::Authentication::DEFAULT_PASSWORD)
|
||||||
{
|
{
|
||||||
loginStatus = Enums::LoginStatus::FIRST_LOGIN;
|
loginStatus = Enums::LoginStatus::FIRST_LOGIN;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "GeneralEmployee.h"
|
#include "GeneralEmployee.h"
|
||||||
#include "FileManager.h"
|
#include "FileManager.h"
|
||||||
#include "ApplicationConfig.h"
|
#include "ApplicationConfig.h"
|
||||||
#include "StringHelper.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)
|
||||||
{
|
{
|
||||||
@@ -132,35 +131,6 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Employees EmployeeManagementService::getEmployees()
|
|
||||||
{
|
|
||||||
Employees activeEmployees;
|
|
||||||
auto& employees = m_dataStore.getEmployees();
|
|
||||||
if (employees.size() <= 0)
|
|
||||||
{
|
|
||||||
return activeEmployees;
|
|
||||||
}
|
|
||||||
for (const auto& iterator : employees)
|
|
||||||
{
|
|
||||||
if (iterator.second->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE)
|
|
||||||
{
|
|
||||||
activeEmployees.push_back(iterator.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::sort(
|
|
||||||
activeEmployees.begin(),
|
|
||||||
activeEmployees.end(),
|
|
||||||
[](std::shared_ptr<const Employee> employeeOne,
|
|
||||||
std::shared_ptr<const Employee> employeeTwo) -> bool
|
|
||||||
{
|
|
||||||
int employeeOneId = util::extractNumber(employeeOne->getId());
|
|
||||||
int employeeTwoId = util::extractNumber(employeeTwo->getId());
|
|
||||||
return employeeOneId < employeeTwoId;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return activeEmployees;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
|
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
|
||||||
{
|
{
|
||||||
return m_dataStore.getAuthenticatedEmployee();
|
return m_dataStore.getAuthenticatedEmployee();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include "DataStore.h"
|
#include "DataStore.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include "StringHelper.h"
|
||||||
|
|
||||||
using Employees = std::vector<std::shared_ptr<const Employee>>;
|
using Employees = std::vector<std::shared_ptr<const Employee>>;
|
||||||
|
|
||||||
@@ -16,10 +17,46 @@ public:
|
|||||||
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
|
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
|
||||||
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
||||||
bool deactivateEmployee(const std::string&);
|
bool deactivateEmployee(const std::string&);
|
||||||
Employees getEmployees();
|
|
||||||
void updateProfile(const std::string&,const std::string&);
|
void updateProfile(const std::string&,const std::string&);
|
||||||
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
|
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
|
||||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||||
void loadEmployees();
|
void loadEmployees();
|
||||||
void saveEmployees();
|
void saveEmployees();
|
||||||
|
|
||||||
|
template<typename... Types>
|
||||||
|
Employees getEmployees(Types... types)
|
||||||
|
{
|
||||||
|
Employees filteredEmployees;
|
||||||
|
const auto& employees = m_dataStore.getEmployees();
|
||||||
|
std::vector<Enums::EmployeeType> filterTypes = { types... };
|
||||||
|
for (const auto& employeePair : employees)
|
||||||
|
{
|
||||||
|
const auto& employee = employeePair.second;
|
||||||
|
if (employee->getEmployeeAccountStatus() != Enums::AccountStatus::ACTIVE)
|
||||||
|
continue;
|
||||||
|
auto employeeType = employee->getEmployeeType();
|
||||||
|
if (filterTypes.empty())
|
||||||
|
{
|
||||||
|
if (employeeType == Enums::EmployeeType::ADMIN)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (std::find(filterTypes.begin(), filterTypes.end(), employeeType) == filterTypes.end())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filteredEmployees.push_back(employee);
|
||||||
|
}
|
||||||
|
std::sort(
|
||||||
|
filteredEmployees.begin(),
|
||||||
|
filteredEmployees.end(),
|
||||||
|
[](const std::shared_ptr<const Employee>& employeeOne,
|
||||||
|
const std::shared_ptr<const Employee>& employeeTwo)
|
||||||
|
{
|
||||||
|
return util::extractNumber(employeeOne->getId()) <
|
||||||
|
util::extractNumber(employeeTwo->getId());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return filteredEmployees;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user