Implement Remove Combo Package for admin

<UserStory> SER003: Remove Combo Package </UserStory>

<Changes>

Added integration between Controller and ServiceManagementService to support combo package removal.

Implemented ServiceManagementService::removeComboPackage with validation for package ID and marking state as INACTIVE.

Enhanced AdminMenu with displayComboPackagesWithIndex helper to show packages in tabular format with index.

Updated AdminMenu::selectComboPackage to allow selection of active packages only and return selected package ID.

Updated AdminMenu::removeComboPackage to prompt for selection, confirm removal, and provide success/failure feedback.
</Changes>

<Test>

Acceptance Criteria:

Admin selects package ID.

System confirms deletion.

Package removed from customer menu.

Precondition:

Admin is logged into the system.

At least one active combo package exists.

Datastore is available for storing combo packages.

Steps:

Navigate to Admin menu and choose "Remove Combo Package".

Verify that the system displays available active packages in tabular format with index.

Select a package ID from the list.

Verify that inactive packages are skipped and only active ones are selectable.

Confirm removal.

Verify that the package is marked INACTIVE and removed from customer menu.

Check customer view.

Verify that the removed package is no longer visible to customers.
</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
Avinash Rajesh
2026-05-21 12:44:00 +05:30
parent 56c5c2dc70
commit ab6eed5ee6
4 changed files with 124 additions and 2 deletions
@@ -1,4 +1,5 @@
#include "Controller.h"
#include "ComboPackage.h"
bool Controller::login(const std::string& username, const std::string& password)
{
@@ -37,7 +38,17 @@ util::Map<std::string, const Service*> Controller::getServices()
util::Map<std::string, const ComboPackage*> Controller::getComboPackages()
{
return util::Map<std::string, const ComboPackage*>();
util::Map<std::string, ComboPackage*> currentAvailableComboPackages = m_serviceManagementService.getComboPackages();
util::Map<std::string, const ComboPackage*> readOnlyComboPackages;
for (int iterator = 0; iterator < currentAvailableComboPackages.getSize(); iterator++)
{
ComboPackage* currentComboPackage = currentAvailableComboPackages.getValueAt(iterator);
if (currentComboPackage)
{
readOnlyComboPackages.insert(currentComboPackage->getId(), currentComboPackage);
}
}
return readOnlyComboPackages;
}
void Controller::purchaseService(const util::Vector<std::string>& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel)
@@ -117,6 +128,7 @@ void Controller::createComboPackage(const std::string& name, const util::Vector<
void Controller::removeComboPackage(const std::string& comboPackageID)
{
m_serviceManagementService.removeComboPackage(comboPackageID);
}
util::Map<std::string, const Invoice*> Controller::getInvoicesByUser()
@@ -1,7 +1,8 @@
#pragma once
#include "Map.h"
#include <string>
#include "Map.h"
#include "Enums.h"
#include "ServiceManagementService.h"
class Service;
class ComboPackage;
@@ -14,6 +15,8 @@ class Notification;
class Controller
{
private:
ServiceManagementService m_serviceManagementService;
public:
bool login(const std::string& username, const std::string& password);
void logout();
@@ -1 +1,28 @@
#include "ServiceManagementService.h"
#include "ComboPackage.h"
#include "Enums.h"
util::Map<std::string, ComboPackage*> ServiceManagementService::getComboPackages()
{
return m_dataStore.getComboPackages();
}
void ServiceManagementService::removeComboPackage(const std::string& comboPackageID)
{
bool removed = false;
util::Map<std::string, ComboPackage*>& currentComboPackages = m_dataStore.getComboPackages();
for (int iterator = 0; iterator < currentComboPackages.getSize(); iterator++)
{
ComboPackage* currentComboPackage = currentComboPackages.getValueAt(iterator);
if (currentComboPackage && currentComboPackage->getId() == comboPackageID)
{
currentComboPackage->setState(util::State::INACTIVE);
removed = true;
break;
}
}
if (!removed)
{
throw std::runtime_error("Combo package with ID '" + comboPackageID + "' not found.");
}
}
@@ -1,6 +1,10 @@
#include <iostream>
#include <iomanip>
#include "AdminMenu.h"
#include "InputHelper.h"
#include "OutputHelper.h"
#include "ComboPackage.h"
#include "Enums.h"
void AdminMenu::showMenu()
{
@@ -80,8 +84,84 @@ void AdminMenu::createComboPackages()
{
}
static void displayComboPackagesWithIndex(util::Map<int, const ComboPackage*>& currentComboPackageIndexMap)
{
for (int iterator = 0; iterator < currentComboPackageIndexMap.getSize(); iterator++)
{
const ComboPackage* currentComboPackage = currentComboPackageIndexMap.getValueAt(iterator);
if (currentComboPackage == nullptr)
{
throw std::runtime_error("Error accessing the combopackage.\n");
}
if (iterator == 0)
{
std::cout << std::left
<< std::setw(8) << "Index"
<< std::setw(10) << "ID"
<< std::setw(20) << "Package Name"
<< std::setw(15) << "Discount (%)"
<< "\n";
}
std::cout << std::left
<< std::setw(8) << currentComboPackageIndexMap.getKeyAt(iterator)
<< std::setw(10) << currentComboPackage->getId()
<< std::setw(20) << currentComboPackage->getPackageName()
<< std::setw(15) << currentComboPackage->getDiscountPercentage()
<< "\n";
}
}
static std::string selectComboPackage(util::Map<std::string, const ComboPackage*>& currentComboPackages)
{
util::Map<int, const ComboPackage*> currentComboPackageIndexMap;
if (currentComboPackages.getSize() == 0)
{
throw std::runtime_error("No combo packages are available.\n");
}
int currentIndex = 1, choice, selectedIndex;
for (int iterator = 0; iterator < currentComboPackages.getSize(); iterator++)
{
if (currentComboPackages.getValueAt(iterator)->getState() == util::State::INACTIVE)
{
continue;
}
currentComboPackageIndexMap.insert(currentIndex++, currentComboPackages.getValueAt(iterator));
}
if (currentComboPackageIndexMap.getSize() == 0)
{
throw std::runtime_error("No combo packages currently active.");
}
displayComboPackagesWithIndex(currentComboPackageIndexMap);
std::cout << "Enter your choice(Index): ";
util::read(choice);
selectedIndex = currentComboPackageIndexMap.find(choice);
if (selectedIndex != -1)
{
std::string selectedComboPackageID = currentComboPackageIndexMap.getValueAt(selectedIndex)->getId();
return selectedComboPackageID;
}
else
{
std::cout << "Enter a valid choice.\n";
return "";
}
}
void AdminMenu::removeComboPackage()
{
util::clear();
util::Map<std::string, const ComboPackage*> currentComboPackages = m_controller.getComboPackages();
std::string selectedComboPackageID = selectComboPackage(currentComboPackages);
if (selectedComboPackageID != "")
{
m_controller.removeComboPackage(selectedComboPackageID);
std::cout << "Combo Package removed successfully.\n";
}
else
{
std::cout << "Combo package removal failed.\n";
}
util::pressEnter();
}
void AdminMenu::viewNotifications()