From 2757e5ca98d582d8ddb0c067320cd76d83f3f20c Mon Sep 17 00:00:00 2001 From: Ajmal Jalaludeen Date: Wed, 8 Apr 2026 17:27:22 +0530 Subject: [PATCH] Add file and function header documentation across Controller, DataStore and Utility files --- .../controllers/ZenvyController.cpp | 39 +++++- .../controllers/ZenvyController.h | 7 + .../Trenser.Zenvy/datastores/DataStore.cpp | 61 ++++++++ .../Trenser.Zenvy/datastores/DataStore.h | 7 + .../Trenser.Zenvy/factories/Factory.h | 18 +++ Trenser.Zenvy/Trenser.Zenvy/utilities/Enums.h | 7 + .../Trenser.Zenvy/utilities/InputHelper.h | 33 ++++- .../Trenser.Zenvy/utilities/OutputHelper.cpp | 15 ++ .../Trenser.Zenvy/utilities/OutputHelper.h | 7 + .../Trenser.Zenvy/utilities/Timestamp.cpp | 131 ++++++++++++++++++ .../Trenser.Zenvy/utilities/Timestamp.h | 9 ++ .../Trenser.Zenvy/utilities/Validator.cpp | 38 +++++ .../Trenser.Zenvy/utilities/Validator.h | 7 + 13 files changed, 377 insertions(+), 2 deletions(-) diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp index 3d97204..162bdd2 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp @@ -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" -//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) { 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() { 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) { m_authenticationManagementService->changePassword(password); diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h index 1a5c77b..364ec49 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h @@ -1,3 +1,10 @@ +/* + * File: ZenvyController.h + * Description : Controls data flow between UI and Service Layers. + * Author: Trenser + * Created : 01-04-2026 + */ + #pragma once #include #include diff --git a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp index 16ddca1..64694df 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp @@ -1,31 +1,92 @@ +/* + * File: DataStore.cpp + * Description: Central Storage for all the System Data. + * Author: Trenser + * Created: 01-04-2026 + */ + #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() { static DataStore 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() { return m_logs; } +/* + * Function: getAuthenticatedEmployee + * Description: returns the currently authenticated employee. + * Parameters: + * None + * Returns: + * std::shared_ptr& - reference to the authenticated employee object. + */ + std::shared_ptr& DataStore::getAuthenticatedEmployee() { 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 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() { return m_employees; } +/* + * Function: getAuthenticatedUser + * Description: alias for getAuthenticatedEmployee, returns the currently authenticated employee. + * Parameters: + * None + * Returns: + * std::shared_ptr& - reference to the authenticated employee object. + */ + std::shared_ptr& DataStore::getAuthenticatedUser() { return m_authenticatedEmployee; diff --git a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h index 5ecfb70..603d49c 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h +++ b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h @@ -1,3 +1,10 @@ +/* + * File: DataStore.h + * Description: Central Storage for all the System Data. + * Author: Trenser + * Created: 01-04-2026 + */ + #pragma once #include #include diff --git a/Trenser.Zenvy/Trenser.Zenvy/factories/Factory.h b/Trenser.Zenvy/Trenser.Zenvy/factories/Factory.h index 0c54b81..f65c267 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/factories/Factory.h +++ b/Trenser.Zenvy/Trenser.Zenvy/factories/Factory.h @@ -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 #include #include @@ -5,6 +12,17 @@ class Factory { 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 - a shared pointer managing the newly created object + */ + template static std::shared_ptr getObject(Args&&... args) { diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Enums.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/Enums.h index ace8792..0d5111b 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Enums.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Enums.h @@ -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 namespace Enums { diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/InputHelper.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/InputHelper.h index 559acda..5de0e35 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/InputHelper.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/InputHelper.h @@ -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 #include #include @@ -7,6 +13,15 @@ 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 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) { 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() { system("pause"); diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.cpp b/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.cpp index a8e0f7c..ce37ac4 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.cpp @@ -1,5 +1,20 @@ +/* + * File: OutputHelper.cpp + * Description: Provides functions to help with console output. + * Author: Trenser + * Created: 01-04-2026 +*/ + #include "outputHelper.h" +/* +* Function: clear +* Description: Clears the console screen output. +* Parameters: None +* Returns: +* void - no return value +*/ + void util::clear() { std::cout << "\x1B[2J\x1B[H" << std::flush; diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.h index a40dbaf..08a5b5f 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/OutputHelper.h @@ -1,3 +1,10 @@ +/* + * File: OutputHelper.h + * Description: Provides functions to help with console output. + * Author: Trenser + * Created: 01-04-2026 +*/ + #pragma once #include diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.cpp b/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.cpp index 42d4758..3a51132 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.cpp @@ -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 #include #include #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() { 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) { 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) { std::tm timeStruct = {}; @@ -26,6 +64,15 @@ util::Timestamp util::Timestamp::fromString(const std::string& timeString) 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::tm timeStruct = {}; @@ -35,11 +82,30 @@ std::string util::Timestamp::toString() const 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) { 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 { std::tm timeStruct{}; @@ -50,36 +116,101 @@ int util::Timestamp::getDateAsInt() const 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) { 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) { 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 { 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 { 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 { 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 { 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 { return m_time == other.m_time; diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.h index abbc58f..ace001a 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Timestamp.h @@ -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 #include #include diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp index 9d14b40..8510bdf 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp @@ -1,8 +1,24 @@ +/* + * File: Validator.cpp + * Description: Validates inputs like phone number, email, password + * Author: Trenser + * Created: 01-Apr-2026 + */ + #include #include #include "Validator.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) { 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) { size_t index = email.find('@'); if (index == std::string::npos) return false; @@ -30,6 +55,19 @@ bool util::isEmailValid(const std::string& email) { 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) { diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h index fbdf962..3710604 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h @@ -1,3 +1,10 @@ +/* + * File: Validator.h + * Description: Validates inputs like phone number, email, password + * Author: Trenser + * Created: 01-Apr-2026 + */ + #pragma once #include #include