Implement Create Service for admin

<UserStory> SER002: Create Service </UserStory>

<Changes>
    1. Added integration between Controller and ServiceManagementService to support service creation.
    2. Implemented ServiceManagementService::createService with validation for duplicate service IDs and insertion into datastore.
    3. Enhanced AdminMenu with selectInventoryItems helper to display inventory in tabular format, allow selection, and handle exit condition.
    4. Updated AdminMenu::createService to prompt for service name, allow inventory selection, capture labour cost, and create service via Controller.
</Changes>

<Test>

 Acceptance Criteria:
 1. Admin enters new service name.
 2. Admin selects required parts for the services.
 3. Service created and visible to customers.

  Precondition:
  1. Admin is logged into the system.
  2. Inventory contains at least one active item.
  3. Datastore is available for storing services.

  Steps:
  1. Navigate to Admin menu and choose "Create Service".
    - Verify that the system prompts for service name.
  2. Select inventory items from the tabular list.
    - Verify that inactive items are skipped and active items can be added.
  3. Enter labour cost and confirm creation.
    - Verify that the service is created successfully and stored in datastore.
  4. Check customer view.
    - Verify that the newly created service is visible to customers.
</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
Jissin Mathew
2026-05-19 20:29:19 +05:30
parent 56c5c2dc70
commit e7f1b51d05
4 changed files with 102 additions and 1 deletions
@@ -1,4 +1,5 @@
#include "Controller.h" #include "Controller.h"
#include "InventoryItem.h"
bool Controller::login(const std::string& username, const std::string& password) bool Controller::login(const std::string& username, const std::string& password)
{ {
@@ -50,7 +51,6 @@ void Controller::purchaseComboPackage(const std::string& comboPackageID, const s
util::Map<std::string, const InventoryItem*> Controller::getInventoryItems() util::Map<std::string, const InventoryItem*> Controller::getInventoryItems()
{ {
return util::Map<std::string, const InventoryItem*>();
} }
const InventoryItem* Controller::getInventoryItem(const std::string& inventoryItemID) const InventoryItem* Controller::getInventoryItem(const std::string& inventoryItemID)
@@ -92,6 +92,7 @@ void Controller::createJobCard(const std::string& bookingID, const std::string&
void Controller::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost) void Controller::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost)
{ {
m_serviceManagementService.createService(name, inventoryItemIDs, laborCost);
} }
void Controller::removeService(const std::string& serviceID) void Controller::removeService(const std::string& serviceID)
@@ -2,6 +2,8 @@
#include "Map.h" #include "Map.h"
#include <string> #include <string>
#include "Enums.h" #include "Enums.h"
#include "InventoryManagementService.h"
#include "ServiceManagementService.h"
class Service; class Service;
class ComboPackage; class ComboPackage;
@@ -14,6 +16,8 @@ class Notification;
class Controller class Controller
{ {
private:
ServiceManagementService m_serviceManagementService;
public: public:
bool login(const std::string& username, const std::string& password); bool login(const std::string& username, const std::string& password);
void logout(); void logout();
@@ -1 +1,18 @@
#include "ServiceManagementService.h" #include "ServiceManagementService.h"
#include "Factory.h"
#include "Service.h"
void ServiceManagementService::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost)
{
Service* newService = Factory::getObject<Service>(name, inventoryItemIDs, laborCost);
if (newService == nullptr)
{
throw std::runtime_error("Unable to create new service.");
}
util::Map<std::string, Service*>& currentServices = m_dataStore.getServices();
if (currentServices.find(newService->getId()) != -1)
{
throw std::runtime_error("Service with this ID Already exists.");
}
currentServices.insert(newService->getId(), newService);
}
@@ -1,6 +1,8 @@
#include <iomanip>
#include "AdminMenu.h" #include "AdminMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
#include "OutputHelper.h" #include "OutputHelper.h"
#include "InventoryItem.h"
void AdminMenu::showMenu() void AdminMenu::showMenu()
{ {
@@ -60,8 +62,85 @@ void AdminMenu::assignJob()
{ {
} }
static void selectInventoryItems(util::Map<std::string, const InventoryItem*>& currentInventoryItems, util::Vector<std::string>& selectedInventoryItems)
{
bool doRun = true, hasInventoryItems = false;
util::Map<int, const InventoryItem*> currentInventoryMap;
int currentIndex = 1;
int choice;
if (currentInventoryItems.getSize() == 0)
{
std::cout << "Inventory empty.";
}
while (doRun)
{
bool hasInventoryItems = false;
int currentIndex = 1;
currentInventoryMap.clear();
std::cout << std::left
<< std::setw(6) << "Index"
<< std::setw(12) << "Item ID"
<< std::setw(20) << "Part Name"
<< std::setw(10) << "Price"
<< std::setw(10) << "Quantity"
<< std::endl;
for (int iterator = 0; iterator < currentInventoryItems.getSize(); iterator++)
{
const InventoryItem* currentInventoryItem = currentInventoryItems.getValueAt(iterator);
if (currentInventoryItem->getState() == util::State::INACTIVE)
{
continue;
}
std::cout << std::left
<< std::setw(6) << currentIndex
<< std::setw(12) << currentInventoryItem->getId()
<< std::setw(20) << currentInventoryItem->getPartName()
<< std::setw(10) << currentInventoryItem->getPrice()
<< std::setw(10) << currentInventoryItem->getQuantity()
<< std::endl;
hasInventoryItems = true;
currentInventoryMap.insert(currentIndex++, currentInventoryItem);
}
if (!hasInventoryItems)
{
std::cout << "No items present in the inventory." << std::endl;
doRun = false;
break;
}
std::cout << "Select the item (Index) or enter -1 to exit: ";
util::read(choice);
if (choice == -1)
{
doRun = false;
}
else if (currentInventoryMap.find(choice) != -1)
{
selectedInventoryItems.push_back(currentInventoryMap.getValueAt(choice)->getId());
std::cout << "Item added successfully." << std::endl;
}
else
{
std::cout << "Enter a valid integer." << std::endl;
}
}
}
void AdminMenu::createService() void AdminMenu::createService()
{ {
util::clear();
std::string serviceName;
double labourCost;
std::cout << "Enter the service name: ";
util::read(serviceName);
util::Map<std::string, const InventoryItem*> currentInventoryItems = m_controller.getInventoryItems();
util::Vector<std::string> selectedInventoryItems;
selectInventoryItems(currentInventoryItems,selectedInventoryItems);
std::cout << "Enter the labour cost: ";
util::read(labourCost);
m_controller.createService(serviceName, selectedInventoryItems, labourCost);
std::cout << "Service created sucessfully.\n";
} }
void AdminMenu::removeService() void AdminMenu::removeService()