Merge branch 'feature-notification-management' into feature-1551-1561-1708

This commit is contained in:
2026-05-25 11:48:25 +05:30
40 changed files with 1983 additions and 58 deletions
@@ -7,12 +7,14 @@ Author: Trenser
Date:19-May-2026
*/
#include <stdexcept>
#include "ServiceManagementService.h"
#include "AuthenticationManagementService.h"
#include "Service.h"
#include "ServiceBooking.h"
#include "ComboPackage.h"
#include "Factory.h"
#include "Service.h"
#include "ServiceBooking.h"
#include "ServiceManagementService.h"
#include "Timestamp.h"
#include "User.h"
/*
Function: purchaseService
@@ -96,3 +98,83 @@ void ServiceManagementService::purchaseComboPackage(const std::string& comboPack
"Combo Package Service Booking succeeded",
"Your service booking for the combo package has been successfully placed with ID " + serviceBooking->getId());
}
util::Map<std::string, User*> ServiceManagementService::m_observers{};
/*
Function: attach
Description: Attaches a user as an observer to the ServiceManagementService for receiving notifications.
Parameters:
- user: Pointer to the User object to be attached.
Returns:
- void
*/
void ServiceManagementService::attach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) == -1)
{
m_observers[userID] = user;
}
}
}
/*
Function: detach
Description: Detaches a user from the observer list of the ServiceManagementService.
Parameters:
- user: Pointer to the User object to be detached.
Returns:
- void
*/
void ServiceManagementService::detach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) != -1)
{
m_observers.remove(userID);
}
}
}
/*
Function: sendNotification
Description: Sends a notification to a user if they are registered as an observer.
Parameters:
- user: Pointer to the User object to receive the notification.
- title: Title of the notification.
- message: Message content of the notification.
Returns:
- void
Throws:
- std::runtime_error if notification creation fails.
*/
void ServiceManagementService::sendNotification(User* user, const std::string& title, const std::string& message)
{
if (user)
{
if (m_observers.find(user->getId()) != -1)
{
Notification* notification =
Factory::getObject<Notification>(
user->getId(),
user,
"ServiceManagementService: " + title,
message,
util::Timestamp()
);
if (notification)
{
user->addNotification(notification);
}
else
{
throw std::runtime_error("Failed to create notification");
}
}
}
}