Merge branch 'feature-service-management-ser003' into feature-service-management
This commit is contained in:
+9
-1
@@ -1,5 +1,6 @@
|
||||
#include "Controller.h"
|
||||
#include "InventoryItem.h"
|
||||
#include "Service.h"
|
||||
|
||||
bool Controller::login(const std::string& username, const std::string& password)
|
||||
{
|
||||
@@ -33,7 +34,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()
|
||||
@@ -110,6 +117,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()
|
||||
|
||||
+19
@@ -5,6 +5,7 @@
|
||||
#include "JobCard.h"
|
||||
#include "Timestamp.h"
|
||||
#include "Service.h"
|
||||
#include "Enums.h"
|
||||
#include "InventoryItem.h"
|
||||
|
||||
util::Map<std::string, ServiceBooking*> ServiceManagementService::getServiceBookings()
|
||||
@@ -82,4 +83,22 @@ void ServiceManagementService::createService(const std::string& name, const util
|
||||
throw std::runtime_error("Service with this ID Already exists.");
|
||||
}
|
||||
currentServices.insert(newService->getId(), newService);
|
||||
}
|
||||
|
||||
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,5 +1,6 @@
|
||||
#include <iomanip>
|
||||
#include "AdminMenu.h"
|
||||
#include "Service.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "ServiceBooking.h"
|
||||
@@ -285,8 +286,66 @@ void AdminMenu::createService()
|
||||
std::cout << "Service created sucessfully.\n";
|
||||
}
|
||||
|
||||
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