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:
+51
-5
@@ -22,6 +22,14 @@ Date: 22-May-2026
|
||||
|
||||
util::Map<std::string, User*> InventoryManagementService::m_observers{};
|
||||
|
||||
/*
|
||||
Function: attach
|
||||
Description: Adds a user to the observer list for receiving inventory notifications.
|
||||
Parameters:
|
||||
- user: User*, pointer to the user to be attached as an observer
|
||||
Returns:
|
||||
- None
|
||||
*/
|
||||
void InventoryManagementService::attach(User* user)
|
||||
{
|
||||
if (user)
|
||||
@@ -34,6 +42,14 @@ void InventoryManagementService::attach(User* user)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: detach
|
||||
Description: Removes a user from the observer list so they no longer receive inventory notifications.
|
||||
Parameters:
|
||||
- user: User*, pointer to the user to be detached from the observer list
|
||||
Returns:
|
||||
- None
|
||||
*/
|
||||
void InventoryManagementService::detach(User* user)
|
||||
{
|
||||
if (user)
|
||||
@@ -46,6 +62,18 @@ void InventoryManagementService::detach(User* user)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: sendNotification
|
||||
Description: Sends a notification to a user if they are subscribed as an observer.
|
||||
Parameters:
|
||||
- user: User*, pointer to the user receiving the notification
|
||||
- title: std::string, title of the notification
|
||||
- message: std::string, body/content of the notification
|
||||
Returns:
|
||||
- None
|
||||
Throws:
|
||||
- std::runtime_error if notification creation fails
|
||||
*/
|
||||
void InventoryManagementService::sendNotification(User* user, const std::string& title, const std::string& message)
|
||||
{
|
||||
if (user)
|
||||
@@ -72,20 +100,39 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
static void sendLowStockAlertsToAdmins(InventoryManagementService& inventoryManagementService, const InventoryItem* inventoryItem, const util::Vector<User*>& adminUsers)
|
||||
{
|
||||
int adminUsersSize = adminUsers.getSize();
|
||||
for (int index = 0; index < adminUsersSize; index++)
|
||||
{
|
||||
std::string title = "Low Stock Alert";
|
||||
std::string message = "The inventory item with ID " + inventoryItem->getId() + " has very low quantity in the inventory";
|
||||
inventoryManagementService.sendNotification(
|
||||
adminUsers[index],
|
||||
"Low Stock Alert",
|
||||
"The inventory item with ID " + inventoryItem->getId() +
|
||||
" has very low quantity in the inventory"
|
||||
);
|
||||
title,
|
||||
message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: sendLowStockAlerts
|
||||
Description: Sends alerts to user for inventory items with low stock
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- None
|
||||
*/
|
||||
void InventoryManagementService::sendLowStockAlerts()
|
||||
{
|
||||
auto& inventoryItems = m_dataStore.getInventoryItems();
|
||||
@@ -116,7 +163,6 @@ void InventoryManagementService::sendLowStockAlerts()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: getObserverIDs
|
||||
Description: Retrieves the IDs of all observers currently attached to the
|
||||
|
||||
+3
-4
@@ -19,7 +19,6 @@ Date: 20-May-2026
|
||||
#include "User.h"
|
||||
#include "Utility.h"
|
||||
|
||||
|
||||
util::Map<std::string, User*> PaymentManagementService::m_observers{};
|
||||
|
||||
/*
|
||||
@@ -128,9 +127,9 @@ void PaymentManagementService::sendPaymentReminders()
|
||||
User* customer = serviceBooking->getCustomer();
|
||||
if (customer)
|
||||
{
|
||||
sendNotification(customer,
|
||||
"Payment Reminder",
|
||||
"Your payment for Invoice ID " + invoice->getId() + " is still pending.Please complete the payment." + invoice->getId());
|
||||
std::string title = "Payment Reminder";
|
||||
std::string message = "Your payment for Invoice ID " + invoice->getId() + " is still pending. Please complete the payment.";
|
||||
sendNotification(customer, title, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -60,9 +60,9 @@ void ServiceManagementService::purchaseService(const util::Vector<std::string>&
|
||||
throw std::runtime_error("Failed to create service booking");
|
||||
}
|
||||
serviceBookingMap[serviceBooking->getId()] = serviceBooking;
|
||||
sendNotification(authenticatedUser,
|
||||
"Service Booking succeeded",
|
||||
"Your service booking has been successfully placed with ID " + serviceBooking->getId());
|
||||
std::string title = "Service Booking succeeded";
|
||||
std::string message = "Your service booking has been successfully placed with ID " + serviceBooking->getId();
|
||||
sendNotification(authenticatedUser, title, message);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -99,9 +99,9 @@ void ServiceManagementService::purchaseComboPackage(const std::string& comboPack
|
||||
throw std::runtime_error("Failed to create combo package service booking");
|
||||
}
|
||||
serviceBookingMap[serviceBooking->getId()] = serviceBooking;
|
||||
sendNotification(authenticatedUser,
|
||||
"Combo Package Service Booking succeeded",
|
||||
"Your service booking for the combo package has been successfully placed with ID " + serviceBooking->getId());
|
||||
std::string title = "Combo Package Service Booking succeeded";
|
||||
std::string message = "Your service booking for the combo package has been successfully placed with ID " + serviceBooking->getId();
|
||||
sendNotification(authenticatedUser, title, message);
|
||||
}
|
||||
|
||||
util::Map<std::string, User*> ServiceManagementService::m_observers{};
|
||||
|
||||
Reference in New Issue
Block a user