76f13b526e
<UserStory> CUS006 Purchase Individual Service </UserStory>
<Changes>
1. Added service selection flow in CustomerMenu to display active services, allow customer to choose a service, and collect vehicle details for booking.
2. Implemented Controller::purchaseService to delegate service booking requests to ServiceManagementService.
3. Added ServiceManagementService::purchaseService logic to validate authenticated user, fetch selected services, create a ServiceBooking, and persist it in DataStore.
4. Updated ServiceBooking constructor and assigned technician handling to use User* references instead of technician name strings.
5. Integrated ServiceManagementService dependency into Controller
</Changes>
<Test>
Validate customer service booking flow and service status tracking
Precondition:
1. Customer account exists and is logged into the system.
2. Active services are available in the system.
3. Service bookings can be created and stored in DataStore.
4. Technician account exists to update service status.
Steps:
1. Navigate to Customer Menu and select the individual service booking option.
2. View the list of active services and select a service.
3. Enter vehicle number, vehicle brand, and vehicle model, then confirm booking.
- Verify that the service booking is created successfully with an initial status.
4. Technician updates the service booking status.
- Verify that the latest status is reflected in the system.
5. Customer refreshes or views service booking history.
- Verify that the updated status is shown correctly in booking history.
</Test>
<Review>
Sreeja Reghukumar, please review
</Review>
40 lines
1.7 KiB
C++
40 lines
1.7 KiB
C++
#include <stdexcept>
|
|
#include "ServiceManagementService.h"
|
|
#include "AuthenticationManagementService.h"
|
|
#include "Service.h"
|
|
#include "ServiceBooking.h"
|
|
#include "Factory.h"
|
|
|
|
void ServiceManagementService::purchaseService(const util::Vector<std::string>& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel)
|
|
{
|
|
AuthenticationManagementService m_authenticationManagementService;
|
|
auto authenticatedUser = m_authenticationManagementService.getAuthenticatedUser();
|
|
if (authenticatedUser == nullptr)
|
|
{
|
|
throw std::runtime_error("No user is currently logged in!");
|
|
}
|
|
auto& servicesMap = m_dataStore.getServices();
|
|
auto& serviceBookingMap = m_dataStore.getServiceBookings();
|
|
util::Map<std::string, Service*> selectedServices;
|
|
int selectedServicesCount = serviceIDs.getSize();
|
|
for (int index = 0; index < selectedServicesCount; index++)
|
|
{
|
|
int serviceIndex = servicesMap.find(serviceIDs[index]);
|
|
if (serviceIndex == -1)
|
|
{
|
|
throw std::runtime_error("Service not found!");
|
|
}
|
|
Service* service = servicesMap.getValueAt(serviceIndex);
|
|
selectedServices[service->getId()] = service;
|
|
}
|
|
ServiceBooking* serviceBooking = Factory::getObject<ServiceBooking>(util::ServiceJobStatus::STARTED, selectedServices, authenticatedUser->getId(), authenticatedUser, vehicleNumber, vehicleBrand, vehicleModel, 0);
|
|
if (serviceBooking == nullptr)
|
|
{
|
|
throw std::runtime_error("Failed to create service booking");
|
|
}
|
|
serviceBookingMap[serviceBooking->getId()] = serviceBooking;
|
|
sendNotification(authenticatedUser,
|
|
"Service Booking succeeded",
|
|
"Your service booking has been successfully placed with ID " + serviceBooking->getId());
|
|
}
|