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();
+}