Implement Configure Notifications functionality
<UserStory> NOT006: Configure Notifications </UserStory>
<Changes>
1. Added notification subscription configuration in CustomerMenu to allow customers to enable or disable notifications for Payment Management Service and Service Management Service.
2. Updated Controller::configureNotifications() to attach or detach the authenticated user from service observers based on selected notification preferences.
3. Refactored Observer interface and User notification handling to support notification delivery through observer subscriptions.
4. Implemented observer attach, detach, and sendNotification logic in InventoryManagementService, PaymentManagementService, and ServiceManagementService to ensure notifications are sent only to subscribed users.
</Changes>
<Test>
Precondition:
1. Customer user is logged into the system.
2. Notification configuration option is available in Customer Menu.
3. Notification-triggering event exists for Payment Management Service or Service Management Service.
Steps:
1. Navigate to Configure Notification Preferences in Customer Menu.
2. Enable notifications for one service and disable notifications for the other.
3. Trigger a notification event for both services.
- Verify that notification is received only from the subscribed service.
4. Change preferences by disabling the subscribed service and enabling the other.
5. Trigger notification events again.
- Verify that notification is received only from the newly subscribed service.
</Test>
<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
+56
@@ -1 +1,57 @@
|
||||
#include <stdexcept>
|
||||
#include "ServiceManagementService.h"
|
||||
#include "User.h"
|
||||
#include "Factory.h"
|
||||
#include "Timestamp.h"
|
||||
|
||||
util::Map<std::string, User*> ServiceManagementService::m_observers{};
|
||||
|
||||
void ServiceManagementService::attach(User* user)
|
||||
{
|
||||
if (user)
|
||||
{
|
||||
const std::string& userID = user->getId();
|
||||
if (m_observers.find(userID) == -1)
|
||||
{
|
||||
m_observers[userID] = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceManagementService::detach(User* user)
|
||||
{
|
||||
if (user)
|
||||
{
|
||||
const std::string& userID = user->getId();
|
||||
if (m_observers.find(userID) != -1)
|
||||
{
|
||||
m_observers.remove(userID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user