Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b76cae358 |
@@ -9,6 +9,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "ComboPackage.h"
|
#include "ComboPackage.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
@@ -28,7 +29,8 @@ Returns:
|
|||||||
ComboPackage::ComboPackage()
|
ComboPackage::ComboPackage()
|
||||||
: m_id("CMP" + std::to_string(++m_uid)),
|
: m_id("CMP" + std::to_string(++m_uid)),
|
||||||
m_status(util::State::ACTIVE),
|
m_status(util::State::ACTIVE),
|
||||||
m_discountPercentage(0.0) {}
|
m_discountPercentage(0.0) {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: ComboPackage
|
Function: ComboPackage
|
||||||
@@ -270,72 +272,38 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the combo package into a CSV-formatted string.
|
Description: Serializes the ComboPackage object into a SerializedComboPackage record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized combo package record
|
- SerializedComboPackage: Serialized representation of the combo package
|
||||||
*/
|
*/
|
||||||
std::string ComboPackage::serialize() const
|
SerializedComboPackage ComboPackage::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedComboPackage;
|
SerializedComboPackage serialized = {};
|
||||||
serializedComboPackage << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_packageName << ','
|
strcpy_s(serialized.packageName, sizeof(serialized.packageName), m_packageName.c_str());
|
||||||
<< m_discountPercentage << ','
|
strcpy_s(serialized.serviceIDs, sizeof(serialized.serviceIDs), getServiceIDsAsString(m_serviceIDs).c_str());
|
||||||
<< getServiceIDsAsString(m_serviceIDs) << ','
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedComboPackage.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a ComboPackage object.
|
Description: Deserializes a SerializedComboPackage record into a ComboPackage object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized combo package record
|
- serializedComboPackage: const SerializedComboPackage&, serialized combo package record
|
||||||
Returns:
|
Returns:
|
||||||
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
ComboPackage* ComboPackage::deserialize(const std::string& record)
|
ComboPackage* ComboPackage::deserialize(const SerializedComboPackage& serializedComboPackage)
|
||||||
{
|
{
|
||||||
std::string id, packageName;
|
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serializedComboPackage.serviceIDs);
|
||||||
std::string discountPercentageString, serviceIDsString, statusString;
|
|
||||||
double discountPercentage;
|
|
||||||
std::istringstream serializedComboPackage(record);
|
|
||||||
getline(serializedComboPackage, id, ',');
|
|
||||||
getline(serializedComboPackage, packageName, ',');
|
|
||||||
getline(serializedComboPackage, discountPercentageString, ',');
|
|
||||||
getline(serializedComboPackage, serviceIDsString, ',');
|
|
||||||
getline(serializedComboPackage, statusString, ',');
|
|
||||||
try
|
|
||||||
{
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid combo package data");
|
|
||||||
}
|
|
||||||
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serviceIDsString);
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<ComboPackage>(
|
return Factory::getObject<ComboPackage>(
|
||||||
id,
|
serializedComboPackage.id,
|
||||||
packageName,
|
serializedComboPackage.packageName,
|
||||||
discountPercentage,
|
serializedComboPackage.discountPercentage,
|
||||||
serviceIDs,
|
serviceIDs,
|
||||||
status
|
serializedComboPackage.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for combo package serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,PackageName,DiscountPercentage,ServiceIDs,Status")
|
|
||||||
*/
|
|
||||||
std::string ComboPackage::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,PackageName,DiscountPercentage,ServiceIDs,Status";
|
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ Date: 19-May-2026
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
|
class SerializedComboPackage;
|
||||||
|
|
||||||
class ComboPackage
|
class ComboPackage
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,6 @@ public:
|
|||||||
void setDiscountPercentage(double discountPercentage);
|
void setDiscountPercentage(double discountPercentage);
|
||||||
void setServices(const util::Map<std::string, Service*>& services);
|
void setServices(const util::Map<std::string, Service*>& services);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedComboPackage serialize() const;
|
||||||
static ComboPackage* deserialize(const std::string&);
|
static ComboPackage* deserialize(const SerializedComboPackage&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -9,6 +9,7 @@ Date:19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "JobCard.h"
|
#include "JobCard.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
@@ -28,7 +29,8 @@ JobCard::JobCard()
|
|||||||
m_booking(nullptr),
|
m_booking(nullptr),
|
||||||
m_service(nullptr),
|
m_service(nullptr),
|
||||||
m_technician(nullptr),
|
m_technician(nullptr),
|
||||||
m_status(util::ServiceJobStatus()) {}
|
m_status(util::ServiceJobStatus()) {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: JobCard
|
Function: JobCard
|
||||||
@@ -65,7 +67,8 @@ JobCard::JobCard(const std::string& bookingId,
|
|||||||
m_technician(technician),
|
m_technician(technician),
|
||||||
m_assignedDate(assignedDate),
|
m_assignedDate(assignedDate),
|
||||||
m_status(status),
|
m_status(status),
|
||||||
m_completionDate(completionDate) {}
|
m_completionDate(completionDate) {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: JobCard (parameterized constructor with ID)
|
Function: JobCard (parameterized constructor with ID)
|
||||||
@@ -351,79 +354,41 @@ void JobCard::setCompletionDate(const util::Timestamp& completionDate)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the job card into a CSV-formatted string.
|
Description: Serializes the JobCard object into a SerializedJobCard record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized job card record
|
- SerializedJobCard: Serialized representation of the job card
|
||||||
*/
|
*/
|
||||||
std::string JobCard::serialize() const
|
SerializedJobCard JobCard::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedJobCard;
|
SerializedJobCard serialized = {};
|
||||||
serializedJobCard << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_bookingId << ','
|
strcpy_s(serialized.bookingId, sizeof(serialized.bookingId), m_bookingId.c_str());
|
||||||
<< m_serviceId << ','
|
strcpy_s(serialized.serviceId, sizeof(serialized.serviceId), m_serviceId.c_str());
|
||||||
<< m_technicianId << ','
|
strcpy_s(serialized.technicianId, sizeof(serialized.technicianId), m_technicianId.c_str());
|
||||||
<< m_assignedDate.toString() << ','
|
serialized.assignedDate = m_assignedDate;
|
||||||
<< util::getServiceJobStatusString(m_status) << ','
|
serialized.status = m_status;
|
||||||
<< m_completionDate.toString();
|
serialized.completionDate = m_completionDate;
|
||||||
return serializedJobCard.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a JobCard object.
|
Description: Deserializes a SerializedJobCard record into a JobCard object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized job card record
|
- serializedJobCard: const SerializedJobCard&, serialized job card record
|
||||||
Returns:
|
Returns:
|
||||||
- JobCard*: Pointer to the deserialized JobCard object
|
- JobCard*: Pointer to the deserialized JobCard object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if timestamp parsing fails
|
|
||||||
*/
|
*/
|
||||||
JobCard* JobCard::deserialize(const std::string& record)
|
JobCard* JobCard::deserialize(const SerializedJobCard& serializedJobCard)
|
||||||
{
|
{
|
||||||
std::string id, bookingId, serviceId, technicianId;
|
|
||||||
std::string assignedDateString, statusString, completionDateString;
|
|
||||||
std::istringstream serializedJobCard(record);
|
|
||||||
getline(serializedJobCard, id, ',');
|
|
||||||
getline(serializedJobCard, bookingId, ',');
|
|
||||||
getline(serializedJobCard, serviceId, ',');
|
|
||||||
getline(serializedJobCard, technicianId, ',');
|
|
||||||
getline(serializedJobCard, assignedDateString, ',');
|
|
||||||
getline(serializedJobCard, statusString, ',');
|
|
||||||
getline(serializedJobCard, completionDateString, ',');
|
|
||||||
util::Timestamp assignedDate;
|
|
||||||
util::Timestamp completionDate;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assignedDate = util::Timestamp::fromString(assignedDateString);
|
|
||||||
completionDate = util::Timestamp::fromString(completionDateString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid timestamp");
|
|
||||||
}
|
|
||||||
util::ServiceJobStatus status = util::getServiceJobStatus(statusString);
|
|
||||||
return Factory::getObject<JobCard>(
|
return Factory::getObject<JobCard>(
|
||||||
id,
|
serializedJobCard.id,
|
||||||
bookingId,
|
serializedJobCard.bookingId,
|
||||||
serviceId,
|
serializedJobCard.serviceId,
|
||||||
technicianId,
|
serializedJobCard.technicianId,
|
||||||
assignedDate,
|
serializedJobCard.assignedDate,
|
||||||
status,
|
serializedJobCard.status,
|
||||||
completionDate
|
serializedJobCard.completionDate);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for job card serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate")
|
|
||||||
*/
|
|
||||||
std::string JobCard::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate";
|
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ Date:19-May-2026
|
|||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedJobCard;
|
||||||
|
|
||||||
class JobCard
|
class JobCard
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,6 @@ public:
|
|||||||
void setAssignedDate(const util::Timestamp& assignedDate);
|
void setAssignedDate(const util::Timestamp& assignedDate);
|
||||||
void setStatus(util::ServiceJobStatus status);
|
void setStatus(util::ServiceJobStatus status);
|
||||||
void setCompletionDate(const util::Timestamp& completionDate);
|
void setCompletionDate(const util::Timestamp& completionDate);
|
||||||
std::string serialize() const;
|
SerializedJobCard serialize() const;
|
||||||
static JobCard* deserialize(const std::string&);
|
static JobCard* deserialize(const SerializedJobCard&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -8,6 +8,7 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
@@ -27,7 +28,8 @@ Returns:
|
|||||||
Service::Service()
|
Service::Service()
|
||||||
: m_id("SRV" + std::to_string(++m_uid)),
|
: m_id("SRV" + std::to_string(++m_uid)),
|
||||||
m_status(util::State::ACTIVE),
|
m_status(util::State::ACTIVE),
|
||||||
m_laborCost(0.0) {}
|
m_laborCost(0.0) {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: Service
|
Function: Service
|
||||||
@@ -266,72 +268,38 @@ static util::Vector<std::string> getInventoryItemIDsAsVector(const std::string&
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the service into a CSV-formatted string.
|
Description: Serializes the Service object into a SerializedService record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized service record
|
- SerializedService: Serialized representation of the service
|
||||||
*/
|
*/
|
||||||
std::string Service::serialize() const
|
SerializedService Service::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedService;
|
SerializedService serialized = {};
|
||||||
serializedService << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_name << ','
|
strcpy_s(serialized.name, sizeof(serialized.name), m_name.c_str());
|
||||||
<< getInventoryItemIDsAsString(m_requiredInventoryItemIDs) << ','
|
strcpy_s(serialized.inventoryItemIDs, sizeof(serialized.inventoryItemIDs), getInventoryItemIDsAsString(m_requiredInventoryItemIDs).c_str());
|
||||||
<< m_laborCost << ','
|
serialized.laborCost = m_laborCost;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedService.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a Service object.
|
Description: Deserializes a SerializedService record into a Service object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized service record
|
- serializedService: const SerializedService&, serialized service record
|
||||||
Returns:
|
Returns:
|
||||||
- Service*: Pointer to the deserialized Service object
|
- Service*: Pointer to the deserialized Service object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if labor cost parsing fails
|
|
||||||
*/
|
*/
|
||||||
Service* Service::deserialize(const std::string& record)
|
Service* Service::deserialize(const SerializedService& serializedService)
|
||||||
{
|
{
|
||||||
std::string id, name;
|
util::Vector<std::string> inventoryItemIDs = getInventoryItemIDsAsVector(serializedService.inventoryItemIDs);
|
||||||
std::string inventoryItemIDsString, laborCostString, statusString;
|
|
||||||
double laborCost;
|
|
||||||
std::istringstream serializedService(record);
|
|
||||||
getline(serializedService, id, ',');
|
|
||||||
getline(serializedService, name, ',');
|
|
||||||
getline(serializedService, inventoryItemIDsString, ',');
|
|
||||||
getline(serializedService, laborCostString, ',');
|
|
||||||
getline(serializedService, statusString, ',');
|
|
||||||
util::Vector<std::string> inventoryItemIDs = getInventoryItemIDsAsVector(inventoryItemIDsString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
laborCost = std::stod(laborCostString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid labor cost");
|
|
||||||
}
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<Service>(
|
return Factory::getObject<Service>(
|
||||||
id,
|
serializedService.id,
|
||||||
name,
|
serializedService.name,
|
||||||
inventoryItemIDs,
|
inventoryItemIDs,
|
||||||
laborCost,
|
serializedService.laborCost,
|
||||||
status
|
serializedService.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for service serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Name,InventoryIDs,LaborCost,Status")
|
|
||||||
*/
|
|
||||||
std::string Service::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Name,InventoryIDs,LaborCost,Status";
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ Author: Trenser
|
|||||||
Date: 19-May-2026
|
Date: 19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
@@ -14,6 +13,7 @@ Date: 19-May-2026
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
class InventoryItem;
|
class InventoryItem;
|
||||||
|
struct SerializedService;
|
||||||
|
|
||||||
class Service
|
class Service
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,6 @@ public:
|
|||||||
void setRequiredInventoryItems(const util::Map<std::string, InventoryItem*>& requiredInventoryItems);
|
void setRequiredInventoryItems(const util::Map<std::string, InventoryItem*>& requiredInventoryItems);
|
||||||
void setLaborCost(double laborCost);
|
void setLaborCost(double laborCost);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedService serialize() const;
|
||||||
static Service* deserialize(const std::string&);
|
static Service* deserialize(const SerializedService&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
+30
-65
@@ -6,8 +6,10 @@ Description: Implementation file containing the method definitions of the
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "ServiceBooking.h"
|
#include "ServiceBooking.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
@@ -28,7 +30,8 @@ ServiceBooking::ServiceBooking()
|
|||||||
m_customer(nullptr),
|
m_customer(nullptr),
|
||||||
m_assignedTechnician(nullptr),
|
m_assignedTechnician(nullptr),
|
||||||
m_status(util::ServiceJobStatus::PENDING),
|
m_status(util::ServiceJobStatus::PENDING),
|
||||||
m_discountPercentage(0.0) {}
|
m_discountPercentage(0.0) {
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: ServiceBooking
|
Function: ServiceBooking
|
||||||
@@ -437,84 +440,46 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the service booking into a CSV-formatted string.
|
Description: Serializes the ServiceBooking object into a SerializedServiceBooking record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized booking record
|
- SerializedServiceBooking: Serialized representation of the service booking
|
||||||
*/
|
*/
|
||||||
std::string ServiceBooking::serialize() const
|
SerializedServiceBooking ServiceBooking::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedBooking;
|
SerializedServiceBooking serialized = {};
|
||||||
serializedBooking << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< util::getServiceJobStatusString(m_status) << ','
|
strcpy_s(serialized.serviceIDs, sizeof(serialized.serviceIDs), getServiceIDsAsString(m_serviceIDs).c_str());
|
||||||
<< getServiceIDsAsString(m_serviceIDs) << ','
|
strcpy_s(serialized.customerId, sizeof(serialized.customerId), m_customerId.c_str());
|
||||||
<< m_customerId << ','
|
strcpy_s(serialized.vehicleNumber, sizeof(serialized.vehicleNumber), m_vehicleNumber.c_str());
|
||||||
<< m_vehicleNumber << ','
|
strcpy_s(serialized.vehicleBrand, sizeof(serialized.vehicleBrand), m_vehicleBrand.c_str());
|
||||||
<< m_vehicleBrand << ','
|
strcpy_s(serialized.vehicleModel, sizeof(serialized.vehicleModel), m_vehicleModel.c_str());
|
||||||
<< m_vehicleModel << ','
|
strcpy_s(serialized.assignedTechnicianId, sizeof(serialized.assignedTechnicianId), m_assignedTechnicianId.c_str());
|
||||||
<< m_assignedTechnicianId << ','
|
serialized.status = m_status;
|
||||||
<< m_discountPercentage << ',';
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
return serializedBooking.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a ServiceBooking object.
|
Description: Deserializes a SerializedServiceBooking record into a ServiceBooking object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized booking record
|
- serializedServiceBooking: const SerializedServiceBooking&, serialized service booking record
|
||||||
Returns:
|
Returns:
|
||||||
- ServiceBooking*: Pointer to the deserialized ServiceBooking object
|
- ServiceBooking*: Pointer to the deserialized ServiceBooking object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if discount percentage parsing fails
|
|
||||||
*/
|
*/
|
||||||
ServiceBooking* ServiceBooking::deserialize(const std::string& record)
|
ServiceBooking* ServiceBooking::deserialize(const SerializedServiceBooking& serializedServiceBooking)
|
||||||
{
|
{
|
||||||
std::string id, customerId, vehicleNumber, vehicleBrand, vehicleModel, assignedTechnicianId;
|
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serializedServiceBooking.serviceIDs);
|
||||||
std::string serviceJobStatusString, serviceIDsString, discountPercentageString;
|
|
||||||
double discountPercentage;
|
|
||||||
std::istringstream serializedBooking(record);
|
|
||||||
getline(serializedBooking, id, ',');
|
|
||||||
getline(serializedBooking, serviceJobStatusString, ',');
|
|
||||||
getline(serializedBooking, serviceIDsString, ',');
|
|
||||||
getline(serializedBooking, customerId, ',');
|
|
||||||
getline(serializedBooking, vehicleNumber, ',');
|
|
||||||
getline(serializedBooking, vehicleBrand, ',');
|
|
||||||
getline(serializedBooking, vehicleModel, ',');
|
|
||||||
getline(serializedBooking, assignedTechnicianId, ',');
|
|
||||||
getline(serializedBooking, discountPercentageString, ',');
|
|
||||||
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serviceIDsString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid discount percentage");
|
|
||||||
}
|
|
||||||
util::ServiceJobStatus status = util::getServiceJobStatus(serviceJobStatusString);
|
|
||||||
return Factory::getObject<ServiceBooking>(
|
return Factory::getObject<ServiceBooking>(
|
||||||
id,
|
serializedServiceBooking.id,
|
||||||
status,
|
serializedServiceBooking.status,
|
||||||
serviceIDs,
|
serviceIDs,
|
||||||
customerId,
|
serializedServiceBooking.customerId,
|
||||||
vehicleNumber,
|
serializedServiceBooking.vehicleNumber,
|
||||||
vehicleBrand,
|
serializedServiceBooking.vehicleBrand,
|
||||||
vehicleModel,
|
serializedServiceBooking.vehicleModel,
|
||||||
assignedTechnicianId,
|
serializedServiceBooking.assignedTechnicianId,
|
||||||
discountPercentage
|
serializedServiceBooking.discountPercentage);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for service booking serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Status,ServiceIDs,CustomerID,VehicleNumber,VehicleBrand,VehicleModel,AssignedTechnicianID,DiscountPercentage")
|
|
||||||
*/
|
|
||||||
std::string ServiceBooking::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Status,ServiceIDs,CustomerID,VehicleNumber,VehicleBrand,VehicleModel,AssignedTechnicianID,DiscountPercentage";
|
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ Description: Header file declaring the ServiceBooking class, which represents
|
|||||||
Author: Trenser
|
Author: Trenser
|
||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
@@ -14,6 +15,7 @@ Date:19-May-2026
|
|||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedServiceBooking;
|
||||||
|
|
||||||
class ServiceBooking
|
class ServiceBooking
|
||||||
{
|
{
|
||||||
@@ -78,7 +80,6 @@ public:
|
|||||||
void setAssignedTechnicianId(const std::string& assignedTechnicianId);
|
void setAssignedTechnicianId(const std::string& assignedTechnicianId);
|
||||||
void setAssignedTechnician(User* assignedTechnician);
|
void setAssignedTechnician(User* assignedTechnician);
|
||||||
void setDiscountPercentage(double discountPercentage);
|
void setDiscountPercentage(double discountPercentage);
|
||||||
std::string serialize() const;
|
SerializedServiceBooking serialize() const;
|
||||||
static ServiceBooking* deserialize(const std::string&);
|
static ServiceBooking* deserialize(const SerializedServiceBooking&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user