refactor: change memory management and fix related code
- Switched shared_ptr to raw pointers - Added cleanup logic in DataStore - Fixed Factory object creation - Updated function signatures to match changes - Small refactors and formatting fixes
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "FileIO.h"
|
#include "FileIO.h"
|
||||||
|
|
||||||
template <typename T> using objects = std::map<std::string, std::shared_ptr<T>>;
|
template <typename T> using objects = std::map<std::string, T*>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class FileManager
|
class FileManager
|
||||||
|
|||||||
@@ -15,14 +15,13 @@
|
|||||||
* password - password of the employee
|
* password - password of the employee
|
||||||
* Returns:
|
* Returns:
|
||||||
* Tuple - login status, employee type, employee designation
|
* Tuple - login status, employee type, employee designation
|
||||||
* login status - success or failed
|
* login status - success or failed
|
||||||
* employee type - type of the employee logged in
|
* employee type - type of the employee logged in
|
||||||
* employee designation - designation if employee type is GENERAL.
|
* employee designation - designation if employee type is GENERAL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
AuthenticationDTO ZenvyController::login(const std::string& email, const std::string& password)
|
AuthenticationDTO ZenvyController::login(const std::string& email, const std::string& password)
|
||||||
{
|
{
|
||||||
return m_authenticationManagementService->login(email, password);
|
return m_authenticationManagementService->login(email, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -36,7 +35,7 @@ AuthenticationDTO ZenvyController::login(const std::string& email, const std::st
|
|||||||
|
|
||||||
void ZenvyController::logout()
|
void ZenvyController::logout()
|
||||||
{
|
{
|
||||||
m_authenticationManagementService->logout();
|
m_authenticationManagementService->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -50,73 +49,73 @@ void ZenvyController::logout()
|
|||||||
|
|
||||||
void ZenvyController::changePassword(const std::string& password)
|
void ZenvyController::changePassword(const std::string& password)
|
||||||
{
|
{
|
||||||
m_authenticationManagementService->changePassword(password);
|
m_authenticationManagementService->changePassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Employee Management
|
//Employee Management
|
||||||
void ZenvyController::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
|
void ZenvyController::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone) const
|
||||||
{
|
{
|
||||||
m_employeeManagementService->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
m_employeeManagementService->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZenvyController::deactivateEmployee(const std::string& id)
|
bool ZenvyController::deactivateEmployee(const std::string& id) const
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->deactivateEmployee(id);
|
return m_employeeManagementService->deactivateEmployee(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZenvyController::updateProfile(const std::string& name, const std::string& phone)
|
void ZenvyController::updateProfile(const std::string& name, const std::string& phone)
|
||||||
{
|
{
|
||||||
m_employeeManagementService->updateProfile(name,phone);
|
m_employeeManagementService->updateProfile(name, phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> ZenvyController::searchEmployee(const std::string& name)
|
std::pair<Enums::EmployeeType, std::vector<const Employee*>> ZenvyController::searchEmployee(const std::string& name)
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->searchEmployee(name);
|
return m_employeeManagementService->searchEmployee(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
|
const Employee* ZenvyController::getCurrentEmployee() const
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->getCurrentEmployee();
|
return m_employeeManagementService->getCurrentEmployee();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZenvyController::updateDesignation(const std::string& id,Enums::EmployeeDesignation designation)
|
bool ZenvyController::updateDesignation(const std::string& id, Enums::EmployeeDesignation designation)
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->updateDesignation(id,designation);
|
return m_employeeManagementService->updateDesignation(id, designation);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Candidate>> ZenvyController::getShorlistedCandidates()
|
std::vector<Candidate*> ZenvyController::getShorlistedCandidates() const
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->getShorlistedCandidates();
|
return m_employeeManagementService->getShorlistedCandidates();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Payslip Management
|
//Payslip Management
|
||||||
void ZenvyController::updateSalary(const std::string& employeeId, double basicSalary, double houseRentAllowance, double foodAllowance, double employeePFContribution, double employerPFContribution)
|
void ZenvyController::updateSalary(const std::string& employeeId, double basicSalary, double houseRentAllowance, double foodAllowance, double employeePFContribution, double employerPFContribution)
|
||||||
{
|
{
|
||||||
m_payslipManagementService->updateSalary(employeeId, basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution);
|
m_payslipManagementService->updateSalary(employeeId, basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZenvyController::generatePayslips()
|
void ZenvyController::generatePayslips()
|
||||||
{
|
{
|
||||||
m_payslipManagementService->generatePayslips();
|
m_payslipManagementService->generatePayslips();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZenvyController::loadStates()
|
void ZenvyController::loadStates()
|
||||||
{
|
{
|
||||||
m_employeeManagementService->loadEmployees();
|
m_employeeManagementService->loadEmployees();
|
||||||
m_payslipManagementService->loadPayrolls();
|
m_payslipManagementService->loadPayrolls();
|
||||||
m_payslipManagementService->loadPayslips();
|
m_payslipManagementService->loadPayslips();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZenvyController::persistStates()
|
void ZenvyController::persistStates()
|
||||||
{
|
{
|
||||||
m_employeeManagementService->saveEmployees();
|
m_employeeManagementService->saveEmployees();
|
||||||
m_payslipManagementService->savePayrolls();
|
m_payslipManagementService->savePayrolls();
|
||||||
m_payslipManagementService->savePayslips();
|
m_payslipManagementService->savePayslips();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>> ZenvyController::getPayslipForMonth(const std::string& employeeId, int year, int month)
|
std::pair<Payroll*, Payslip*> ZenvyController::getPayslipForMonth(const std::string& employeeId, int year, int month)
|
||||||
{
|
{
|
||||||
return m_payslipManagementService->getPayslipForMonth(employeeId, year, month);
|
return m_payslipManagementService->getPayslipForMonth(employeeId, year, month);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZenvyController::~ZenvyController()
|
ZenvyController::~ZenvyController()
|
||||||
|
|||||||
@@ -22,55 +22,56 @@
|
|||||||
class ZenvyController
|
class ZenvyController
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
AuthenticationManagementService* m_authenticationManagementService;
|
AuthenticationManagementService* m_authenticationManagementService;
|
||||||
AttendanceManagementService* m_attendanceManagementService;
|
AttendanceManagementService* m_attendanceManagementService;
|
||||||
BookingManagementService* m_bookingManagementService;
|
BookingManagementService* m_bookingManagementService;
|
||||||
EmployeeManagementService* m_employeeManagementService;
|
EmployeeManagementService* m_employeeManagementService;
|
||||||
LeaveManagementService* m_leaveManagementService;
|
LeaveManagementService* m_leaveManagementService;
|
||||||
NotificationManagementService* m_notificationManagementService;
|
NotificationManagementService* m_notificationManagementService;
|
||||||
PayslipManagementService* m_payslipManagementService;
|
PayslipManagementService* m_payslipManagementService;
|
||||||
TalentAcquisitionManagementService* m_talentAcquisitionManagementService;
|
TalentAcquisitionManagementService* m_talentAcquisitionManagementService;
|
||||||
TeamManagementService* m_teamManagementService;
|
TeamManagementService* m_teamManagementService;
|
||||||
TicketManagementService* m_ticketManagementService;
|
TicketManagementService* m_ticketManagementService;
|
||||||
public:
|
public:
|
||||||
ZenvyController() :
|
ZenvyController() :
|
||||||
m_authenticationManagementService(new AuthenticationManagementService()),
|
m_authenticationManagementService(new AuthenticationManagementService()),
|
||||||
m_attendanceManagementService(new AttendanceManagementService()),
|
m_attendanceManagementService(new AttendanceManagementService()),
|
||||||
m_bookingManagementService(new BookingManagementService()),
|
m_bookingManagementService(new BookingManagementService()),
|
||||||
m_employeeManagementService(new EmployeeManagementService()),
|
m_employeeManagementService(new EmployeeManagementService()),
|
||||||
m_leaveManagementService(new LeaveManagementService()),
|
m_leaveManagementService(new LeaveManagementService()),
|
||||||
m_notificationManagementService(new NotificationManagementService()),
|
m_notificationManagementService(new NotificationManagementService()),
|
||||||
m_payslipManagementService(new PayslipManagementService()),
|
m_payslipManagementService(new PayslipManagementService()),
|
||||||
m_talentAcquisitionManagementService(new TalentAcquisitionManagementService()),
|
m_talentAcquisitionManagementService(new TalentAcquisitionManagementService()),
|
||||||
m_teamManagementService(new TeamManagementService()),
|
m_teamManagementService(new TeamManagementService()),
|
||||||
m_ticketManagementService(new TicketManagementService()) {};
|
m_ticketManagementService(new TicketManagementService()) {};
|
||||||
|
~ZenvyController();
|
||||||
|
|
||||||
//Authentication
|
//Authentication
|
||||||
AuthenticationDTO login(const std::string& email, const std::string& password);
|
AuthenticationDTO login(const std::string& email, const std::string& password);
|
||||||
void logout();
|
void logout();
|
||||||
void changePassword(const std::string&);
|
void changePassword(const std::string&);
|
||||||
|
|
||||||
//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&) const;
|
||||||
bool deactivateEmployee(const std::string&);
|
bool deactivateEmployee(const std::string&) const;
|
||||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
const Employee* getCurrentEmployee() const;
|
||||||
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<const Employee*>> searchEmployee(const std::string&);
|
||||||
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
|
bool updateDesignation(const std::string&, Enums::EmployeeDesignation);
|
||||||
std::vector<std::shared_ptr<Candidate>> getShorlistedCandidates();
|
std::vector<Candidate*> getShorlistedCandidates() const;
|
||||||
|
|
||||||
template <typename ...Types>
|
template <typename ...Types>
|
||||||
Employees getEmployees(Types ...types)
|
Employees getEmployees(Types ...types) const
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->getEmployees(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);
|
||||||
void generatePayslips();
|
void generatePayslips();
|
||||||
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>>getPayslipForMonth(const std::string&, int, int);
|
std::pair<Payroll*, Payslip*>getPayslipForMonth(const std::string&, int, int);
|
||||||
|
|
||||||
//File Management
|
//File Management
|
||||||
void loadStates();
|
void loadStates();
|
||||||
void persistStates();
|
void persistStates();
|
||||||
};
|
};
|
||||||
@@ -8,19 +8,19 @@
|
|||||||
#include "DataStore.h"
|
#include "DataStore.h"
|
||||||
#include "EmployeeManagementService.h"
|
#include "EmployeeManagementService.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: getInstance
|
* Function: getInstance
|
||||||
* Description: provides a singleton instance of the DataStore.
|
* Description: provides a singleton instance of the DataStore.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* None
|
* None
|
||||||
* Returns:
|
* Returns:
|
||||||
* DataStore& - reference to the single DataStore object.
|
* DataStore& - reference to the single DataStore object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DataStore& DataStore::getInstance()
|
DataStore& DataStore::getInstance()
|
||||||
{
|
{
|
||||||
static DataStore dataStore;
|
static DataStore dataStore;
|
||||||
return dataStore;
|
return dataStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -34,7 +34,7 @@ DataStore& DataStore::getInstance()
|
|||||||
|
|
||||||
logMap& DataStore::getLogs()
|
logMap& DataStore::getLogs()
|
||||||
{
|
{
|
||||||
return m_logs;
|
return m_logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -48,7 +48,7 @@ logMap& DataStore::getLogs()
|
|||||||
|
|
||||||
Employee*& DataStore::getAuthenticatedEmployee()
|
Employee*& DataStore::getAuthenticatedEmployee()
|
||||||
{
|
{
|
||||||
return m_authenticatedEmployee;
|
return m_authenticatedEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,7 +62,7 @@ Employee*& DataStore::getAuthenticatedEmployee()
|
|||||||
|
|
||||||
void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee)
|
void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee)
|
||||||
{
|
{
|
||||||
m_authenticatedEmployee = authenticatedEmployee;
|
m_authenticatedEmployee = authenticatedEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -76,12 +76,22 @@ void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee)
|
|||||||
|
|
||||||
employeeMap& DataStore::getEmployees()
|
employeeMap& DataStore::getEmployees()
|
||||||
{
|
{
|
||||||
return m_employees;
|
return m_employees;
|
||||||
}
|
}
|
||||||
|
|
||||||
payrollMap& DataStore::getPayrolls()
|
payrollMap& DataStore::getPayrolls()
|
||||||
{
|
{
|
||||||
return m_payrolls;
|
return m_payrolls;
|
||||||
|
}
|
||||||
|
|
||||||
|
payslipMap& DataStore::getPayslips()
|
||||||
|
{
|
||||||
|
return m_payslips;
|
||||||
|
}
|
||||||
|
|
||||||
|
candidateMap& DataStore::getCandidates()
|
||||||
|
{
|
||||||
|
return m_candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataStore::~DataStore()
|
DataStore::~DataStore()
|
||||||
@@ -91,19 +101,25 @@ DataStore::~DataStore()
|
|||||||
delete pair.second;
|
delete pair.second;
|
||||||
}
|
}
|
||||||
m_employees.clear();
|
m_employees.clear();
|
||||||
|
for (auto& pair : m_payrolls)
|
||||||
|
{
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
|
m_payrolls.clear();
|
||||||
|
for (auto& pair : m_payslips)
|
||||||
|
{
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
|
m_payslips.clear();
|
||||||
for (auto& pair : m_logs)
|
for (auto& pair : m_logs)
|
||||||
{
|
{
|
||||||
delete pair.second;
|
delete pair.second;
|
||||||
}
|
}
|
||||||
m_logs.clear();
|
m_logs.clear();
|
||||||
if (m_authenticatedEmployee)
|
for (auto& pair : m_candidates)
|
||||||
{
|
{
|
||||||
delete m_authenticatedEmployee;
|
delete pair.second;
|
||||||
m_authenticatedEmployee = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
m_candidates.clear();
|
||||||
|
m_authenticatedEmployee = nullptr;
|
||||||
payslipMap& DataStore::getPayslips()
|
|
||||||
{
|
|
||||||
return m_payslips;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
DataStore& operator=(const DataStore&) = delete;
|
DataStore& operator=(const DataStore&) = delete;
|
||||||
DataStore(DataStore&&) = delete;
|
DataStore(DataStore&&) = delete;
|
||||||
DataStore& operator=(DataStore&&) = delete;
|
DataStore& operator=(DataStore&&) = delete;
|
||||||
employeeMap& getEmployees();
|
employeeMap& getEmployees();
|
||||||
payrollMap& getPayrolls();
|
payrollMap& getPayrolls();
|
||||||
payslipMap& getPayslips();
|
payslipMap& getPayslips();
|
||||||
logMap& getLogs();
|
logMap& getLogs();
|
||||||
|
|||||||
@@ -20,11 +20,10 @@ public:
|
|||||||
* Args - constructor arguments forwarded to T's constructor
|
* Args - constructor arguments forwarded to T's constructor
|
||||||
* Returns:
|
* Returns:
|
||||||
* std::shared_ptr<T> - a shared pointer managing the newly created object
|
* std::shared_ptr<T> - a shared pointer managing the newly created object
|
||||||
*/
|
*/;
|
||||||
|
template<typename T, typename... Args>
|
||||||
template<typename T, typename... Args>
|
static T* getObject(Args&&... args)
|
||||||
static T* getObject(Args&&... args)
|
{
|
||||||
{
|
return new T(std::forward<Args>(args)...);
|
||||||
return T*(std::forward<Args>(args)...);
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -44,6 +44,7 @@ public:
|
|||||||
m_accountStatus(Enums::AccountStatus::ACTIVE),
|
m_accountStatus(Enums::AccountStatus::ACTIVE),
|
||||||
m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM),
|
m_teamStatus(Enums::TeamStatus::NOT_IN_TEAM),
|
||||||
m_teamId(""),
|
m_teamId(""),
|
||||||
|
m_payroll(nullptr),
|
||||||
m_employeeType(Enums::EmployeeType::GENERAL) {}
|
m_employeeType(Enums::EmployeeType::GENERAL) {}
|
||||||
Employee(const std::string& name,
|
Employee(const std::string& name,
|
||||||
const std::string& phone,
|
const std::string& phone,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ File: JobListing.h
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include "Candidate.h"
|
#include "Candidate.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
using candidateMap = std::map<std::string, Candidate*>;
|
using candidateMap = std::map<std::string, Candidate*>;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ File: Payroll.cpp
|
|||||||
* Author : Trenser
|
* Author : Trenser
|
||||||
* Created : 31-Mar-2026
|
* Created : 31-Mar-2026
|
||||||
*/
|
*/
|
||||||
|
#include <sstream>
|
||||||
#include "Payroll.h"
|
#include "Payroll.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ File: Payroll.h
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
|
|
||||||
class Payroll
|
class Payroll
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ File: Payslip.h
|
|||||||
* Created : 31-Mar-2026
|
* Created : 31-Mar-2026
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ File: Room.h
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include "Booking.h"
|
#include "Booking.h"
|
||||||
using bookingMap = std::map<std::string, Booking*>;
|
using bookingMap = std::map<std::string, Booking*>;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ File: Team.h
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include "Employee.h"
|
#include "Employee.h"
|
||||||
using employeeMap = std::map<std::string, Employee*>;
|
using employeeMap = std::map<std::string, Employee*>;
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType,
|
|||||||
throw std::runtime_error("No authenticated user");
|
throw std::runtime_error("No authenticated user");
|
||||||
}
|
}
|
||||||
Enums::EmployeeType authenticatedEmployeeType = authenticatedEmployee->getEmployeeType();
|
Enums::EmployeeType authenticatedEmployeeType = authenticatedEmployee->getEmployeeType();
|
||||||
Employee* employee;
|
Employee* employee = nullptr;
|
||||||
Payroll* payroll;
|
Payroll* payroll = nullptr;
|
||||||
if (employeeType != Enums::EmployeeType::GENERAL && util::hasActiveEmployeeOfType(employeeType, employees))
|
if (employeeType != Enums::EmployeeType::GENERAL && util::hasActiveEmployeeOfType(employeeType, employees))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Cannot create more than one employee of type " + Enums::getEmployeeTypeString(employeeType));
|
throw std::runtime_error("Cannot create more than one employee of type " + Enums::getEmployeeTypeString(employeeType));
|
||||||
|
|||||||
@@ -7,23 +7,23 @@
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
|
|
||||||
using Employees = std::vector<std::shared_ptr<const Employee>>;
|
using Employees = std::vector<const Employee*>;
|
||||||
|
|
||||||
class EmployeeManagementService
|
class EmployeeManagementService
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
DataStore& m_dataStore;
|
DataStore& m_dataStore;
|
||||||
public:
|
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&);
|
||||||
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
|
bool updateDesignation(const std::string&, Enums::EmployeeDesignation);
|
||||||
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<const Employee*>> searchEmployee(const std::string&);
|
||||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
const Employee* getCurrentEmployee();
|
||||||
std::vector<std::shared_ptr<Candidate>> getShorlistedCandidates();
|
std::vector<Candidate*> getShorlistedCandidates();
|
||||||
void loadEmployees();
|
void loadEmployees();
|
||||||
void saveEmployees();
|
void saveEmployees();
|
||||||
|
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
Employees getEmployees(Types... types)
|
Employees getEmployees(Types... types)
|
||||||
@@ -52,8 +52,8 @@ public:
|
|||||||
std::sort(
|
std::sort(
|
||||||
filteredEmployees.begin(),
|
filteredEmployees.begin(),
|
||||||
filteredEmployees.end(),
|
filteredEmployees.end(),
|
||||||
[](const std::shared_ptr<const Employee>& employeeOne,
|
[](const Employee* employeeOne,
|
||||||
const std::shared_ptr<const Employee>& employeeTwo)
|
const Employee* employeeTwo)
|
||||||
{
|
{
|
||||||
return util::extractNumber(employeeOne->getId()) <
|
return util::extractNumber(employeeOne->getId()) <
|
||||||
util::extractNumber(employeeTwo->getId());
|
util::extractNumber(employeeTwo->getId());
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ bool util::isPasswordValid(const std::string& password)
|
|||||||
return hasUpper && hasLower && hasDigit && hasSpecial;
|
return hasUpper && hasLower && hasDigit && hasSpecial;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util::hasActiveEmployeeOfType(Enums::EmployeeType employeeType, const std::map<std::string, std::shared_ptr<Employee>> & employees)
|
bool util::hasActiveEmployeeOfType(Enums::EmployeeType employeeType, const std::map<std::string, Employee*> & employees)
|
||||||
{
|
{
|
||||||
for (const auto& employeePair : employees)
|
for (const auto& employeePair : employees)
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ bool util::hasActiveEmployeeOfType(Enums::EmployeeType employeeType, const std::
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util::isEmailDuplicate(const std::string& email, const std::map<std::string, std::shared_ptr<Employee>>& employees)
|
bool util::isEmailDuplicate(const std::string& email, const std::map<std::string, Employee*>& employees)
|
||||||
{
|
{
|
||||||
for (const auto& employeePair : employees)
|
for (const auto& employeePair : employees)
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ bool util::isEmailDuplicate(const std::string& email, const std::map<std::string
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util::isPhoneDuplicate(const std::string& phone, const std::map<std::string, std::shared_ptr<Employee>>& employees)
|
bool util::isPhoneDuplicate(const std::string& phone, const std::map<std::string, Employee*>& employees)
|
||||||
{
|
{
|
||||||
for (const auto& employeePair : employees)
|
for (const auto& employeePair : employees)
|
||||||
{
|
{
|
||||||
@@ -151,7 +151,7 @@ bool util::isPhoneDuplicate(const std::string& phone, const std::map<std::string
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool util::isPhoneDuplicate(const std::string& phone, const std::vector<std::shared_ptr<const Employee>>& employees)
|
bool util::isPhoneDuplicate(const std::string& phone, const std::vector<const Employee*>& employees)
|
||||||
{
|
{
|
||||||
for (const auto& employee : employees)
|
for (const auto& employee : employees)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
* Author: Trenser
|
* Author: Trenser
|
||||||
* Created: 01-Apr-2026
|
* Created: 01-Apr-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include<string>
|
#include<string>
|
||||||
#include<map>
|
#include<map>
|
||||||
@@ -21,8 +20,8 @@ namespace util
|
|||||||
bool isPhoneNumberValid(const std::string&);
|
bool isPhoneNumberValid(const std::string&);
|
||||||
bool isEmailValid(const std::string&);
|
bool isEmailValid(const std::string&);
|
||||||
bool isPasswordValid(const std::string&);
|
bool isPasswordValid(const std::string&);
|
||||||
bool hasActiveEmployeeOfType(Enums::EmployeeType, const std::map<std::string, std::shared_ptr<Employee>>&);
|
bool hasActiveEmployeeOfType(Enums::EmployeeType, const std::map<std::string, Employee*>&);
|
||||||
bool isEmailDuplicate(const std::string&, const std::map<std::string, std::shared_ptr<Employee>>&);
|
bool isEmailDuplicate(const std::string&, const std::map<std::string, Employee*>&);
|
||||||
bool isPhoneDuplicate(const std::string&, const std::map<std::string, std::shared_ptr<Employee>>&);
|
bool isPhoneDuplicate(const std::string&, const std::map<std::string, Employee*>&);
|
||||||
bool isPhoneDuplicate(const std::string&, const std::vector<std::shared_ptr<const Employee>>&);
|
bool isPhoneDuplicate(const std::string&, const std::vector<const Employee*>&);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -22,7 +21,7 @@ void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController)
|
|||||||
|
|
||||||
inline void viewPayslipHistory(ZenvyController* m_zenvyController)
|
inline void viewPayslipHistory(ZenvyController* m_zenvyController)
|
||||||
{
|
{
|
||||||
auto employeePayslips = m_zenvyController->getCurrentEmployee()->getEmployeePayslips();
|
auto& employeePayslips = m_zenvyController->getCurrentEmployee()->getEmployeePayslips();
|
||||||
util::clear();
|
util::clear();
|
||||||
if (employeePayslips.empty())
|
if (employeePayslips.empty())
|
||||||
{
|
{
|
||||||
@@ -147,7 +146,7 @@ inline void updateProfile(ZenvyController* m_zenvyController)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string selectEmployeeId(std::vector<const Employee*>& allEmployees)
|
inline std::string selectEmployeeId(const std::vector<const Employee*>& allEmployees)
|
||||||
{
|
{
|
||||||
int choice;
|
int choice;
|
||||||
std::map<int, const Employee*> employeeList;
|
std::map<int, const Employee*> employeeList;
|
||||||
@@ -353,7 +352,7 @@ inline void viewPayslip(ZenvyController* m_zenvyController)
|
|||||||
if (payroll && payslip)
|
if (payroll && payslip)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Payslip for " << employee->getEmployeeName() << " (" << year << "-" << std::setw(2) << std::setfill('0') << month << ")\n\n";
|
std::cout << "Payslip for " << employee->getEmployeeName() << " (" << year << "-" << std::setw(2) << month << ")\n\n";
|
||||||
std::cout << "Basic Salary : " << payroll->getBasicSalary() << "\n";
|
std::cout << "Basic Salary : " << payroll->getBasicSalary() << "\n";
|
||||||
std::cout << "House Rent Allowance : " << payroll->getHouseRentAllowance() << "\n";
|
std::cout << "House Rent Allowance : " << payroll->getHouseRentAllowance() << "\n";
|
||||||
std::cout << "Food Allowance : " << payroll->getFoodAllowance() << "\n";
|
std::cout << "Food Allowance : " << payroll->getFoodAllowance() << "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user