Add function headers in Controller, DataStore, and Utilities

This commit is contained in:
2026-04-17 10:27:27 +05:30
parent a0c499d78f
commit a8d50c29f8
12 changed files with 390 additions and 109 deletions
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created : 01-Apr-2026 * Created : 01-Apr-2026
*/ */
#include "ZenvyController.h" #include "ZenvyController.h"
/* /*
@@ -25,14 +24,13 @@ AuthenticationDTO ZenvyController::login(const std::string& email, const std::st
} }
/* /*
* Function: changePassword * Function: logout
* Description: updates the password of the currently authenticated employee. * Description: logs out the currently authenticated employee
* Parameters: * Parameters:
* password - the new password to be set for the employee * None
* Returns: * Returns:
* void - no return value * void - no return value
*/ */
void ZenvyController::logout() void ZenvyController::logout()
{ {
m_authenticationManagementService->logout(); m_authenticationManagementService->logout();
@@ -40,65 +38,153 @@ void ZenvyController::logout()
/* /*
* Function: changePassword * Function: changePassword
* Description: updates the password of the currently authenticated employee. * Description: updates the password of the currently authenticated employee
* Parameters: * Parameters:
* password - the new password to be set for the employee * password - the new password to be set for the employee
* Returns: * Returns:
* void - no return value * void - no return value
*/ */
void ZenvyController::changePassword(const std::string& password) void ZenvyController::changePassword(const std::string& password)
{ {
m_authenticationManagementService->changePassword(password); m_authenticationManagementService->changePassword(password);
} }
//Employee Management /*
* Function: createEmployee
* Description: creates a new employee with the given details
* Parameters:
* employeeType - type of employee to be created
* employeeDesignation - designation of the employee
* email - email address of the employee
* name - name of the employee
* phone - phone number of the employee
* Returns:
* void - no return value
*/
void ZenvyController::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone) const 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);
} }
/*
* Function: deactivateEmployee
* Description: deactivates an employee based on employee ID
* Parameters:
* id - unique employee ID
* Returns:
* bool - true if deactivated successfully, false otherwise
*/
bool ZenvyController::deactivateEmployee(const std::string& id) const bool ZenvyController::deactivateEmployee(const std::string& id) const
{ {
return m_employeeManagementService->deactivateEmployee(id); return m_employeeManagementService->deactivateEmployee(id);
} }
/*
* Function: updateProfile
* Description: updates the profile of the currently authenticated employee
* Parameters:
* name - updated name of the employee
* phone - updated phone number
* Returns:
* void - no return value
*/
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);
} }
/*
* Function: searchEmployee
* Description: searches employees based on name
* Parameters:
* name - name or partial name of the employee
* Returns:
* Pair of employee type and list of matching employees
*/
std::pair<Enums::EmployeeType, std::vector<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);
} }
/*
* Function: getCurrentEmployee
* Description: retrieves the currently authenticated employee
* Parameters:
* None
* Returns:
* Pointer to the authenticated employee
*/
const Employee* ZenvyController::getCurrentEmployee() const const Employee* ZenvyController::getCurrentEmployee() const
{ {
return m_employeeManagementService->getCurrentEmployee(); return m_employeeManagementService->getCurrentEmployee();
} }
/*
* Function: updateDesignation
* Description: updates the designation of an employee
* Parameters:
* id - unique employee ID
* designation - new designation to be assigned
* Returns:
* bool - true if update is successful, false otherwise
*/
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);
} }
/*
* Function: getShorlistedCandidates
* Description: retrieves the list of shortlisted candidates
* Parameters:
* None
* Returns:
* Vector of shortlisted candidate pointers
*/
std::vector<Candidate*> ZenvyController::getShorlistedCandidates() const std::vector<Candidate*> ZenvyController::getShorlistedCandidates() const
{ {
return m_employeeManagementService->getShorlistedCandidates(); return m_employeeManagementService->getShorlistedCandidates();
} }
//Payslip Management /*
* Function: updateSalary
* Description: updates salary details of an employee
* Parameters:
* employeeId - unique employee ID
* basicSalary - basic salary amount
* houseRentAllowance - HRA amount
* foodAllowance - food allowance amount
* employeePFContribution - employee PF contribution
* employerPFContribution - employer PF contribution
* Returns:
* void - no return value
*/
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);
} }
/*
* Function: generatePayslips
* Description: generates payslips for all eligible employees
* Parameters:
* None
* Returns:
* void - no return value
*/
void ZenvyController::generatePayslips() void ZenvyController::generatePayslips()
{ {
m_payslipManagementService->generatePayslips(); m_payslipManagementService->generatePayslips();
} }
/*
* Function: loadStates
* Description: loads persisted application data into memory
* Parameters:
* None
* Returns:
* void - no return value
*/
void ZenvyController::loadStates() void ZenvyController::loadStates()
{ {
m_employeeManagementService->loadEmployees(); m_employeeManagementService->loadEmployees();
@@ -106,6 +192,14 @@ void ZenvyController::loadStates()
m_payslipManagementService->loadPayslips(); m_payslipManagementService->loadPayslips();
} }
/*
* Function: persistStates
* Description: saves current application data to storage
* Parameters:
* None
* Returns:
* void - no return value
*/
void ZenvyController::persistStates() void ZenvyController::persistStates()
{ {
m_employeeManagementService->saveEmployees(); m_employeeManagementService->saveEmployees();
@@ -113,11 +207,29 @@ void ZenvyController::persistStates()
m_payslipManagementService->savePayslips(); m_payslipManagementService->savePayslips();
} }
/*
* Function: getPayslipForMonth
* Description: retrieves payroll and payslip details for a specific month
* Parameters:
* employeeId - unique employee ID
* year - year of the payslip
* month - month of the payslip
* Returns:
* Pair of payroll and payslip pointers
*/
std::pair<Payroll*, 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);
} }
/*
* Function: ~ZenvyController
* Description: cleans up dynamically allocated service objects
* Parameters:
* None
* Returns:
* void - no return value
*/
ZenvyController::~ZenvyController() ZenvyController::~ZenvyController()
{ {
delete m_authenticationManagementService; delete m_authenticationManagementService;
@@ -16,7 +16,6 @@
* 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;
@@ -31,7 +30,6 @@ DataStore& DataStore::getInstance()
* Returns: * Returns:
* logMap& - reference to the log map. * logMap& - reference to the log map.
*/ */
logMap& DataStore::getLogs() logMap& DataStore::getLogs()
{ {
return m_logs; return m_logs;
@@ -39,13 +37,12 @@ logMap& DataStore::getLogs()
/* /*
* Function: getAuthenticatedEmployee * Function: getAuthenticatedEmployee
* Description: returns the currently authenticated employee. * Description: retrieves the currently authenticated employee.
* Parameters: * Parameters:
* None * None
* Returns: * Returns:
* std::shared_ptr<Employee>& - reference to the authenticated employee object. * Employee*& - reference to the authenticated employee pointer.
*/ */
Employee*& DataStore::getAuthenticatedEmployee() Employee*& DataStore::getAuthenticatedEmployee()
{ {
return m_authenticatedEmployee; return m_authenticatedEmployee;
@@ -55,11 +52,10 @@ Employee*& DataStore::getAuthenticatedEmployee()
* Function: setAuthenticatedEmployee * Function: setAuthenticatedEmployee
* Description: sets the currently authenticated employee. * Description: sets the currently authenticated employee.
* Parameters: * Parameters:
* authenticatedEmployee - shared pointer to the employee object to be set as authenticated. * authenticatedEmployee - pointer to the employee to be set as authenticated.
* Returns: * Returns:
* void - no return value. * void - no return value.
*/ */
void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee) void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee)
{ {
m_authenticatedEmployee = authenticatedEmployee; m_authenticatedEmployee = authenticatedEmployee;
@@ -67,33 +63,64 @@ void DataStore::setAuthenticatedEmployee(Employee* authenticatedEmployee)
/* /*
* Function: getEmployees * Function: getEmployees
* Description: retrieves the employee map containing all employees. * Description: retrieves the map containing all employees.
* Parameters: * Parameters:
* None * None
* Returns: * Returns:
* employeeMap& - reference to the employee map. * employeeMap& - reference to the employee map.
*/ */
employeeMap& DataStore::getEmployees() employeeMap& DataStore::getEmployees()
{ {
return m_employees; return m_employees;
} }
/*
* Function: getPayrolls
* Description: retrieves the map containing all payroll records.
* Parameters:
* None
* Returns:
* payrollMap& - reference to the payroll map.
*/
payrollMap& DataStore::getPayrolls() payrollMap& DataStore::getPayrolls()
{ {
return m_payrolls; return m_payrolls;
} }
/*
* Function: getPayslips
* Description: retrieves the map containing all payslip records.
* Parameters:
* None
* Returns:
* payslipMap& - reference to the payslip map.
*/
payslipMap& DataStore::getPayslips() payslipMap& DataStore::getPayslips()
{ {
return m_payslips; return m_payslips;
} }
/*
* Function: getCandidates
* Description: retrieves the map containing all shortlisted candidates.
* Parameters:
* None
* Returns:
* candidateMap& - reference to the candidate map.
*/
candidateMap& DataStore::getCandidates() candidateMap& DataStore::getCandidates()
{ {
return m_candidates; return m_candidates;
} }
/*
* Function: ~DataStore
* Description: releases all dynamically allocated objects stored in the DataStore.
* Parameters:
* None
* Returns:
* void - no return value.
*/
DataStore::~DataStore() DataStore::~DataStore()
{ {
for (auto& pair : m_employees) for (auto& pair : m_employees)
@@ -1,7 +1,7 @@
/* /*
* File: Factory.h * File: Factory.h
* Description: Provides a generic factory utility to create shared_ptr instances of objects. * Description: Provides a generic factory utility to create objects.
* Author: Ajmal J S * Author: Trenser
* Created: 01-Apr-2026 * Created: 01-Apr-2026
*/ */
@@ -14,13 +14,13 @@ public:
/* /*
* Function: getObject * Function: getObject
* Description: Creates and returns a shared_ptr to an object of type T. * Description: Creates and returns a dynamically allocated object of type T.
* Parameters: * Parameters:
* T - the type of object to be created * T - the type of object to be created
* 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 * T* - pointer to the newly created object
*/; */
template<typename T, typename... Args> template<typename T, typename... Args>
static T* getObject(Args&&... args) static T* getObject(Args&&... args)
{ {
+89 -2
View File
@@ -116,6 +116,14 @@ namespace Enums {
INVALID INVALID
}; };
/*
* Function: getAccountStatusString
* Description: Converts AccountStatus enum value to string.
* Parameters:
* status - account status enum
* Returns:
* std::string - string representation of status
*/
inline std::string getAccountStatusString(AccountStatus status) inline std::string getAccountStatusString(AccountStatus status)
{ {
switch (status) switch (status)
@@ -129,6 +137,14 @@ namespace Enums {
} }
} }
/*
* Function: getEmployeeTypeString
* Description: Converts EmployeeType enum value to string.
* Parameters:
* type - employee type enum
* Returns:
* std::string - string representation of employee type
*/
inline std::string getEmployeeTypeString(EmployeeType type) inline std::string getEmployeeTypeString(EmployeeType type)
{ {
switch (type) switch (type)
@@ -154,6 +170,14 @@ namespace Enums {
} }
} }
/*
* Function: getTeamStatusString
* Description: Converts TeamStatus enum value to string.
* Parameters:
* status - team status enum
* Returns:
* std::string - string representation of team status
*/
inline std::string getTeamStatusString(TeamStatus status) inline std::string getTeamStatusString(TeamStatus status)
{ {
switch (status) switch (status)
@@ -167,6 +191,14 @@ namespace Enums {
} }
} }
/*
* Function: getEmployeeDesignationString
* Description: Converts EmployeeDesignation enum value to string.
* Parameters:
* designation - employee designation enum
* Returns:
* std::string - string representation of designation
*/
inline std::string getEmployeeDesignationString(EmployeeDesignation designation) inline std::string getEmployeeDesignationString(EmployeeDesignation designation)
{ {
switch (designation) switch (designation)
@@ -184,6 +216,14 @@ namespace Enums {
} }
} }
/*
* Function: getCandidateStatusString
* Description: Converts CandidateStatus enum value to string.
* Parameters:
* status - candidate status enum
* Returns:
* std::string - string representation of candidate status
*/
inline std::string getCandidateStatusString(CandidateStatus status) inline std::string getCandidateStatusString(CandidateStatus status)
{ {
switch (status) switch (status)
@@ -195,11 +235,19 @@ namespace Enums {
} }
} }
/*
* Function: getMonthString
* Description: Converts Month enum value to month name.
* Parameters:
* month - month enum
* Returns:
* std::string - month name
*/
inline std::string getMonthString(Month month) inline std::string getMonthString(Month month)
{ {
switch (month) switch (month)
{ {
case Month::JANUARY : case Month::JANUARY:
return "January"; return "January";
case Month::FEBRUARY: case Month::FEBRUARY:
return "February"; return "February";
@@ -230,6 +278,14 @@ namespace Enums {
} }
} }
/*
* Function: getAccountStatus
* Description: Converts string to AccountStatus enum.
* Parameters:
* input - string representation of account status
* Returns:
* AccountStatus - enum value
*/
inline AccountStatus getAccountStatus(const std::string& input) inline AccountStatus getAccountStatus(const std::string& input)
{ {
if (input == "ACTIVE") if (input == "ACTIVE")
@@ -243,6 +299,14 @@ namespace Enums {
return AccountStatus::INACTIVE; return AccountStatus::INACTIVE;
} }
/*
* Function: getEmployeeType
* Description: Converts string to EmployeeType enum.
* Parameters:
* input - string representation of employee type
* Returns:
* EmployeeType - enum value
*/
inline EmployeeType getEmployeeType(const std::string& input) inline EmployeeType getEmployeeType(const std::string& input)
{ {
if (input == "GENERAL") if (input == "GENERAL")
@@ -276,6 +340,14 @@ namespace Enums {
return EmployeeType::INVALID; return EmployeeType::INVALID;
} }
/*
* Function: getTeamStatus
* Description: Converts string to TeamStatus enum.
* Parameters:
* str - string representation of team status
* Returns:
* TeamStatus - enum value
*/
inline TeamStatus getTeamStatus(const std::string& str) inline TeamStatus getTeamStatus(const std::string& str)
{ {
if (str == "IN_TEAM") if (str == "IN_TEAM")
@@ -289,6 +361,14 @@ namespace Enums {
return TeamStatus::NOT_IN_TEAM; return TeamStatus::NOT_IN_TEAM;
} }
/*
* Function: getEmployeeDesignation
* Description: Converts string to EmployeeDesignation enum.
* Parameters:
* input - string representation of designation
* Returns:
* EmployeeDesignation - enum value
*/
inline EmployeeDesignation getEmployeeDesignation(const std::string& input) inline EmployeeDesignation getEmployeeDesignation(const std::string& input)
{ {
if (input == "JUNIOR") if (input == "JUNIOR")
@@ -306,6 +386,14 @@ namespace Enums {
return EmployeeDesignation::INVALID; return EmployeeDesignation::INVALID;
} }
/*
* Function: getMonth
* Description: Converts integer to Month enum.
* Parameters:
* inputMonth - month number (112)
* Returns:
* Month - enum value
*/
inline Month getMonth(const int inputMonth) inline Month getMonth(const int inputMonth)
{ {
switch (inputMonth) switch (inputMonth)
@@ -340,4 +428,3 @@ namespace Enums {
} }
} }
@@ -4,7 +4,6 @@
* Author: Smitha * Author: Smitha
* Created: 08-Apr-2026 * Created: 08-Apr-2026
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <limits> #include <limits>
@@ -21,7 +20,6 @@ namespace util
* Returns: * Returns:
* void - throws runtime_error if input is invalid * void - throws runtime_error if input is invalid
*/ */
template <typename T> template <typename T>
inline void read(T& value) inline void read(T& value)
{ {
@@ -41,7 +39,6 @@ namespace util
* Returns: * Returns:
* void - no return value * void - no return value
*/ */
inline void read(std::string& value) inline void read(std::string& value)
{ {
std::getline(std::cin >> std::ws, value); std::getline(std::cin >> std::ws, value);
@@ -53,7 +50,6 @@ namespace util
* Parameters: None * Parameters: None
* Returns: void - no return value * Returns: void - no return value
*/ */
inline void pressEnter() inline void pressEnter()
{ {
std::cout << std::endl; std::cout << std::endl;
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 01-04-2026 * Created: 01-04-2026
*/ */
#include "outputHelper.h" #include "outputHelper.h"
/* /*
@@ -14,7 +13,6 @@
* Returns: * Returns:
* void - no return value * void - no return value
*/ */
void util::clear() void util::clear()
{ {
std::cout << "\x1B[2J\x1B[H" << std::flush; std::cout << "\x1B[2J\x1B[H" << std::flush;
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 01-04-2026 * Created: 01-04-2026
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
@@ -1,6 +1,20 @@
/*
* File: StringHelper.cpp
* Description: Provides functions to help with string manipulation.
* Author: Trenser
* Created: 10-04-2026
*/
#include "StringHelper.h" #include "StringHelper.h"
#include <cctype> #include <cctype>
/*
* Function: extractNumber
* Description: Extracts and returns the numeric value formed by digits in the input string.
* Parameters:
* input - string containing numeric and non-numeric characters
* Returns:
* int - number extracted from the input string
*/
int util::extractNumber(const std::string& input) int util::extractNumber(const std::string& input)
{ {
int result = 0; int result = 0;
@@ -1,3 +1,9 @@
/*
* File: StringHelper.h
* Description: Provides functions to help with string manipulation.
* Author: Trenser
* Created: 10-04-2026
*/
#pragma once #pragma once
#include <string> #include <string>
@@ -6,21 +6,19 @@
* Author: Trenser * Author: Trenser
* Created: 01-Apr-2026 * Created: 01-Apr-2026
*/ */
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <stdexcept> #include <stdexcept>
#include "Timestamp.h" #include "Timestamp.h"
/* /*
* Function: Timestamp * Function: Timestamp
* Description: Default constructor that initializes the timestamp to the current system time. * Description: Default constructor that initializes the timestamp to the current system time.
* Parameters: * Parameters:
* None * None
* Returns: * Returns:
* Timestamp object * Timestamp object
*/ */
util::Timestamp::Timestamp() util::Timestamp::Timestamp()
{ {
m_time = std::time(nullptr); m_time = std::time(nullptr);
@@ -34,7 +32,6 @@ util::Timestamp::Timestamp()
* Returns: * Returns:
* Timestamp object * Timestamp object
*/ */
util::Timestamp::Timestamp(std::time_t timeValue) util::Timestamp::Timestamp(std::time_t timeValue)
{ {
m_time = timeValue; m_time = timeValue;
@@ -50,7 +47,6 @@ util::Timestamp::Timestamp(std::time_t timeValue)
* Throws: * Throws:
* runtime_error if the string format is invalid * runtime_error if the string format is invalid
*/ */
util::Timestamp util::Timestamp::fromString(const std::string& timeString) util::Timestamp util::Timestamp::fromString(const std::string& timeString)
{ {
std::tm timeStruct = {}; std::tm timeStruct = {};
@@ -72,7 +68,6 @@ util::Timestamp util::Timestamp::fromString(const std::string& timeString)
* Returns: * Returns:
* string - formatted as "YYYY-MM-DD HH:MM:SS" * string - formatted as "YYYY-MM-DD HH:MM:SS"
*/ */
std::string util::Timestamp::toString() const std::string util::Timestamp::toString() const
{ {
std::tm timeStruct = {}; std::tm timeStruct = {};
@@ -91,7 +86,6 @@ std::string util::Timestamp::toString() const
* Returns: * Returns:
* double - duration in seconds * double - duration in seconds
*/ */
double util::Timestamp::getDurationInSeconds(const Timestamp& startTimestamp, const Timestamp& endTimestamp) double util::Timestamp::getDurationInSeconds(const Timestamp& startTimestamp, const Timestamp& endTimestamp)
{ {
return std::difftime(endTimestamp.m_time, startTimestamp.m_time); return std::difftime(endTimestamp.m_time, startTimestamp.m_time);
@@ -105,7 +99,6 @@ double util::Timestamp::getDurationInSeconds(const Timestamp& startTimestamp, co
* Returns: * Returns:
* int - date as YYYYMMDD * int - date as YYYYMMDD
*/ */
int util::Timestamp::getDateAsInt() const int util::Timestamp::getDateAsInt() const
{ {
std::tm timeStruct{}; std::tm timeStruct{};
@@ -116,6 +109,14 @@ int util::Timestamp::getDateAsInt() const
return year * 10000 + month * 100 + day; return year * 10000 + month * 100 + day;
} }
/*
* Function: getMonth
* Description: Extracts the month value from the timestamp.
* Parameters:
* None
* Returns:
* int - month value (1 to 12)
*/
int util::Timestamp::getMonth() const int util::Timestamp::getMonth() const
{ {
std::tm timeStruct{}; std::tm timeStruct{};
@@ -123,6 +124,14 @@ int util::Timestamp::getMonth() const
return timeStruct.tm_mon + 1; return timeStruct.tm_mon + 1;
} }
/*
* Function: getYear
* Description: Extracts the year value from the timestamp.
* Parameters:
* None
* Returns:
* int - year value
*/
int util::Timestamp::getYear() const int util::Timestamp::getYear() const
{ {
std::tm timeStruct{}; std::tm timeStruct{};
@@ -130,6 +139,14 @@ int util::Timestamp::getYear() const
return timeStruct.tm_year + 1900; return timeStruct.tm_year + 1900;
} }
/*
* Function: getDay
* Description: Extracts the day value from the timestamp.
* Parameters:
* None
* Returns:
* int - day of the month
*/
int util::Timestamp::getDay() const int util::Timestamp::getDay() const
{ {
std::tm timeStruct{}; std::tm timeStruct{};
@@ -146,7 +163,6 @@ int util::Timestamp::getDay() const
* Returns: * Returns:
* double - duration in minutes * double - duration in minutes
*/ */
double util::Timestamp::getDurationInMinutes(const Timestamp& startTimestamp, const Timestamp& endTimestamp) double util::Timestamp::getDurationInMinutes(const Timestamp& startTimestamp, const Timestamp& endTimestamp)
{ {
return getDurationInSeconds(startTimestamp, endTimestamp) / 60.0; return getDurationInSeconds(startTimestamp, endTimestamp) / 60.0;
@@ -161,7 +177,6 @@ double util::Timestamp::getDurationInMinutes(const Timestamp& startTimestamp, co
* Returns: * Returns:
* double - duration in hours * double - duration in hours
*/ */
double util::Timestamp::getDurationInHours(const Timestamp& startTimestamp, const Timestamp& endTimestamp) double util::Timestamp::getDurationInHours(const Timestamp& startTimestamp, const Timestamp& endTimestamp)
{ {
return getDurationInSeconds(startTimestamp, endTimestamp) / 3600.0; return getDurationInSeconds(startTimestamp, endTimestamp) / 3600.0;
@@ -175,7 +190,6 @@ double util::Timestamp::getDurationInHours(const Timestamp& startTimestamp, cons
* Returns: * Returns:
* bool - true if current timestamp is earlier * bool - true if current timestamp is earlier
*/ */
bool util::Timestamp::operator<(const Timestamp& other) const bool util::Timestamp::operator<(const Timestamp& other) const
{ {
return m_time < other.m_time; return m_time < other.m_time;
@@ -189,7 +203,6 @@ bool util::Timestamp::operator<(const Timestamp& other) const
* Returns: * Returns:
* bool - true if current timestamp is later * bool - true if current timestamp is later
*/ */
bool util::Timestamp::operator>(const Timestamp& other) const bool util::Timestamp::operator>(const Timestamp& other) const
{ {
return m_time > other.m_time; return m_time > other.m_time;
@@ -203,7 +216,6 @@ bool util::Timestamp::operator>(const Timestamp& other) const
* Returns: * Returns:
* bool - true if current timestamp is earlier or equal * bool - true if current timestamp is earlier or equal
*/ */
bool util::Timestamp::operator<=(const Timestamp& other) const bool util::Timestamp::operator<=(const Timestamp& other) const
{ {
return m_time <= other.m_time; return m_time <= other.m_time;
@@ -217,7 +229,6 @@ bool util::Timestamp::operator<=(const Timestamp& other) const
* Returns: * Returns:
* bool - true if current timestamp is later or equal * bool - true if current timestamp is later or equal
*/ */
bool util::Timestamp::operator>=(const Timestamp& other) const bool util::Timestamp::operator>=(const Timestamp& other) const
{ {
return m_time >= other.m_time; return m_time >= other.m_time;
@@ -231,7 +242,6 @@ bool util::Timestamp::operator>=(const Timestamp& other) const
* Returns: * Returns:
* bool - true if both timestamps are equal * bool - true if both timestamps are equal
*/ */
bool util::Timestamp::operator==(const Timestamp& other) const bool util::Timestamp::operator==(const Timestamp& other) const
{ {
return m_time == other.m_time; return m_time == other.m_time;
@@ -6,7 +6,6 @@
* Author: Trenser * Author: Trenser
* Created: 01-Apr-2026 * Created: 01-Apr-2026
*/ */
#pragma once #pragma once
#include <ctime> #include <ctime>
#include <string> #include <string>
@@ -11,7 +11,7 @@
#include "Employee.h" #include "Employee.h"
#include "ApplicationConfig.h" #include "ApplicationConfig.h"
/* /*
* Function: isPhoneNumberValid * Function: isPhoneNumberValid
* Description: Validates whether the given string is a valid phone number. * Description: Validates whether the given string is a valid phone number.
* Parameters: * Parameters:
@@ -19,7 +19,6 @@
* Returns: * Returns:
* bool - true if the phone number is valid (10 digits, all numeric), false otherwise * bool - true if the phone number is valid (10 digits, all numeric), false otherwise
*/ */
bool util::isPhoneNumberValid(const std::string& phoneNumber) { bool util::isPhoneNumberValid(const std::string& phoneNumber) {
if (phoneNumber.size() != 10) if (phoneNumber.size() != 10)
{ {
@@ -41,7 +40,6 @@ bool util::isPhoneNumberValid(const std::string& phoneNumber) {
* Returns: * Returns:
* bool - true if the email contains exactly one '@' character and is not at the start or end, false otherwise * bool - true if the email contains exactly one '@' character and is not at the start or end, false otherwise
*/ */
bool util::isEmailValid(const std::string& email) { bool util::isEmailValid(const std::string& email) {
size_t index = email.find('@'); size_t index = email.find('@');
if (index == std::string::npos) if (index == std::string::npos)
@@ -72,7 +70,6 @@ bool util::isEmailValid(const std::string& email) {
* - Must contain at least one uppercase letter, one lowercase letter, one digit, and one special character * - Must contain at least one uppercase letter, one lowercase letter, one digit, and one special character
* - Must not contain whitespace * - Must not contain whitespace
*/ */
bool util::isPasswordValid(const std::string& password) bool util::isPasswordValid(const std::string& password)
{ {
if (password == Config::Authentication::DEFAULT_PASSWORD) if (password == Config::Authentication::DEFAULT_PASSWORD)
@@ -112,7 +109,16 @@ 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, Employee*> & employees) /*
* Function: hasActiveEmployeeOfType
* Description: Checks whether there is any active employee of the given employee type.
* Parameters:
* employeeType - the type of employee to check against
* employees - map of employee ID to Employee* objects
* Returns:
* bool - true if an active employee of the given type exists, otherwise false
*/
bool util::hasActiveEmployeeOfType(Enums::EmployeeType employeeType, const std::map<std::string, Employee*>& employees)
{ {
for (const auto& employeePair : employees) for (const auto& employeePair : employees)
{ {
@@ -125,6 +131,15 @@ bool util::hasActiveEmployeeOfType(Enums::EmployeeType employeeType, const std::
return false; return false;
} }
/*
* Function: isEmailDuplicate
* Description: Checks if an email already exists among the given employees.
* Parameters:
* email - the email address to check
* employees - map of employee ID to Employee* objects
* Returns:
* bool - true if a duplicate email is found, otherwise false
*/
bool util::isEmailDuplicate(const std::string& email, const std::map<std::string, 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,6 +153,15 @@ bool util::isEmailDuplicate(const std::string& email, const std::map<std::string
return false; return false;
} }
/*
* Function: isPhoneDuplicate
* Description: Checks if a phone number already exists among the given employees.
* Parameters:
* phone - the phone number to check
* employees - map of employee ID to Employee* objects
* Returns:
* bool - true if a duplicate phone number is found, otherwise false
*/
bool util::isPhoneDuplicate(const std::string& phone, const std::map<std::string, 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,6 +175,15 @@ bool util::isPhoneDuplicate(const std::string& phone, const std::map<std::string
return false; return false;
} }
/*
* Function: isPhoneDuplicate (overloaded)
* Description: Checks if a phone number already exists in a vector of employees.
* Parameters:
* phone - the phone number to check
* employees - vector of Employee* pointers
* Returns:
* bool - true if a duplicate phone number is found, otherwise false
*/
bool util::isPhoneDuplicate(const std::string& phone, const std::vector<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)