From 9f882610b326543e498ca9d45d88e873cc3de964 Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Tue, 19 May 2026 15:26:19 +0530 Subject: [PATCH] Implement View Stock Level Functionality INV001: View Stock Level 1. Integrated InventoryManagementService into Controller to provide read-only access to inventory items. 2. Added implementation for InventoryManagementService::getInventoryItems to fetch data from DataStore. 3. Enhanced AdminMenu with viewStockLevels functionality to display inventory details (ID, part name, quantity, price). 4. Updated NotificationManagementService interface to provide concrete implementations for sendNotification, attach, detach, and notify methods. 5. Included necessary headers (InventoryItem, InventoryManagementService, iomanip) for new functionality. Precondition: 1. Admin user is logged into the system. 2. Inventory contains multiple items with varying stock levels. 3. Notification service is active and users are registered. Steps: 1. Navigate to Admin Menu and select "View Stock Levels". - Verify that the system displays all inventory items with ID, part name, quantity, and price. 2. Check items with sufficient stock. - Verify that they are displayed normally without highlighting. 3. Check items with low stock threshold. - Verify that these items are highlighted to indicate low availability. 4. Trigger a notification for a low-stock item. - Verify that the notification is sent to registered users successfully. Sreeja Reghukumar --- .../controllers/Controller.cpp | 9 +++++++- .../controllers/Controller.h | 3 +++ .../services/InventoryManagementService.cpp | 5 ++++ .../views/AdminMenu.cpp | 23 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..4b5b661 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -50,7 +50,14 @@ void Controller::purchaseComboPackage(const std::string& comboPackageID, const s util::Map Controller::getInventoryItems() { - return util::Map(); + auto inventoryIems = m_inventoryManagementService.getInventoryItems(); + util::Map readOnlyInventoryItems; + int inventoryItemsMapSize = inventoryIems.getSize(); + for (int index = 0; index < inventoryItemsMapSize; index++) + { + readOnlyInventoryItems.insert(inventoryIems.getKeyAt(index), inventoryIems.getValueAt(index)); + } + return readOnlyInventoryItems; } const InventoryItem* Controller::getInventoryItem(const std::string& inventoryItemID) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..a06695a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,7 @@ #include "Map.h" #include #include "Enums.h" +#include "InventoryManagementService.h"; class Service; class ComboPackage; @@ -14,6 +15,8 @@ class Notification; class Controller { +private: + InventoryManagementService m_inventoryManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp index 39ef719..3e0a872 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp @@ -1 +1,6 @@ #include "InventoryManagementService.h" + +util::Map InventoryManagementService::getInventoryItems() +{ + return m_dataStore.getInventoryItems(); +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index 0432f3c..aad212a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -1,4 +1,6 @@ +#include #include "AdminMenu.h" +#include "InventoryItem.h" #include "InputHelper.h" #include "OutputHelper.h" @@ -42,6 +44,27 @@ void AdminMenu::changePassword() void AdminMenu::viewStockLevels() { + auto inventoryItems = m_controller.getInventoryItems(); + std::cout << std::left << std::setw(15) << "Item ID" + << std::setw(25) << "Part Name" + << std::setw(10) << "Quantity" + << std::setw(10) << "Price" + << std::endl; + for (int iterator = 0; iterator < inventoryItems.getSize(); ++iterator) + { + const InventoryItem* item = inventoryItems.getValueAt(iterator); + if (item != nullptr) + { + if (item->getState() != util::State::INACTIVE) + { + std::cout << std::left << std::setw(15) << item->getId() + << std::setw(25) << item->getPartName() + << std::setw(10) << item->getQuantity() + << std::setw(10) << item->getPrice() + << std::endl; + } + } + } } void AdminMenu::addInventoryItem()