Add file and function header documentation across Controller, DataStore and Utility files

This commit is contained in:
Ajmal Jalaludeen
2026-04-08 17:27:22 +05:30
parent 21549b4c24
commit 2757e5ca98
13 changed files with 377 additions and 2 deletions
@@ -1,16 +1,53 @@
/*
* File: ZenvyController.cpp
* Description : Controls data flow between UI and Service Layers.
* Author: Trenser
* Created : 01-04-2026
*/
#include "ZenvyController.h" #include "ZenvyController.h"
//Authentication /*
* Function: login
* Description: authenticates the employee based on email and password
* Parameters:
* email - email of the employee
* password - password of the employee
* Returns:
* Tuple - login status, employee type, employee designation
* login status - success or failed
* employee type - type of the employee logged in
* 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);
} }
/*
* Function: changePassword
* Description: updates the password of the currently authenticated employee.
* Parameters:
* password - the new password to be set for the employee
* Returns:
* void - no return value
*/
void ZenvyController::logout() void ZenvyController::logout()
{ {
m_authenticationManagementService->logout(); m_authenticationManagementService->logout();
} }
/*
* Function: changePassword
* Description: updates the password of the currently authenticated employee.
* Parameters:
* password - the new password to be set for the employee
* Returns:
* 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);
@@ -1,3 +1,10 @@
/*
* File: ZenvyController.h
* Description : Controls data flow between UI and Service Layers.
* Author: Trenser
* Created : 01-04-2026
*/
#pragma once #pragma once
#include <memory> #include <memory>
#include <utility> #include <utility>
@@ -1,31 +1,92 @@
/*
* File: DataStore.cpp
* Description: Central Storage for all the System Data.
* Author: Trenser
* Created: 01-04-2026
*/
#include "DataStore.h" #include "DataStore.h"
/*
* Function: getInstance
* Description: provides a singleton instance of the DataStore.
* Parameters:
* None
* Returns:
* DataStore& - reference to the single DataStore object.
*/
DataStore& DataStore::getInstance() DataStore& DataStore::getInstance()
{ {
static DataStore dataStore; static DataStore dataStore;
return dataStore; return dataStore;
} }
/*
* Function: getLogs
* Description: retrieves the log map containing system logs.
* Parameters:
* None
* Returns:
* logMap& - reference to the log map.
*/
logMap& DataStore::getLogs() logMap& DataStore::getLogs()
{ {
return m_logs; return m_logs;
} }
/*
* Function: getAuthenticatedEmployee
* Description: returns the currently authenticated employee.
* Parameters:
* None
* Returns:
* std::shared_ptr<Employee>& - reference to the authenticated employee object.
*/
std::shared_ptr<Employee>& DataStore::getAuthenticatedEmployee() std::shared_ptr<Employee>& DataStore::getAuthenticatedEmployee()
{ {
return m_authenticatedEmployee; return m_authenticatedEmployee;
} }
/*
* Function: setAuthenticatedEmployee
* Description: sets the currently authenticated employee.
* Parameters:
* authenticatedEmployee - shared pointer to the employee object to be set as authenticated.
* Returns:
* void - no return value.
*/
void DataStore::setAuthenticatedEmployee(std::shared_ptr<Employee> authenticatedEmployee) void DataStore::setAuthenticatedEmployee(std::shared_ptr<Employee> authenticatedEmployee)
{ {
m_authenticatedEmployee = authenticatedEmployee; m_authenticatedEmployee = authenticatedEmployee;
} }
/*
* Function: getEmployees
* Description: retrieves the employee map containing all employees.
* Parameters:
* None
* Returns:
* employeeMap& - reference to the employee map.
*/
employeeMap& DataStore::getEmployees() employeeMap& DataStore::getEmployees()
{ {
return m_employees; return m_employees;
} }
/*
* Function: getAuthenticatedUser
* Description: alias for getAuthenticatedEmployee, returns the currently authenticated employee.
* Parameters:
* None
* Returns:
* std::shared_ptr<Employee>& - reference to the authenticated employee object.
*/
std::shared_ptr<Employee>& DataStore::getAuthenticatedUser() std::shared_ptr<Employee>& DataStore::getAuthenticatedUser()
{ {
return m_authenticatedEmployee; return m_authenticatedEmployee;
@@ -1,3 +1,10 @@
/*
* File: DataStore.h
* Description: Central Storage for all the System Data.
* Author: Trenser
* Created: 01-04-2026
*/
#pragma once #pragma once
#include <memory> #include <memory>
#include <map> #include <map>
@@ -1,3 +1,10 @@
/*
* File: Factory.h
* Description: Provides a generic factory utility to create shared_ptr instances of objects.
* Author: Ajmal J S
* Created: 01-04-2026
*/
#pragma once #pragma once
#include <memory> #include <memory>
#include <utility> #include <utility>
@@ -5,6 +12,17 @@
class Factory class Factory
{ {
public: public:
/*
* Function: getObject
* Description: Creates and returns a shared_ptr to an object of type T.
* Parameters:
* T - the type of object to be created
* Args - constructor arguments forwarded to T's constructor
* Returns:
* std::shared_ptr<T> - a shared pointer managing the newly created object
*/
template<typename T, typename... Args> template<typename T, typename... Args>
static std::shared_ptr<T> getObject(Args&&... args) static std::shared_ptr<T> getObject(Args&&... args)
{ {
@@ -1,3 +1,10 @@
/*
* File: Enums.h
* Description: Defines strongly typed enumerations for statuses, types, and designations used across the HRMS system.
* Author: Smitha
* Created: 01-04-2026
*/
#pragma once #pragma once
namespace Enums { namespace Enums {
@@ -1,5 +1,11 @@
#pragma once /*
* File: InputHelper.h
* Description: Handles input validation and error handling
* Author: Smitha
* Created: 08-Apr-2026
*/
#pragma once
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <string> #include <string>
@@ -7,6 +13,15 @@
namespace util namespace util
{ {
/*
* Function: read
* Description: Reads input from console into a variable of type T.
* Parameters:
* value - reference to a variable of type T where the input will be stored
* Returns:
* void - throws runtime_error if input is invalid
*/
template <typename T> template <typename T>
inline void read(T& value) inline void read(T& value)
{ {
@@ -18,11 +33,27 @@ namespace util
} }
} }
/*
* Function: read
* Description: Reads a line of text input from console into a string.
* Parameters:
* value - reference to a string where the input will be stored
* Returns:
* 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);
} }
/*
* Function: pressEnter
* Description: Pauses execution until the user presses Enter.
* Parameters: None
* Returns: void - no return value
*/
inline void pressEnter() inline void pressEnter()
{ {
system("pause"); system("pause");
@@ -1,5 +1,20 @@
/*
* File: OutputHelper.cpp
* Description: Provides functions to help with console output.
* Author: Trenser
* Created: 01-04-2026
*/
#include "outputHelper.h" #include "outputHelper.h"
/*
* Function: clear
* Description: Clears the console screen output.
* Parameters: None
* Returns:
* 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;
@@ -1,3 +1,10 @@
/*
* File: OutputHelper.h
* Description: Provides functions to help with console output.
* Author: Trenser
* Created: 01-04-2026
*/
#pragma once #pragma once
#include <iostream> #include <iostream>
@@ -1,18 +1,56 @@
/*
* File: Timestamp.cpp
* Description: Provides a utility class for representing and manipulating time values.
* Supports conversion between string and time formats, duration calculations
* (hours, minutes, seconds), date extraction, and comparison operators.
* Author: Trenser
* Created: 01-Apr-2026
*/
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <stdexcept> #include <stdexcept>
#include "Timestamp.h" #include "Timestamp.h"
/*
* Function: Timestamp
* Description: Default constructor that initializes the timestamp to the current system time.
* Parameters:
* None
* Returns:
* Timestamp object
*/
util::Timestamp::Timestamp() util::Timestamp::Timestamp()
{ {
m_time = std::time(nullptr); m_time = std::time(nullptr);
} }
/*
* Function: Timestamp (overloaded)
* Description: Constructor that initializes the timestamp with a given time value.
* Parameters:
* timeValue - time_t value representing a specific time
* Returns:
* Timestamp object
*/
util::Timestamp::Timestamp(std::time_t timeValue) util::Timestamp::Timestamp(std::time_t timeValue)
{ {
m_time = timeValue; m_time = timeValue;
} }
/*
* Function: fromString
* Description: Creates a Timestamp object from a formatted string.
* Parameters:
* timeString - string in the format "YYYY-MM-DD HH:MM:SS"
* Returns:
* Timestamp object representing the parsed time
* Throws:
* 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 = {};
@@ -26,6 +64,15 @@ util::Timestamp util::Timestamp::fromString(const std::string& timeString)
return Timestamp(parsedTimestamp); return Timestamp(parsedTimestamp);
} }
/*
* Function: toString
* Description: Converts the Timestamp object into a formatted string.
* Parameters:
* None
* Returns:
* 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 = {};
@@ -35,11 +82,30 @@ std::string util::Timestamp::toString() const
return outputStream.str(); return outputStream.str();
} }
/*
* Function: getDurationInSeconds
* Description: Calculates the duration between two timestamps in seconds.
* Parameters:
* startTimestamp - starting time
* endTimestamp - ending time
* Returns:
* 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);
} }
/*
* Function: getDateAsInt
* Description: Returns the date portion of the timestamp as an integer in YYYYMMDD format.
* Parameters:
* None
* Returns:
* int - date as YYYYMMDD
*/
int util::Timestamp::getDateAsInt() const int util::Timestamp::getDateAsInt() const
{ {
std::tm timeStruct{}; std::tm timeStruct{};
@@ -50,36 +116,101 @@ int util::Timestamp::getDateAsInt() const
return year * 10000 + month * 100 + day; return year * 10000 + month * 100 + day;
} }
/*
* Function: getDurationInMinutes
* Description: Calculates the duration between two timestamps in minutes.
* Parameters:
* startTimestamp - starting time
* endTimestamp - ending time
* Returns:
* 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;
} }
/*
* Function: getDurationInHours
* Description: Calculates the duration between two timestamps in hours.
* Parameters:
* startTimestamp - starting time
* endTimestamp - ending time
* Returns:
* 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;
} }
/*
* Function: operator<
* Description: Compares two timestamps to check if one is earlier than the other.
* Parameters:
* other - Timestamp to compare against
* Returns:
* 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;
} }
/*
* Function: operator>
* Description: Compares two timestamps to check if one is later than the other.
* Parameters:
* other - Timestamp to compare against
* Returns:
* 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;
} }
/*
* Function: operator<=
* Description: Compares two timestamps to check if one is earlier or equal.
* Parameters:
* other - Timestamp to compare against
* Returns:
* 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;
} }
/*
* Function: operator>=
* Description: Compares two timestamps to check if one is later or equal.
* Parameters:
* other - Timestamp to compare against
* Returns:
* 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;
} }
/*
* Function: operator==
* Description: Compares two timestamps for equality.
* Parameters:
* other - Timestamp to compare against
* Returns:
* 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;
@@ -1,3 +1,12 @@
/*
* File: Timestamp.h
* Description: Provides a utility class for representing and manipulating time values.
* Supports conversion between string and time formats, duration calculations
* (hours, minutes, seconds), date extraction, and comparison operators.
* Author: Trenser
* Created: 01-Apr-2026
*/
#pragma once #pragma once
#include <ctime> #include <ctime>
#include <string> #include <string>
@@ -1,8 +1,24 @@
/*
* File: Validator.cpp
* Description: Validates inputs like phone number, email, password
* Author: Trenser
* Created: 01-Apr-2026
*/
#include <string> #include <string>
#include <cctype> #include <cctype>
#include "Validator.h" #include "Validator.h"
#include "ApplicationConfig.h" #include "ApplicationConfig.h"
/*
* Function: isPhoneNumberValid
* Description: Validates whether the given string is a valid phone number.
* Parameters:
* phoneNumber - string containing the phone number to validate
* Returns:
* 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)
{ {
@@ -16,6 +32,15 @@ bool util::isPhoneNumberValid(const std::string& phoneNumber) {
); );
} }
/*
* Function: isEmailValid
* Description: Validates whether the given string is a properly formatted email address.
* Parameters:
* email - string containing the email address to validate
* Returns:
* 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) return false; if (index == std::string::npos) return false;
@@ -30,6 +55,19 @@ bool util::isEmailValid(const std::string& email) {
return true; return true;
} }
/*
* Function: isPasswordValid
* Description: Validates whether the given string meets password requirements.
* Parameters:
* password - string containing the password to validate
* Returns:
* bool - true if the password is valid, false otherwise
* Notes:
* - Must not equal the default password
* - Must be at least 8 characters long
* - Must contain at least one uppercase letter, one lowercase letter, one digit, and one special character
* - Must not contain whitespace
*/
bool util::isPasswordValid(const std::string& password) bool util::isPasswordValid(const std::string& password)
{ {
@@ -1,3 +1,10 @@
/*
* File: Validator.h
* Description: Validates inputs like phone number, email, password
* Author: Trenser
* Created: 01-Apr-2026
*/
#pragma once #pragma once
#include<string> #include<string>
#include<algorithm> #include<algorithm>