Implement View Service History

<UserStory> SER004: View Service History </UserStory>

<Changes>
    1. Added integration between Controller and ServiceManagementService to fetch service bookings by customer ID.
    2. Enhanced ServiceBooking model to store technician as a User* instead of a string for richer details.
    3. Implemented Controller::getServiceBookingsByUser to return a read-only map of bookings for safe access.
    4. Updated CustomerMenu::viewServiceHistory to display bookings in tabular format with aligned columns.
    5. Added condition check to show technician name if assigned, otherwise display "Not Assigned".
    6. Included booking status and discount percentage in the service history output.
</Changes>

<Test>

 Acceptance Criteria:
 1. System should fetch real-time status.
 2. Status should update automatically when technician changes it.
 3. Customer should be able to view history.

  Precondition:
  1. Customer is logged into the console application.
  2. At least one active service booking exists for the customer.
  3. Technician has permission to update booking status.

  Steps:
  1. Navigate to Customer menu and choose "View Service History".
    - Verify that the console displays current booking status along with technician assignment.
  2. Technician updates the status of a booking.
    - Verify that the console view reflects the updated status automatically.
  3. Customer views service history again.
    - Verify that the history shows the latest status changes.
</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
Jissin Mathew
2026-05-19 22:54:55 +05:30
parent 56c5c2dc70
commit fc7bb2569b
6 changed files with 84 additions and 8 deletions
@@ -1,4 +1,5 @@
#include "Controller.h"
#include "ServiceBooking.h"
bool Controller::login(const std::string& username, const std::string& password)
{
@@ -73,7 +74,13 @@ util::Map<std::string, const ServiceBooking*> Controller::getServiceBookings()
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookingsByUser(const std::string userID)
{
return util::Map<std::string, const ServiceBooking*>();
util::Map<std::string, const ServiceBooking*> readOnlyServiceBookingsByUserMap;
util::Map<std::string, ServiceBooking*> currentServiceBookingsByUser = m_serviceManagementService.getServiceBookings(userID);
for (int iterator = 0; iterator < currentServiceBookingsByUser.getSize(); iterator++)
{
readOnlyServiceBookingsByUserMap.insert(currentServiceBookingsByUser.getValueAt(iterator)->getId(), currentServiceBookingsByUser.getValueAt(iterator));
}
return readOnlyServiceBookingsByUserMap;
}
util::Map<std::string, const User*> Controller::getUsers()
@@ -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();
@@ -18,7 +18,7 @@ ServiceBooking::ServiceBooking(
const std::string& vehicleBrand,
const std::string& vehicleModel,
const std::string& assignedTechnicianId,
const std::string& assignedTechnician,
const User* assignedTechnician,
double discountPercentage
)
: m_id("SRV" + std::to_string(++m_uid)),
@@ -80,7 +80,7 @@ const std::string& ServiceBooking::getAssignedTechnicianId() const
return m_assignedTechnicianId;
}
const std::string& ServiceBooking::getAssignedTechnician() const
const User* ServiceBooking::getAssignedTechnician() const
{
return m_assignedTechnician;
}
@@ -135,7 +135,7 @@ void ServiceBooking::setAssignedTechnicianId(const std::string& assignedTechnici
m_assignedTechnicianId = assignedTechnicianId;
}
void ServiceBooking::setAssignedTechnician(const std::string& assignedTechnician)
void ServiceBooking::setAssignedTechnician(const User* assignedTechnician)
{
m_assignedTechnician = assignedTechnician;
}
@@ -19,7 +19,7 @@ private:
std::string m_vehicleBrand;
std::string m_vehicleModel;
std::string m_assignedTechnicianId;
std::string m_assignedTechnician;
const User* m_assignedTechnician;
double m_discountPercentage;
public:
ServiceBooking();
@@ -34,7 +34,7 @@ public:
const std::string& vehicleBrand,
const std::string& vehicleModel,
const std::string& assignedTechnicianId,
const std::string& assignedTechnician,
const User* assignedTechnician,
double discountPercentage
);
const std::string& getId() const;
@@ -46,7 +46,7 @@ public:
const std::string& getVehicleBrand() const;
const std::string& getVehicleModel() const;
const std::string& getAssignedTechnicianId() const;
const std::string& getAssignedTechnician() const;
const User* getAssignedTechnician() const;
double getDiscountPercentage() const;
void setId(const std::string& id);
void setStatus(const util::ServiceJobStatus& status);
@@ -57,6 +57,6 @@ public:
void setVehicleBrand(const std::string& vehicleBrand);
void setVehicleModel(const std::string& vehicleModel);
void setAssignedTechnicianId(const std::string& assignedTechnicianId);
void setAssignedTechnician(const std::string& assignedTechnician);
void setAssignedTechnician(const User*);
void setDiscountPercentage(double discountPercentage);
};
@@ -1 +1,25 @@
#include "ServiceManagementService.h"
#include "ServiceBooking.h"
util::Map<std::string, ServiceBooking*> ServiceManagementService::getServiceBookings()
{
return m_dataStore.getServiceBookings();
}
util::Map<std::string, ServiceBooking*> ServiceManagementService::getServiceBookings(const std::string& customerID)
{
util::Map<std::string, ServiceBooking*> currentServiceBookings = getServiceBookings();
util::Map<std::string, ServiceBooking*> currentUserServiceBookings;
if (currentServiceBookings.getSize() != 0)
{
for (int iterator = 0; iterator < currentServiceBookings.getSize(); iterator++)
{
auto currentServiceBooking = currentServiceBookings.getValueAt(iterator);
if (currentServiceBooking->getCustomerId() == customerID)
{
currentUserServiceBookings.insert(currentServiceBooking->getId(), currentServiceBooking);
}
}
}
return currentUserServiceBookings;
}
@@ -1,6 +1,10 @@
#include <iomanip>
#include "CustomerMenu.h"
#include "InputHelper.h"
#include "OutputHelper.h"
#include "User.h"
#include "ServiceBooking.h"
#include "Enums.h"
void CustomerMenu::showMenu()
{
@@ -53,6 +57,44 @@ void CustomerMenu::selectComboPackage()
void CustomerMenu::viewServiceHistory()
{
util::clear();
bool hasServiceHistory = false;
const User* currentUser = m_controller.getAuthenticatedUser();
std::string currentUserID = currentUser->getId();
util::Map<std::string, const ServiceBooking*> serviceBookingsByCurrentUser = m_controller.getServiceBookingsByUser(currentUserID);
if (serviceBookingsByCurrentUser.getSize() != 0)
{
std::cout << std::left
<< std::setw(12) << "Booking ID"
<< std::setw(20) << "Technician"
<< std::setw(15) << "Vehicle Brand"
<< std::setw(15) << "Vehicle Number"
<< std::setw(15) << "Vehicle Model"
<< std::setw(10) << "Discount %"
<< std::setw(12) << "Status"
<< std::endl;
for (int iterator = 0; iterator < serviceBookingsByCurrentUser.getSize(); iterator++)
{
const ServiceBooking* currentBooking = serviceBookingsByCurrentUser.getValueAt(iterator);
std::string technicianName = currentBooking->getAssignedTechnician() == nullptr
? "Not Assigned"
: currentBooking->getAssignedTechnician()->getName();
std::cout << std::left
<< std::setw(12) << currentBooking->getId()
<< std::setw(20) << technicianName
<< std::setw(15) << currentBooking->getVehicleBrand()
<< std::setw(15) << currentBooking->getVehicleNumber()
<< std::setw(15) << currentBooking->getVehicleModel()
<< std::setw(10) << currentBooking->getDiscountPercentage()
<< std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus())
<< std::endl;
hasServiceHistory = true;
}
}
if (!hasServiceHistory)
{
std::cout << "No history available." << std::endl;
}
}
void CustomerMenu::completePayments()