Add function headers to Service Layers
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* File: EmployeeManagementService.h
|
||||
* Description: Provides services for managing employees, including creation, deactivation,
|
||||
* designation updates, profile modifications, searching, and retrieval of
|
||||
* shortlisted candidates.
|
||||
* Author: Trenser
|
||||
* Created: 07-Apr-2026
|
||||
*/
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
@@ -15,6 +23,19 @@
|
||||
#include "FileManager.h"
|
||||
#include "ApplicationConfig.h"
|
||||
|
||||
/*
|
||||
* Function: createEmployee
|
||||
* Description: Creates a new employee of the specified type and designation, validates
|
||||
* email and phone, enforces authorization, and associates payroll.
|
||||
* Parameters:
|
||||
* employeeType - type of employee (HR, IT, Finance, Team, Talent Acquisition, General)
|
||||
* employeeDesignation - designation for general employees (Junior, Senior)
|
||||
* email - employee email address
|
||||
* name - employee name
|
||||
* phone - employee phone number
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
|
||||
{
|
||||
auto& employees = m_dataStore.getEmployees();
|
||||
@@ -113,6 +134,16 @@ void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType,
|
||||
m_dataStore.getPayrolls().emplace(std::make_pair(payroll->getId(), payroll));
|
||||
m_dataStore.getEmployees().emplace(std::make_pair(employee->getId(), employee));
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: deactivateEmployee
|
||||
* Description: Deactivates an employee account by setting its status to INACTIVE.
|
||||
* Prevents deactivation of Admin accounts.
|
||||
* Parameters:
|
||||
* id - unique identifier of the employee
|
||||
* Returns:
|
||||
* bool - true if deactivation succeeded, false otherwise
|
||||
*/
|
||||
bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
||||
{
|
||||
auto& authenticatedEmployee = m_dataStore.getAuthenticatedEmployee();
|
||||
@@ -131,6 +162,15 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: updateDesignation
|
||||
* Description: Updates the designation of a general employee.
|
||||
* Parameters:
|
||||
* id - unique identifier of the employee
|
||||
* designation - new designation to assign
|
||||
* Returns:
|
||||
* bool - true if update succeeded, false otherwise
|
||||
*/
|
||||
bool EmployeeManagementService::updateDesignation(const std::string& id, Enums::EmployeeDesignation designation)
|
||||
{
|
||||
auto& authenticatedEmployee = m_dataStore.getAuthenticatedEmployee();
|
||||
@@ -149,11 +189,28 @@ bool EmployeeManagementService::updateDesignation(const std::string& id, Enums::
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: getCurrentEmployee
|
||||
* Description: Retrieves the currently authenticated employee from the DataStore.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* const Employee* - pointer to the current employee
|
||||
*/
|
||||
const Employee* EmployeeManagementService::getCurrentEmployee()
|
||||
{
|
||||
return m_dataStore.getAuthenticatedEmployee();
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: updateProfile
|
||||
* Description: Updates the name and phone number of the currently authenticated employee.
|
||||
* Parameters:
|
||||
* name - new employee name
|
||||
* phone - new employee phone number
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
void EmployeeManagementService::updateProfile(const std::string& name,const std::string& phone)
|
||||
{
|
||||
Employee* employee = m_dataStore.getAuthenticatedEmployee();
|
||||
@@ -161,6 +218,15 @@ void EmployeeManagementService::updateProfile(const std::string& name,const std:
|
||||
employee->setEmployeePhone(phone);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: searchEmployee
|
||||
* Description: Searches employees by name and returns matches along
|
||||
* with the type of the current authenticated employee.
|
||||
* Parameters:
|
||||
* name - search string for employee name
|
||||
* Returns:
|
||||
* pair<Enums::EmployeeType, vector<const Employee*>> - current user type and matching employees
|
||||
*/
|
||||
std::pair<Enums::EmployeeType, std::vector<const Employee*>> EmployeeManagementService::searchEmployee(const std::string& name)
|
||||
{
|
||||
Employee* currentUser = m_dataStore.getAuthenticatedEmployee();
|
||||
@@ -189,6 +255,36 @@ std::pair<Enums::EmployeeType, std::vector<const Employee*>> EmployeeManagementS
|
||||
return { employeeType, employeeList };
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: getShorlistedCandidates
|
||||
* Description: Retrieves candidates with status SHORTLISTED from the DataStore.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* vector<Candidate*> - list of shortlisted candidates
|
||||
*/
|
||||
std::vector<Candidate*> EmployeeManagementService::getShorlistedCandidates()
|
||||
{
|
||||
candidateMap candidates = m_dataStore.getCandidates();
|
||||
std::vector<Candidate*> shortlistedCandidates;
|
||||
for (auto& candidate : candidates)
|
||||
{
|
||||
if (candidate.second->getCandidateStatus() == Enums::CandidateStatus::SHORTLISTED)
|
||||
{
|
||||
shortlistedCandidates.push_back(candidate.second);
|
||||
}
|
||||
}
|
||||
return shortlistedCandidates;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: loadEmployees
|
||||
* Description: Loads employees and general employees from FileManager into the DataStore.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
void EmployeeManagementService::loadEmployees()
|
||||
{
|
||||
FileManager<Employee> employeeFileManager(Config::File::EMPLOYEES_FILE);
|
||||
@@ -214,6 +310,14 @@ void EmployeeManagementService::loadEmployees()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: saveEmployees
|
||||
* Description: Saves employees and general employees from the DataStore into FileManager.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
void EmployeeManagementService::saveEmployees()
|
||||
{
|
||||
FileManager<Employee> employeeFileManager(Config::File::EMPLOYEES_FILE);
|
||||
@@ -235,17 +339,3 @@ void EmployeeManagementService::saveEmployees()
|
||||
employeeFileManager.save(employees);
|
||||
generalEmployeeFileManager.save(generalEmployees);
|
||||
}
|
||||
|
||||
std::vector<Candidate*> EmployeeManagementService::getShorlistedCandidates()
|
||||
{
|
||||
candidateMap candidates = m_dataStore.getCandidates();
|
||||
std::vector<Candidate*> shortlistedCandidates;
|
||||
for (auto& candidate : candidates)
|
||||
{
|
||||
if (candidate.second->getCandidateStatus() == Enums::CandidateStatus::SHORTLISTED)
|
||||
{
|
||||
shortlistedCandidates.push_back(candidate.second);
|
||||
}
|
||||
}
|
||||
return shortlistedCandidates;
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* File: EmployeeManagementService.h
|
||||
* Description: Provides services for managing employees, including creation, deactivation,
|
||||
* designation updates, profile modifications, searching, and retrieval of
|
||||
* shortlisted candidates.
|
||||
* Author: Trenser
|
||||
* Created: 07-Apr-2026
|
||||
*/
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
@@ -25,6 +33,15 @@ public:
|
||||
void loadEmployees();
|
||||
void saveEmployees();
|
||||
|
||||
/*
|
||||
* Function: getEmployees (template)
|
||||
* Description: Retrieves active employees filtered by specified types. Excludes admin employees
|
||||
* if no filter is provided.
|
||||
* Parameters:
|
||||
* types... - variadic list of employee types
|
||||
* Returns:
|
||||
* Employees - vector of pointers to filtered employees
|
||||
*/
|
||||
template<typename... Types>
|
||||
Employees getEmployees(Types... types)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,15 @@
|
||||
#include "Factory.h"
|
||||
#include "DataStore.h"
|
||||
|
||||
/*
|
||||
* Function: log
|
||||
* Description: Creates a new log entry with the given message, assigns a timestamp,
|
||||
* and stores it in the DataStore.
|
||||
* Parameters:
|
||||
* message - string containing the log message to be recorded
|
||||
* Returns:
|
||||
* void - no return value
|
||||
*/
|
||||
void LogService::log(const std::string& message)
|
||||
{
|
||||
DataStore& dataStore = DataStore::getInstance();
|
||||
|
||||
@@ -13,6 +13,20 @@
|
||||
#include "FileManager.h"
|
||||
#include "Factory.h"
|
||||
|
||||
/*
|
||||
* Function: updateSalary
|
||||
* Description: Updates the payroll details of a given employee, including salary components
|
||||
* and PF contributions.
|
||||
* Parameters:
|
||||
* employeeId - unique identifier of the employee
|
||||
* basicSalary - basic salary of the employee
|
||||
* houseRentAllowance - HRA component
|
||||
* foodAllowance - food allowance component
|
||||
* employeePFContribution - employee PF contribution
|
||||
* employerPFContribution - employer PF contribution
|
||||
* Returns:
|
||||
* void - throws runtime_error if employee not found or unauthorized
|
||||
*/
|
||||
void PayslipManagementService::updateSalary(const std::string& employeeId, double basicSalary, double houseRentAllowance, double foodAllowance, double employeePFContribution, double employerPFContribution)
|
||||
{
|
||||
util::enforceAuthorization(m_dataStore.getAuthenticatedEmployee()->getEmployeeType(), Enums::EmployeeType::FINANCE);
|
||||
@@ -32,6 +46,14 @@ void PayslipManagementService::updateSalary(const std::string& employeeId, doubl
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: generatePayslips
|
||||
* Description: Generates payslips for all employees for the current month and year.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* void - creates and stores payslips in DataStore
|
||||
*/
|
||||
void PayslipManagementService::generatePayslips()
|
||||
{
|
||||
util::enforceAuthorization(m_dataStore.getAuthenticatedEmployee()->getEmployeeType(), Enums::EmployeeType::FINANCE);
|
||||
@@ -68,6 +90,15 @@ void PayslipManagementService::generatePayslips()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: loadPayrolls
|
||||
* Description: Loads payroll objects from persistent storage and associates them
|
||||
* with existing employees.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* void - updates DataStore with loaded payrolls
|
||||
*/
|
||||
void PayslipManagementService::loadPayrolls()
|
||||
{
|
||||
FileManager<Payroll> payrollFileManager(Config::File::PAYROLL_FILE);
|
||||
@@ -86,6 +117,14 @@ void PayslipManagementService::loadPayrolls()
|
||||
payrolls.insert(payrollObjects.begin(), payrollObjects.end());
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: savePayrolls
|
||||
* Description: Saves all payroll objects from DataStore into persistent storage.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
void PayslipManagementService::savePayrolls()
|
||||
{
|
||||
FileManager<Payroll> payrollFileManager(Config::File::PAYROLL_FILE);
|
||||
@@ -93,6 +132,17 @@ void PayslipManagementService::savePayrolls()
|
||||
payrollFileManager.save(payrolls);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: getPayslipForMonth
|
||||
* Description: Retrieves the payroll and payslip of a given employee for a specific
|
||||
* month and year.
|
||||
* Parameters:
|
||||
* employeeId - unique identifier of the employee
|
||||
* year - year of the payslip
|
||||
* month - month of the payslip
|
||||
* Returns:
|
||||
* pair<Payroll*, Payslip*> - payroll and payslip for the given month.
|
||||
*/
|
||||
std::pair<Payroll*, Payslip*> PayslipManagementService::getPayslipForMonth(const std::string& employeeId, int year, int month)
|
||||
{
|
||||
auto& employees = m_dataStore.getEmployees();
|
||||
@@ -116,6 +166,15 @@ std::pair<Payroll*, Payslip*> PayslipManagementService::getPayslipForMonth(const
|
||||
return { nullptr, nullptr };
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: loadPayslips
|
||||
* Description: Loads payslip objects from FileManager and associates them
|
||||
* with existing employees.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* void - updates DataStore with loaded payslips
|
||||
*/
|
||||
void PayslipManagementService::loadPayslips()
|
||||
{
|
||||
FileManager<Payslip> payslipFileManager(Config::File::PAYSLIP_FILE);
|
||||
@@ -134,6 +193,14 @@ void PayslipManagementService::loadPayslips()
|
||||
payslips.insert(payslipObjects.begin(), payslipObjects.end());
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: savePayslips
|
||||
* Description: Saves all payslip objects from DataStore into FileManager.
|
||||
* Parameters:
|
||||
* None
|
||||
* Returns:
|
||||
* void
|
||||
*/
|
||||
void PayslipManagementService::savePayslips()
|
||||
{
|
||||
FileManager<Payslip> payslipFileManager(Config::File::PAYSLIP_FILE);
|
||||
|
||||
@@ -1,14 +1,40 @@
|
||||
/*
|
||||
* File: AuthorizationHelper.h
|
||||
* Description : Provides utility functions to check and enforce authorization
|
||||
* based on allowed employee types.
|
||||
* Author : Trenser
|
||||
* Created : 07-Apr-2026
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdexcept>
|
||||
#include "Enums.h"
|
||||
|
||||
namespace util
|
||||
{
|
||||
/*
|
||||
* Function: isAuthorized
|
||||
* Description: Checks if the current employee type matches the specified allowed type.
|
||||
* Parameters:
|
||||
* current - the employee type of the current user
|
||||
* first - the allowed employee type to compare against
|
||||
* Returns:
|
||||
* bool - true if current matches the allowed type, false otherwise
|
||||
*/
|
||||
inline bool isAuthorized(Enums::EmployeeType current, Enums::EmployeeType first)
|
||||
{
|
||||
return current == first;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: isAuthorized
|
||||
* Description: Checks if the current employee type matches any of the specified allowed types.
|
||||
* Parameters:
|
||||
* current - the employee type of the current user
|
||||
* first - the first allowed employee type
|
||||
* rest - additional allowed employee types
|
||||
* Returns:
|
||||
* bool - true if current matches any of the allowed types, false otherwise
|
||||
*/
|
||||
template <typename... Rest>
|
||||
inline bool isAuthorized(Enums::EmployeeType current, Enums::EmployeeType first,
|
||||
Rest... rest)
|
||||
@@ -20,6 +46,16 @@ namespace util
|
||||
return isAuthorized(current, rest...);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: enforceAuthorization
|
||||
* Description: Enforces authorization by checking if the current employee type
|
||||
* is among the allowed types.
|
||||
* Parameters:
|
||||
* current - the employee type of the current user
|
||||
* alloweds - one or more allowed employee types
|
||||
* Returns:
|
||||
* void - throws runtime_error if current is not authorized
|
||||
*/
|
||||
template <typename... Allowed>
|
||||
inline void enforceAuthorization(Enums::EmployeeType current, Allowed... allowed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user