Implement View Customer Notifications
<UserStory> NOT001: View Customer Notifications </UserStory> <Changes> 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. </Changes> <Test> 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. </Test> <Review> Sreeja Reghukumar, please review </Review>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
#include <iomanip>
|
||||
#include "Vector.h"
|
||||
#include "Controller.h"
|
||||
#include "Notification.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
|
||||
inline const Notification* selectNotification(const util::Vector<const Notification*>& notifications)
|
||||
{
|
||||
if (notifications.getSize() == 0)
|
||||
{
|
||||
std::cout << "No notifications available." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
util::Map<int, const Notification*> 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();
|
||||
}
|
||||
Reference in New Issue
Block a user