From b8e87ade0f7b99eec8f2e3474510d4c9749e4ee1 Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Wed, 20 May 2026 15:11:34 +0530 Subject: [PATCH] Implement View Customer Notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOT001: View Customer Notifications 1. Added shared notification helper functions to display notifications in tabular format, support notification selection, and show full notification details. 2. Implemented notification deletion logic in Controller and UserManagementService to remove notifications for the authenticated user after viewing. 3. Updated CustomerMenu::viewNotifications() to use the shared notification viewing and deletion flow. Precondition: 1. Customer is registered in the system. 2. Customer is logged into the system. 3. Customer has one or more notifications available. Steps: 1. Navigate to “View Notifications” from the customer menu. - Verify that the system displays the list of notifications with title and timestamp. 2. Select a notification from the displayed list. - Verify that the system displays the full notification details including message. 3. View the selected notification and continue. - Verify that the viewed notification is deleted from the system. 4. Navigate to “View Notifications” again. - Verify that the previously viewed notification no longer appears in the notification list. Sreeja Reghukumar, please review --- .../Trenser.VehicleServiceSystem.vcxproj | 1 + ...enser.VehicleServiceSystem.vcxproj.filters | 3 + .../controllers/Controller.cpp | 22 +++++- .../controllers/Controller.h | 5 ++ .../services/UserManagementService.cpp | 44 +++++++++++ .../views/CustomerMenu.cpp | 2 + .../views/MenuHelper.h | 79 +++++++++++++++++++ 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj index a65c46d..aaca946 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj @@ -180,6 +180,7 @@ + diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters index 77d0509..c72bd44 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters @@ -233,5 +233,8 @@ Header Files\Models + + Header Files\Views + \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..298706c 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -1,4 +1,6 @@ +#include #include "Controller.h" +#include "User.h" bool Controller::login(const std::string& username, const std::string& password) { @@ -130,11 +132,29 @@ void Controller::completePayment(const std::string& invoiceID, util::PaymentMode util::Vector Controller::getNotifications() { - return util::Vector(); + const User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); + if (!authenticatedUser) + { + throw std::runtime_error("No user is currently logged in!"); + } + auto notifications = m_userManagementService.getUserNotifications(authenticatedUser->getId()); + int numberOfNotifications = notifications.getSize(); + util::Vector readOnlyNotifications; + for (int index = 0; index < numberOfNotifications; index++) + { + readOnlyNotifications.push_back(notifications[index]); + } + return readOnlyNotifications; } void Controller::deleteNotification(const std::string& notificationID) { + const User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); + if (!authenticatedUser) + { + throw std::runtime_error("No user is currently logged in!"); + } + m_userManagementService.deleteNotification(notificationID, authenticatedUser->getId()); } void Controller::configureNotifications(const std::string& userID, bool paymentNotifications, bool serviceNotifications) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..e1ecc49 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,8 @@ #include "Map.h" #include #include "Enums.h" +#include "AuthenticationManagementService.h" +#include "UserManagementService.h" class Service; class ComboPackage; @@ -14,6 +16,9 @@ class Notification; class Controller { +private: + AuthenticationManagementService m_authenticationManagementService; + UserManagementService m_userManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp index 2a5bd9e..bff09b1 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp @@ -1 +1,45 @@ +#include #include "UserManagementService.h" +#include "User.h" +#include "Vector.h" + +util::Vector UserManagementService::getUserNotifications(const std::string& userID) +{ + auto& usersMap = m_dataStore.getUsers(); + if (usersMap.find(userID) == -1) + { + throw std::runtime_error("No user found with given UserID"); + } + User* user = usersMap[userID]; + if (user) + { + auto& notifications = user->getNotifications(); + int numberOfNotifications = notifications.getSize(); + util::Vector notificationsVector; + for (int index = 0; index < numberOfNotifications; index++) + { + notificationsVector.push_back(notifications.getValueAt(index)); + } + return notificationsVector; + } + else + { + throw std::runtime_error("Invalid User object"); + } +} + +void UserManagementService::deleteNotification(const std::string& notificationID, const std::string& userID) +{ + auto& usersMap = m_dataStore.getUsers(); + if (usersMap.find(userID) == -1) + { + throw std::runtime_error("No user found with given UserID"); + } + User* user = usersMap[userID]; + auto& notifications = user->getNotifications(); + if (notifications.find(notificationID) == -1) + { + throw std::runtime_error("No notification found with given NotificationID"); + } + notifications.remove(notificationID); +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 047f471..6b3a868 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,7 @@ #include "CustomerMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "MenuHelper.h" void CustomerMenu::showMenu() { @@ -65,6 +66,7 @@ void CustomerMenu::viewInvoices() void CustomerMenu::viewNotifications() { + viewAndDeleteNotification(m_controller); } void CustomerMenu::configureNotifications() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h new file mode 100644 index 0000000..a84ba0f --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -0,0 +1,79 @@ +#pragma once +#include +#include "Vector.h" +#include "Controller.h" +#include "Notification.h" +#include "InputHelper.h" +#include "OutputHelper.h" + +inline const Notification* selectNotification(const util::Vector& notifications) +{ + if (notifications.getSize() == 0) + { + std::cout << "No notifications available." << std::endl; + return nullptr; + } + util::Map indexedNotifications; + std::cout << std::left + << std::setw(6) << "Index" + << std::setw(15) << "ID" + << std::setw(30) << "Title" + << std::setw(25) << "Timestamp" + << std::endl; + int currentIndex = 1; + for (int index = 0; index < notifications.getSize(); index++) + { + const Notification* currentNotification = notifications[index]; + if (currentNotification) + { + std::cout << std::left + << std::setw(6) << currentIndex + << std::setw(15) << currentNotification->getId() + << std::setw(30) << currentNotification->getTitle() + << std::setw(25) << currentNotification->getCreatedAt().toString() + << std::endl; + indexedNotifications.insert(currentIndex, currentNotification); + currentIndex++; + } + } + int selectedIndex; + std::cout << "Select notification: "; + util::read(selectedIndex); + if (!indexedNotifications.containsKey(selectedIndex)) + { + std::cout << "Invalid selection." << std::endl; + return nullptr; + } + return indexedNotifications[selectedIndex]; +} + +inline void displayNotification(const Notification* notification) +{ + util::clear(); + if (!notification) + { + std::cout << "Notification not found." << std::endl; + return; + } + std::cout << "Notification Details" << std::endl; + std::cout << "ID : " << notification->getId() << std::endl; + std::cout << "Title : " << notification->getTitle() << std::endl; + std::cout << "Timestamp : " << notification->getCreatedAt().toString() << std::endl; + std::cout << "Message : " << notification->getMessage() << std::endl; +} + +inline void viewAndDeleteNotification(Controller& controller) +{ + util::clear(); + auto notifications = controller.getNotifications(); + const Notification* selectedNotification = selectNotification(notifications); + if (!selectedNotification) + { + std::cout << "Failed to display notification!"; + util::pressEnter(); + return; + } + displayNotification(selectedNotification); + controller.deleteNotification(selectedNotification->getId()); + util::pressEnter(); +}