Fix PR review comments and refactor menu helper logic
Changes: - Added name parameter to createTechnician for consistency - Added function headers for notification-related methods in InventoryManagementService - Used variables for notification title and message instead of passing strings directly - Fixed payment reminder notification message formatting - Moved common helper functions to MenuHelper.h - Updated CustomerMenu to use shared helper functions instead of duplicate code - Added missing includes in MenuHelper.h - Removed redundant helper code from CustomerMenu.cpp - Minor formatting and comment cleanup
This commit is contained in:
@@ -15,7 +15,6 @@ Date:19-May-2026
|
||||
#include "MenuHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Service.h"
|
||||
#include "Utility.h"
|
||||
#include "Validator.h"
|
||||
#include "Vector.h"
|
||||
|
||||
@@ -25,6 +24,7 @@ Description: Displays the customer menu and handles user input until logout is s
|
||||
Parameter: None
|
||||
Return type: void
|
||||
*/
|
||||
|
||||
void CustomerMenu::showMenu()
|
||||
{
|
||||
while (true)
|
||||
@@ -125,19 +125,7 @@ Return type: void
|
||||
*/
|
||||
void CustomerMenu::changePassword()
|
||||
{
|
||||
std::string newPassword;
|
||||
util::clear();
|
||||
std::cout << "Enter new password: ";
|
||||
util::read(newPassword);
|
||||
m_controller.changePassword(newPassword);
|
||||
if (!util::isPasswordValid(newPassword))
|
||||
{
|
||||
std::cout << "Error: Password is not strong enough!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
std::cout << "Password changed successfully";
|
||||
util::pressEnter();
|
||||
changePasswordHelper(m_controller);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,55 +159,6 @@ void CustomerMenu::updateDetails()
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectServiceFromServices
|
||||
Description: Displays active services and allows the customer to select one by index.
|
||||
Parameter: const util::Map<std::string, const Service*>& services - list of services
|
||||
Return type: const Service* - selected service
|
||||
*/
|
||||
static const Service* selectServiceFromServices(const util::Map<std::string, const Service*>& services)
|
||||
{
|
||||
util::Map<int, const Service*> activeServicesMap;
|
||||
int currentIndex = 1;
|
||||
int userInputIndex;
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << "Index"
|
||||
<< std::setw(15) << "Service ID"
|
||||
<< std::setw(25) << "Service Name"
|
||||
<< std::setw(15) << "Estimated Cost"
|
||||
<< std::endl;
|
||||
for (int index = 0; index < services.getSize(); index++)
|
||||
{
|
||||
const Service* currentService = services.getValueAt(index);
|
||||
if (currentService->getState() != util::State::ACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
activeServicesMap.insert(currentIndex, currentService);
|
||||
double partsCost = util::calculatePartsCost(currentService);
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << currentIndex
|
||||
<< std::setw(15) << currentService->getId()
|
||||
<< std::setw(25) << currentService->getName()
|
||||
<< std::setw(15) << (currentService->getLaborCost() + partsCost)
|
||||
<< std::endl;
|
||||
currentIndex++;
|
||||
}
|
||||
if (activeServicesMap.getSize() == 0)
|
||||
{
|
||||
std::cout << "No active services available." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::cout << "Enter service index: ";
|
||||
util::read(userInputIndex);
|
||||
if (activeServicesMap.find(userInputIndex) == -1)
|
||||
{
|
||||
std::cout << "Invalid service index." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return activeServicesMap[userInputIndex];
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectService
|
||||
Description: Allows the customer to select a service, provide vehicle details,
|
||||
@@ -253,54 +192,6 @@ void CustomerMenu::selectService()
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectComboPackageFromPackages
|
||||
Description: Displays active combo packages and allows the customer to select one by index.
|
||||
Parameter: const util::Map<std::string, const ComboPackage*>& comboPackages - list of combo packages
|
||||
Return type: const ComboPackage* - selected combo package
|
||||
*/
|
||||
static const ComboPackage* selectComboPackageFromPackages(const util::Map<std::string, const ComboPackage*>& comboPackages)
|
||||
{
|
||||
util::Map<int, const ComboPackage*> activeComboPackages;
|
||||
int currentIndex = 1;
|
||||
int userInputIndex;
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << "Index"
|
||||
<< std::setw(15) << "Combo Package ID"
|
||||
<< std::setw(15) << "Combo Package Name"
|
||||
<< std::setw(15) << "Estimate Cost"
|
||||
<< std::endl;
|
||||
for (int index = 0; index < comboPackages.getSize(); index++)
|
||||
{
|
||||
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
||||
if (currentComboPackage->getState() != util::State::ACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
activeComboPackages.insert(currentIndex, currentComboPackage);
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << currentIndex
|
||||
<< std::setw(15) << currentComboPackage->getId()
|
||||
<< std::setw(25) << currentComboPackage->getPackageName()
|
||||
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
||||
<< std::endl;
|
||||
currentIndex++;
|
||||
}
|
||||
if (activeComboPackages.getSize() == 0)
|
||||
{
|
||||
std::cout << "No active combo packages available." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::cout << "Enter combo package index: ";
|
||||
util::read(userInputIndex);
|
||||
if (activeComboPackages.find(userInputIndex) == -1)
|
||||
{
|
||||
std::cout << "Invalid combo package index." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return activeComboPackages[userInputIndex];
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectComboPackage
|
||||
Description: Allows the customer to select a combo package, provide vehicle details,
|
||||
@@ -357,38 +248,6 @@ void CustomerMenu::viewNotifications()
|
||||
viewAndDeleteNotification(m_controller);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getNotificationPreference (static helper)
|
||||
Description: Helper function to configure notification preferences for a specific service.
|
||||
Parameters:
|
||||
- serviceName: Name of the service for which notifications are being configured.
|
||||
Returns:
|
||||
- bool: True if notifications are enabled, False if disabled.
|
||||
*/
|
||||
static bool getNotificationPreference(const std::string& serviceName)
|
||||
{
|
||||
int choice;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << " Configure Notification Preferences\n";
|
||||
std::cout << "\n" << serviceName << " Notifications\n";
|
||||
std::cout << "1. Enable Notifications\n";
|
||||
std::cout << "2. Disable Notifications\n";
|
||||
std::cout << "Enter your choice: ";
|
||||
util::read(choice);
|
||||
if (choice == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (choice == 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::cout << "\nInvalid choice. Please enter 1 or 2.\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: configureNotifications
|
||||
|
||||
@@ -7,6 +7,7 @@ Description: Header file declaring the CustomerMenu class, which provides
|
||||
Author: Trenser
|
||||
Date:19-May-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Controller.h"
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ Date: 21-May-2026
|
||||
#include "Notification.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Vector.h"
|
||||
#include "Validator.h"
|
||||
#include "Service.h"
|
||||
#include "ComboPackage.h"
|
||||
#include "Utility.h"
|
||||
|
||||
/*
|
||||
Function: selectNotification
|
||||
@@ -112,3 +116,172 @@ inline void viewAndDeleteNotification(Controller& controller)
|
||||
controller.deleteNotification(selectedNotification->getId());
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: changePassword
|
||||
Description: Helper function to change password
|
||||
Parameter: controller: Reference to the Controller object used to manage notifications.
|
||||
Return type: void
|
||||
*/
|
||||
inline void changePasswordHelper(Controller& controller)
|
||||
{
|
||||
std::string newPassword;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Enter new password: ";
|
||||
util::read(newPassword);
|
||||
if (!util::isPasswordValid(newPassword))
|
||||
{
|
||||
std::cout << "Error: Password is not strong enough!\n";
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
controller.changePassword(newPassword);
|
||||
std::cout << "Password changed successfully\n";
|
||||
util::pressEnter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectServiceFromServices
|
||||
Description: Displays active services and allows the customer to select one by index.
|
||||
Parameter: const util::Map<std::string, const Service*>& services - list of services
|
||||
Return type: const Service* - selected service
|
||||
*/
|
||||
inline const Service* selectServiceFromServices(const util::Map<std::string, const Service*>& services)
|
||||
{
|
||||
util::Map<int, const Service*> activeServicesMap;
|
||||
int currentIndex = 1;
|
||||
int userInputIndex;
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << "Index"
|
||||
<< std::setw(15) << "Service ID"
|
||||
<< std::setw(25) << "Service Name"
|
||||
<< std::setw(15) << "Estimated Cost"
|
||||
<< std::endl;
|
||||
for (int index = 0; index < services.getSize(); index++)
|
||||
{
|
||||
const Service* currentService = services.getValueAt(index);
|
||||
if (currentService->getState() != util::State::ACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
activeServicesMap.insert(currentIndex, currentService);
|
||||
double partsCost = util::calculatePartsCost(currentService);
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << currentIndex
|
||||
<< std::setw(15) << currentService->getId()
|
||||
<< std::setw(25) << currentService->getName()
|
||||
<< std::setw(15) << (currentService->getLaborCost() + partsCost)
|
||||
<< std::endl;
|
||||
currentIndex++;
|
||||
}
|
||||
if (activeServicesMap.getSize() == 0)
|
||||
{
|
||||
std::cout << "No active services available." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::cout << "Enter service index: ";
|
||||
util::read(userInputIndex);
|
||||
if (activeServicesMap.find(userInputIndex) == -1)
|
||||
{
|
||||
std::cout << "Invalid service index." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return activeServicesMap[userInputIndex];
|
||||
}
|
||||
|
||||
/*
|
||||
Function: selectComboPackageFromPackages
|
||||
Description: Displays active combo packages and allows the customer to select one by index.
|
||||
Parameter: const util::Map<std::string, const ComboPackage*>& comboPackages - list of combo packages
|
||||
Return type: const ComboPackage* - selected combo package
|
||||
*/
|
||||
inline const ComboPackage* selectComboPackageFromPackages(const util::Map<std::string, const ComboPackage*>& comboPackages)
|
||||
{
|
||||
util::Map<int, const ComboPackage*> activeComboPackages;
|
||||
int currentIndex = 1;
|
||||
int userInputIndex;
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << "Index"
|
||||
<< std::setw(15) << "Combo Package ID"
|
||||
<< std::setw(15) << "Combo Package Name"
|
||||
<< std::setw(15) << "Estimate Cost"
|
||||
<< std::endl;
|
||||
for (int index = 0; index < comboPackages.getSize(); index++)
|
||||
{
|
||||
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
||||
if (currentComboPackage->getState() != util::State::ACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
activeComboPackages.insert(currentIndex, currentComboPackage);
|
||||
std::cout << std::left
|
||||
<< std::setw(10) << currentIndex
|
||||
<< std::setw(15) << currentComboPackage->getId()
|
||||
<< std::setw(25) << currentComboPackage->getPackageName()
|
||||
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
||||
<< std::endl;
|
||||
currentIndex++;
|
||||
}
|
||||
if (activeComboPackages.getSize() == 0)
|
||||
{
|
||||
std::cout << "No active combo packages available." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
std::cout << "Enter combo package index: ";
|
||||
util::read(userInputIndex);
|
||||
if (activeComboPackages.find(userInputIndex) == -1)
|
||||
{
|
||||
std::cout << "Invalid combo package index." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return activeComboPackages[userInputIndex];
|
||||
}
|
||||
|
||||
/*
|
||||
Function: sendLowStockAlertsToAdmins (static helper)
|
||||
Description: Sends low stock alert notifications to all admin users for a given inventory item.
|
||||
Parameters:
|
||||
- inventoryManagementService: InventoryManagementService&, service used to send notifications
|
||||
- inventoryItem: const InventoryItem*, pointer to the low-stock inventory item
|
||||
- adminUsers: const util::Vector<User*>&, list of admin users to notify
|
||||
Returns:
|
||||
- None
|
||||
*/
|
||||
|
||||
/*
|
||||
Function: getNotificationPreference (static helper)
|
||||
Description: Helper function to configure notification preferences for a specific service.
|
||||
Parameters:
|
||||
- serviceName: Name of the service for which notifications are being configured.
|
||||
Returns:
|
||||
- bool: True if notifications are enabled, False if disabled.
|
||||
*/
|
||||
inline bool getNotificationPreference(const std::string& serviceName)
|
||||
{
|
||||
int choice;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << " Configure Notification Preferences\n";
|
||||
std::cout << "\n" << serviceName << " Notifications\n";
|
||||
std::cout << "1. Enable Notifications\n";
|
||||
std::cout << "2. Disable Notifications\n";
|
||||
std::cout << "Enter your choice: ";
|
||||
util::read(choice);
|
||||
if (choice == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (choice == 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::cout << "\nInvalid choice. Please enter 1 or 2.\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Description: Implementation file containing the method definitions of the
|
||||
and customer registration logic.
|
||||
Author: Trenser
|
||||
Date:19-May-2026
|
||||
|
||||
*/
|
||||
#include "UserInterface.h"
|
||||
#include "InputHelper.h"
|
||||
|
||||
Reference in New Issue
Block a user