Fix View Service History and View Notification Issue

- Updated sendNotification in InventoryManagementService, PaymentManagementService, and ServiceManagementService to use only the provided title instead of prefixing with service name.
- Added "View Service History" header in CustomerMenu::viewServiceHistory for clarity.
- Adjusted column widths in service history table for better alignment:
  - Booking ID column widened to 15.
  - Vehicle Brand, Vehicle Number, Vehicle Model, Discount %, and Status columns widened to 20.
- Updated output formatting in CustomerMenu::viewServiceHistory to match new widths.
- Added "View and Delete Notification" header in MenuHelper::viewAndDeleteNotification for clarity.
- Moved empty notification validation from selectNotification to viewAndDeleteNotification:
  - Displays "No notifications available." message.
  - Added util::pressEnter() prompt before returning when no notifications exist.
- Increased Notification title column width from 30 to 35 in selectNotification for improved readability.

Fixes #1748
This commit is contained in:
Avinash Rajesh
2026-05-26 18:48:23 +05:30
committed by Joel Thomas
parent a87af89a8a
commit 80b91f3f1b
5 changed files with 24 additions and 21 deletions
@@ -323,7 +323,7 @@ void InventoryManagementService::sendNotification(User* user, const std::string&
Factory::getObject<Notification>(
user->getId(),
user,
"InventoryManagementService: " + title,
title,
message,
util::Timestamp()
);
@@ -86,7 +86,7 @@ void PaymentManagementService::sendNotification(User* user, const std::string& t
Factory::getObject<Notification>(
user->getId(),
user,
"PaymentManagementService: " + title,
title,
message,
util::Timestamp()
);
@@ -175,7 +175,7 @@ void ServiceManagementService::sendNotification(User* user, const std::string& t
Factory::getObject<Notification>(
user->getId(),
user,
"ServiceManagementService: " + title,
title,
message,
util::Timestamp()
);
@@ -260,16 +260,17 @@ void CustomerMenu::viewServiceHistory()
const User* currentUser = m_controller.getAuthenticatedUser();
std::string currentUserID = currentUser->getId();
util::Map<std::string, const ServiceBooking*> serviceBookingsByCurrentUser = m_controller.getServiceBookingsByUser(currentUserID);
std::cout << "View Service History" << std::endl;
if (serviceBookingsByCurrentUser.getSize() != 0)
{
std::cout << std::left
<< std::setw(12) << "Booking ID"
<< std::setw(15) << "Booking ID"
<< std::setw(20) << "Technician"
<< std::setw(15) << "Vehicle Brand"
<< std::setw(15) << "Vehicle Number"
<< std::setw(15) << "Vehicle Model"
<< std::setw(10) << "Discount %"
<< std::setw(12) << "Status"
<< std::setw(20) << "Vehicle Brand"
<< std::setw(20) << "Vehicle Number"
<< std::setw(20) << "Vehicle Model"
<< std::setw(20) << "Discount %"
<< std::setw(20) << "Status"
<< std::endl;
for (int iterator = 0; iterator < serviceBookingsByCurrentUser.getSize(); iterator++)
{
@@ -278,13 +279,13 @@ void CustomerMenu::viewServiceHistory()
? "Not Assigned"
: currentBooking->getAssignedTechnician()->getName();
std::cout << std::left
<< std::setw(12) << currentBooking->getId()
<< std::setw(15) << currentBooking->getId()
<< std::setw(20) << technicianName
<< std::setw(15) << currentBooking->getVehicleBrand()
<< std::setw(15) << currentBooking->getVehicleNumber()
<< std::setw(15) << currentBooking->getVehicleModel()
<< std::setw(10) << currentBooking->getDiscountPercentage()
<< std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus())
<< std::setw(20) << currentBooking->getVehicleBrand()
<< std::setw(20) << currentBooking->getVehicleNumber()
<< std::setw(20) << currentBooking->getVehicleModel()
<< std::setw(20) << currentBooking->getDiscountPercentage()
<< std::setw(20) << util::getServiceJobStatusString(currentBooking->getStatus())
<< std::endl;
hasServiceHistory = true;
}
@@ -529,11 +529,6 @@ Return type: const Notification* - pointer to the selected notification
*/
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"
@@ -550,7 +545,7 @@ inline const Notification* selectNotification(const util::Vector<const Notificat
std::cout << std::left
<< std::setw(6) << currentIndex
<< std::setw(15) << currentNotification->getId()
<< std::setw(30) << currentNotification->getTitle()
<< std::setw(35) << currentNotification->getTitle()
<< std::setw(25) << currentNotification->getCreatedAt().toString()
<< std::endl;
indexedNotifications.insert(currentIndex, currentNotification);
@@ -603,6 +598,13 @@ inline void viewAndDeleteNotification(Controller& controller)
{
util::clear();
auto notifications = controller.getNotifications();
std::cout << "View and Delete Notification" << std::endl;
if (notifications.getSize() == 0)
{
std::cout << "No notifications available." << std::endl;
util::pressEnter();
return;
}
const Notification* selectedNotification = selectNotification(notifications);
if (!selectedNotification)
{