Merge branch 'feature-notification-management-not006' into feature-notification-management

This commit is contained in:
Jissin Mathew
2026-05-21 21:07:17 +05:30
10 changed files with 232 additions and 10 deletions
@@ -157,8 +157,32 @@ void Controller::deleteNotification(const std::string& notificationID)
m_userManagementService.deleteNotification(notificationID, authenticatedUser->getId());
}
void Controller::configureNotifications(const std::string& userID, bool paymentNotifications, bool serviceNotifications)
void Controller::configureNotifications(bool paymentNotifications, bool serviceNotifications)
{
User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser();
if (authenticatedUser)
{
if (paymentNotifications)
{
m_paymentManagementService.attach(authenticatedUser);
}
else
{
m_paymentManagementService.detach(authenticatedUser);
}
if (serviceNotifications)
{
m_serviceManagementService.attach(authenticatedUser);
}
else
{
m_serviceManagementService.detach(authenticatedUser);
}
}
else
{
throw std::runtime_error("No user is currently logged in!");
}
}
void Controller::runSystemChecks()
@@ -3,6 +3,7 @@
#include <string>
#include "Enums.h"
#include "AuthenticationManagementService.h"
#include "ServiceManagementService.h"
#include "UserManagementService.h"
#include "InventoryManagementService.h"
#include "PaymentManagementService.h"
@@ -23,6 +24,7 @@ private:
UserManagementService m_userManagementService;
InventoryManagementService m_inventoryManagementService;
PaymentManagementService m_paymentManagementService;
ServiceManagementService m_serviceManagementService;
public:
bool login(const std::string& username, const std::string& password);
void logout();
@@ -55,6 +57,6 @@ public:
void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode);
util::Vector<const Notification*> getNotifications();
void deleteNotification(const std::string& notificationID);
void configureNotifications(const std::string& userID, bool paymentNotifications, bool serviceNotifications);
void configureNotifications(bool paymentNotifications, bool serviceNotifications);
void runSystemChecks();
};
@@ -6,5 +6,5 @@ class Observer
{
public:
virtual ~Observer() = default;
virtual void update(Notification* notification) = 0;
virtual void addNotification(Notification* notification) = 0;
};
@@ -104,7 +104,10 @@ void User::setEmail(const std::string& email)
void User::addNotification(Notification* notification)
{
if (notification)
{
m_notifications.insert(notification->getId(), notification);
}
}
void User::setRole(util::UserType role)
@@ -116,7 +119,3 @@ void User::setState(util::State status)
{
m_status = status;
}
void User::update(Notification* notification)
{
}
@@ -38,8 +38,7 @@ public:
void setName(const std::string& name);
void setPhone(const std::string& phone);
void setEmail(const std::string& email);
void addNotification(Notification* notification);
void addNotification(Notification* notification) override;
void setRole(util::UserType role);
void setState(util::State status);
void update(Notification* notification) override;
};
@@ -4,6 +4,61 @@
#include "Enums.h"
#include "InventoryItem.h"
#include "Config.h"
#include "User.h"
#include "Factory.h"
#include "Timestamp.h"
util::Map<std::string, User*> InventoryManagementService::m_observers{};
void InventoryManagementService::attach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) == -1)
{
m_observers[userID] = user;
}
}
}
void InventoryManagementService::detach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) != -1)
{
m_observers.remove(userID);
}
}
}
void InventoryManagementService::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,
"InventoryManagementService: " + title,
message,
util::Timestamp()
);
if (notification)
{
user->addNotification(notification);
}
else
{
throw std::runtime_error("Failed to create notification");
}
}
}
}
static void sendLowStockAlertsToAdmins(InventoryManagementService& inventoryManagementService, const InventoryItem* inventoryItem, const util::Vector<User*>& adminUsers)
{
@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include "Subject.h"
#include "Notification.h"
#include "User.h"
class NotificationManagementService : public Subject
@@ -1,9 +1,64 @@
#include <stdexcept>
#include "PaymentManagementService.h"
#include "Invoice.h"
#include "ServiceBooking.h"
#include "Enums.h"
#include "Timestamp.h"
#include "Config.h"
#include "User.h"
#include "Factory.h"
util::Map<std::string, User*> PaymentManagementService::m_observers{};
void PaymentManagementService::attach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) == -1)
{
m_observers[userID] = user;
}
}
}
void PaymentManagementService::detach(User* user)
{
if (user)
{
const std::string& userID = user->getId();
if (m_observers.find(userID) != -1)
{
m_observers.remove(userID);
}
}
}
void PaymentManagementService::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,
"PaymentManagementService: " + title,
message,
util::Timestamp()
);
if (notification)
{
user->addNotification(notification);
}
else
{
throw std::runtime_error("Failed to create notification");
}
}
}
}
void PaymentManagementService::sendPaymentReminders()
{
@@ -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");
}
}
}
}
@@ -69,6 +69,37 @@ void CustomerMenu::viewNotifications()
viewAndDeleteNotification(m_controller);
}
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();
}
}
void CustomerMenu::configureNotifications()
{
bool paymentServiceNotifications = getNotificationPreference("Payment Management Service");
bool serviceManagementNotifications = getNotificationPreference("Service Management Service");
m_controller.configureNotifications(paymentServiceNotifications, serviceManagementNotifications);
util::clear();
std::cout << "Notification preferences updated successfully.\n";
util::pressEnter();
}