Implement Remove Service for admin
<UserStory> SER003: Remove Service </UserStory>
<Changes>
1. Added integration between Controller and ServiceManagementService to support service removal.
2. Implemented ServiceManagementService::removeService with validation for service existence and marking as INACTIVE.
3. Enhanced Controller::getServices to return a read-only map of services for safe UI access.
4. Added AdminMenu::selectServicesToRemove helper to list active services in tabular format and capture user choice.
5. Updated AdminMenu::removeService to prompt for service selection, delegate removal to Controller, and display success/failure messages.
</Changes>
<Test>
Acceptance Criteria:
1. Admin selects service ID.
2. System confirms deletion.
3. Service removed from customer menu.
Precondition:
1. Admin is logged into the system.
2. At least one active service exists in the datastore.
3. Customer menu displays available services.
Steps:
1. Navigate to Admin menu and choose "Remove Service".
- Verify that the system lists active services in tabular format.
2. Select a service ID from the list.
- Verify that the system confirms deletion.
3. Check customer menu.
- Verify that the removed service no longer appears.
</Test>
<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
+9
-1
@@ -1,4 +1,5 @@
|
||||
#include "Controller.h"
|
||||
#include "Service.h"
|
||||
|
||||
bool Controller::login(const std::string& username, const std::string& password)
|
||||
{
|
||||
@@ -32,7 +33,13 @@ void Controller::updateUserDetails(const std::string& email, const std::string&
|
||||
|
||||
util::Map<std::string, const Service*> Controller::getServices()
|
||||
{
|
||||
return util::Map<std::string, const Service*>();
|
||||
util::Map<std::string, Service*> currentServices = m_serviceManagementService.getServices();
|
||||
util::Map<std::string, const Service*> readOnlyServices;
|
||||
for (int iterator = 0; iterator < currentServices.getSize(); iterator++)
|
||||
{
|
||||
readOnlyServices.insert(currentServices.getValueAt(iterator)->getId(), currentServices.getValueAt(iterator));
|
||||
}
|
||||
return readOnlyServices;
|
||||
}
|
||||
|
||||
util::Map<std::string, const ComboPackage*> Controller::getComboPackages()
|
||||
@@ -96,6 +103,7 @@ void Controller::createService(const std::string& name, const util::Vector<std::
|
||||
|
||||
void Controller::removeService(const std::string& serviceID)
|
||||
{
|
||||
m_serviceManagementService.removeService(serviceID);
|
||||
}
|
||||
|
||||
util::Map<std::string, const JobCard*> Controller::getJobCardsByUser()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Map.h"
|
||||
#include <string>
|
||||
#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();
|
||||
|
||||
+20
@@ -1 +1,21 @@
|
||||
#include "ServiceManagementService.h"
|
||||
#include "Service.h"
|
||||
#include "Enums.h"
|
||||
|
||||
util::Map<std::string, Service*> ServiceManagementService::getServices()
|
||||
{
|
||||
return m_dataStore.getServices();
|
||||
}
|
||||
|
||||
void ServiceManagementService::removeService(const std::string& serviceID)
|
||||
{
|
||||
util::Map<std::string, Service*> currentServices = getServices();
|
||||
if (currentServices.find(serviceID) != -1)
|
||||
{
|
||||
currentServices.getValueAt(currentServices.find(serviceID))->setState(util::State::INACTIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Service not found.");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <iomanip>
|
||||
#include "AdminMenu.h"
|
||||
#include "Service.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
|
||||
@@ -64,8 +66,66 @@ void AdminMenu::createService()
|
||||
{
|
||||
}
|
||||
|
||||
static std::string selectServicesToRemove(util::Map<std::string, const Service*> currentServices)
|
||||
{
|
||||
util::Map<int, const Service*> currentServicesMap;
|
||||
bool hasServices = false;
|
||||
int currentIndex = 1, choice;
|
||||
std::cout << std::left
|
||||
<< std::setw(6) << "Index"
|
||||
<< std::setw(12) << "Service ID"
|
||||
<< std::setw(20) << "Name"
|
||||
<< std::setw(10) << "Labor Cost"
|
||||
<< std::endl;
|
||||
for (int iterator = 0; iterator < currentServices.getSize(); iterator++)
|
||||
{
|
||||
const Service* currentService = currentServices.getValueAt(iterator);
|
||||
if (currentService->getState() == util::State::INACTIVE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::cout << std::left
|
||||
<< std::setw(6) << currentIndex
|
||||
<< std::setw(12) << currentService->getId()
|
||||
<< std::setw(20) << currentService->getName()
|
||||
<< std::setw(10) << currentService->getLaborCost()
|
||||
<< std::endl;
|
||||
hasServices = true;
|
||||
currentServicesMap.insert(currentIndex++, currentService);
|
||||
}
|
||||
if (!hasServices)
|
||||
{
|
||||
std::cout << "No services currently available." << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::cout << "Enter your choice: ";
|
||||
util::read(choice);
|
||||
if (currentServicesMap.find(choice) != -1)
|
||||
{
|
||||
return currentServicesMap.getValueAt(currentServicesMap.find(choice))->getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid choice." << std::endl;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void AdminMenu::removeService()
|
||||
{
|
||||
util::clear();
|
||||
std::string selectedServiceID;
|
||||
util::Map<std::string, const Service*> currentServices = m_controller.getServices();
|
||||
selectedServiceID = selectServicesToRemove(currentServices);
|
||||
if (selectedServiceID != "")
|
||||
{
|
||||
m_controller.removeService(selectedServiceID);
|
||||
std::cout << "Service removed sucessfully.";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to remove service.";
|
||||
}
|
||||
}
|
||||
|
||||
void AdminMenu::addTechnician()
|
||||
|
||||
Reference in New Issue
Block a user