From 468106952f9894c67234df6d05c468ddb5fce4ac Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Wed, 17 Jun 2026 17:39:45 +0530 Subject: [PATCH] Notify admins when new service bookings are created Changes: - Added notifyAllAdmins() helper in ServiceManagementService. - Sent notifications to all administrators when a customer places a service booking. - Sent notifications to all administrators when a customer purchases a combo package. - Included the generated Service Booking ID in admin notifications. Fixes #2100 --- .../services/ServiceManagementService.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index da5eef6..a4d72bd 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -29,6 +29,31 @@ Date:19-May-2026 #include "DataStoreLockGuard.h" #include "EventManager.h" +/* +Function: notifyAllAdmins +Description: Sends a notification to all users with the ADMIN role. + Iterates through the provided user collection and delivers + the specified notification to each administrator using the + ServiceManagementService notification mechanism. +Parameter: const std::string& title - notification title +Parameter: const std::string& message - notification message +Parameter: const util::Map>& users - collection of tracked users +Parameter: ServiceManagementService* serviceManagementService - service used to dispatch notifications +Return type: void +*/ +static void notifyAllAdmins(const std::string& title, const std::string& message, const util::Map>& users, ServiceManagementService* serviceManagementService) +{ + int numberOfUsers = users.getSize(); + for (int index = 0; index < numberOfUsers; index++) + { + User* user = users.getValueAt(index).data; + if (user->getUserType() == util::UserType::ADMIN) + { + serviceManagementService->sendNotification(user, title, message); + } + } +} + /* Function: purchaseService Description: Creates a new service booking for the authenticated user. Validates @@ -73,6 +98,7 @@ void ServiceManagementService::purchaseService(const util::Vector& std::string title = "Service Booking succeeded"; std::string message = "Your service booking has been successfully placed with ID " + serviceBooking->getId(); sendNotification(authenticatedUser, title, message); + notifyAllAdmins("New Service Order Available", "A new service order has been placed with Service Booking ID " + serviceBooking->getId(), m_dataStore.getUsers(), this); } /* @@ -114,6 +140,7 @@ void ServiceManagementService::purchaseComboPackage(const std::string& comboPack 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); + notifyAllAdmins("New Combo Package Order Available", "A new combo package order has been placed with Service Booking ID " + serviceBooking->getId(), m_dataStore.getUsers(), this); } util::Map ServiceManagementService::m_observers{};