finish ser/deser
This commit is contained in:
+44
-11
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
#include "Enums.h"
|
||||||
|
#include "Timestamp.h"
|
||||||
|
|
||||||
struct SerializedUser
|
struct SerializedUser
|
||||||
{
|
{
|
||||||
@@ -15,7 +17,11 @@ struct SerializedUser
|
|||||||
|
|
||||||
struct SerializedNotification
|
struct SerializedNotification
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
|
char recipientUserId[64];
|
||||||
|
char title[128];
|
||||||
|
char message[1024];
|
||||||
|
util::Timestamp createdAt;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerializedService
|
struct SerializedService
|
||||||
@@ -29,30 +35,57 @@ struct SerializedService
|
|||||||
|
|
||||||
struct SerializedComboPackage
|
struct SerializedComboPackage
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
|
char packageName[128];
|
||||||
|
double discountPercentage;
|
||||||
|
char serviceIDs[1024];
|
||||||
|
util::State status;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerializedInventoryItem
|
struct SerializedInventoryItem
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
|
char partName[128];
|
||||||
|
int quantity;
|
||||||
|
double price;
|
||||||
|
util::State status;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerializedServiceBooking
|
struct SerializedServiceBooking
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
|
util::ServiceJobStatus status;
|
||||||
|
char serviceIDs[1024];
|
||||||
|
char customerId[64];
|
||||||
|
char vehicleNumber[64];
|
||||||
|
char vehicleBrand[64];
|
||||||
|
char vehicleModel[64];
|
||||||
|
char assignedTechnicianId[64];
|
||||||
|
double discountPercentage;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerializedJobCard
|
struct SerializedJobCard
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
|
char bookingId[64];
|
||||||
|
char serviceId[64];
|
||||||
|
char technicianId[64];
|
||||||
|
util::Timestamp assignedDate;
|
||||||
|
util::ServiceJobStatus status;
|
||||||
|
util::Timestamp completionDate;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SerializedInvoice
|
struct SerializedInvoice
|
||||||
{
|
{
|
||||||
|
char id[64];
|
||||||
};
|
char bookingId[64];
|
||||||
|
util::Timestamp invoiceDate;
|
||||||
struct SerializedPayment
|
char partIDs[1024];
|
||||||
{
|
double laborCost;
|
||||||
|
double partsCost;
|
||||||
|
double discountPercentage;
|
||||||
|
double totalAmount;
|
||||||
|
util::Timestamp paymentDate;
|
||||||
|
util::PaymentMode paymentMethod;
|
||||||
|
util::PaymentStatus status;
|
||||||
};
|
};
|
||||||
@@ -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"
|
||||||
@@ -270,72 +271,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();
|
|
||||||
};
|
};
|
||||||
+19
-54
@@ -8,6 +8,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
@@ -206,73 +207,37 @@ void InventoryItem::setState(util::State status)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the inventory item into a CSV-formatted string.
|
Description: Serializes the InventoryItem object into a SerializedInventoryItem record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized inventory item record
|
- SerializedInventoryItem: Serialized representation of the inventory item
|
||||||
*/
|
*/
|
||||||
std::string InventoryItem::serialize() const
|
SerializedInventoryItem InventoryItem::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedInventoryItem;
|
SerializedInventoryItem serialized = {};
|
||||||
serializedInventoryItem << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_partName << ','
|
strcpy_s(serialized.partName, sizeof(serialized.partName), m_partName.c_str());
|
||||||
<< m_quantity << ','
|
serialized.quantity = m_quantity;
|
||||||
<< m_price << ','
|
serialized.price = m_price;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedInventoryItem.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into an InventoryItem object.
|
Description: Deserializes a SerializedInventoryItem record into an InventoryItem object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized inventory item record
|
- serializedInventoryItem: const SerializedInventoryItem&, serialized inventory item record
|
||||||
Returns:
|
Returns:
|
||||||
- InventoryItem*: Pointer to the deserialized InventoryItem object
|
- InventoryItem*: Pointer to the deserialized InventoryItem object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
InventoryItem* InventoryItem::deserialize(const std::string& record)
|
InventoryItem* InventoryItem::deserialize(const SerializedInventoryItem& serializedInventoryItem)
|
||||||
{
|
{
|
||||||
std::string id, partName;
|
|
||||||
std::string quantityString, priceString, statusString;
|
|
||||||
int quantity;
|
|
||||||
double price;
|
|
||||||
std::istringstream serializedInventoryItem(record);
|
|
||||||
getline(serializedInventoryItem, id, ',');
|
|
||||||
getline(serializedInventoryItem, partName, ',');
|
|
||||||
getline(serializedInventoryItem, quantityString, ',');
|
|
||||||
getline(serializedInventoryItem, priceString, ',');
|
|
||||||
getline(serializedInventoryItem, statusString, ',');
|
|
||||||
try
|
|
||||||
{
|
|
||||||
quantity = std::stoi(quantityString);
|
|
||||||
price = std::stod(priceString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid inventory item data");
|
|
||||||
}
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<InventoryItem>(
|
return Factory::getObject<InventoryItem>(
|
||||||
id,
|
serializedInventoryItem.id,
|
||||||
partName,
|
serializedInventoryItem.partName,
|
||||||
quantity,
|
serializedInventoryItem.quantity,
|
||||||
price,
|
serializedInventoryItem.price,
|
||||||
status
|
serializedInventoryItem.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for inventory item serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,PartName,Quantity,Price,Status")
|
|
||||||
*/
|
|
||||||
std::string InventoryItem::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,PartName,Quantity,Price,Status";
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,12 @@ Author: Trenser
|
|||||||
Date: 19-May-2026
|
Date: 19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
|
struct SerializedInventoryItem;
|
||||||
|
|
||||||
class InventoryItem
|
class InventoryItem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -34,7 +35,6 @@ public:
|
|||||||
void setQuantity(int quantity);
|
void setQuantity(int quantity);
|
||||||
void setPrice(double price);
|
void setPrice(double price);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedInventoryItem serialize() const;
|
||||||
static InventoryItem* deserialize(const std::string&);
|
static InventoryItem* deserialize(const SerializedInventoryItem&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -9,6 +9,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Invoice.h"
|
#include "Invoice.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
@@ -473,100 +474,50 @@ static util::Vector<std::string> getPartIDsAsVector(const std::string& partIDsSt
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the invoice into a CSV-formatted string.
|
Description: Serializes the Invoice object into a SerializedInvoice record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized invoice record
|
- SerializedInvoice: Serialized representation of the invoice
|
||||||
*/
|
*/
|
||||||
std::string Invoice::serialize() const
|
SerializedInvoice Invoice::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedInvoice;
|
SerializedInvoice serialized = {};
|
||||||
serializedInvoice << 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_invoiceDate.toString() << ','
|
strcpy_s(serialized.partIDs, sizeof(serialized.partIDs), getPartIDsAsString(m_partIDs).c_str());
|
||||||
<< m_laborCost << ','
|
serialized.invoiceDate = m_invoiceDate;
|
||||||
<< getPartIDsAsString(m_partIDs) << ','
|
serialized.laborCost = m_laborCost;
|
||||||
<< m_partsCost << ','
|
serialized.partsCost = m_partsCost;
|
||||||
<< m_discountPercentage << ','
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
<< m_totalAmount << ','
|
serialized.totalAmount = m_totalAmount;
|
||||||
<< m_paymentDate.toString() << ','
|
serialized.paymentDate = m_paymentDate;
|
||||||
<< util::getPaymentModeString(m_paymentMethod) << ','
|
serialized.paymentMethod = m_paymentMethod;
|
||||||
<< util::getPaymentStatusString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedInvoice.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into an Invoice object.
|
Description: Deserializes a SerializedInvoice record into an Invoice object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized invoice record
|
- serializedInvoice: const SerializedInvoice&, serialized invoice record
|
||||||
Returns:
|
Returns:
|
||||||
- Invoice*: Pointer to the deserialized Invoice object
|
- Invoice*: Pointer to the deserialized Invoice object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
Invoice* Invoice::deserialize(const std::string& record)
|
Invoice* Invoice::deserialize(const SerializedInvoice& serializedInvoice)
|
||||||
{
|
{
|
||||||
std::string id, bookingId;
|
util::Vector<std::string> partIDs = getPartIDsAsVector(serializedInvoice.partIDs);
|
||||||
std::string invoiceDateString, laborCostString, partIDsString;
|
|
||||||
std::string partsCostString, discountPercentageString, totalAmountString;
|
|
||||||
std::string paymentDateString, paymentMethodString, statusString;
|
|
||||||
double laborCost, partsCost, discountPercentage, totalAmount;
|
|
||||||
std::istringstream serializedInvoice(record);
|
|
||||||
getline(serializedInvoice, id, ',');
|
|
||||||
getline(serializedInvoice, bookingId, ',');
|
|
||||||
getline(serializedInvoice, invoiceDateString, ',');
|
|
||||||
getline(serializedInvoice, laborCostString, ',');
|
|
||||||
getline(serializedInvoice, partIDsString, ',');
|
|
||||||
getline(serializedInvoice, partsCostString, ',');
|
|
||||||
getline(serializedInvoice, discountPercentageString, ',');
|
|
||||||
getline(serializedInvoice, totalAmountString, ',');
|
|
||||||
getline(serializedInvoice, paymentDateString, ',');
|
|
||||||
getline(serializedInvoice, paymentMethodString, ',');
|
|
||||||
getline(serializedInvoice, statusString, ',');
|
|
||||||
util::Timestamp invoiceDate;
|
|
||||||
util::Timestamp paymentDate;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
invoiceDate = util::Timestamp::fromString(invoiceDateString);
|
|
||||||
paymentDate = util::Timestamp::fromString(paymentDateString);
|
|
||||||
laborCost = std::stod(laborCostString);
|
|
||||||
partsCost = std::stod(partsCostString);
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
totalAmount = std::stod(totalAmountString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid invoice data");
|
|
||||||
}
|
|
||||||
util::Vector<std::string> partIDs = getPartIDsAsVector(partIDsString);
|
|
||||||
util::PaymentMode paymentMethod = util::getPaymentMode(paymentMethodString);
|
|
||||||
util::PaymentStatus status = util::getPaymentStatus(statusString);
|
|
||||||
return Factory::getObject<Invoice>(
|
return Factory::getObject<Invoice>(
|
||||||
id,
|
serializedInvoice.id,
|
||||||
bookingId,
|
serializedInvoice.bookingId,
|
||||||
invoiceDate,
|
serializedInvoice.invoiceDate,
|
||||||
partIDs,
|
partIDs,
|
||||||
laborCost,
|
serializedInvoice.laborCost,
|
||||||
partsCost,
|
serializedInvoice.partsCost,
|
||||||
discountPercentage,
|
serializedInvoice.discountPercentage,
|
||||||
totalAmount,
|
serializedInvoice.totalAmount,
|
||||||
paymentDate,
|
serializedInvoice.paymentDate,
|
||||||
paymentMethod,
|
serializedInvoice.paymentMethod,
|
||||||
status
|
serializedInvoice.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for invoice serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,BookingID,InvoiceDate,LaborCost,PartIDs,PartsCost,DiscountPercentage,TotalAmount,PaymentDate,PaymentMethod,Status")
|
|
||||||
*/
|
|
||||||
std::string Invoice::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,BookingID,InvoiceDate,LaborCost,PartIDs,PartsCost,DiscountPercentage,TotalAmount,PaymentDate,PaymentMethod,Status";
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class InventoryItem;
|
class InventoryItem;
|
||||||
|
struct SerializedInvoice;
|
||||||
|
|
||||||
class Invoice
|
class Invoice
|
||||||
{
|
{
|
||||||
@@ -87,7 +88,6 @@ public:
|
|||||||
void setPaymentDate(const util::Timestamp& paymentDate);
|
void setPaymentDate(const util::Timestamp& paymentDate);
|
||||||
void setPaymentMethod(util::PaymentMode paymentMethod);
|
void setPaymentMethod(util::PaymentMode paymentMethod);
|
||||||
void setStatus(util::PaymentStatus status);
|
void setStatus(util::PaymentStatus status);
|
||||||
std::string serialize() const;
|
SerializedInvoice serialize() const;
|
||||||
static Invoice* deserialize(const std::string&);
|
static Invoice* deserialize(const SerializedInvoice&);
|
||||||
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"
|
||||||
@@ -351,79 +352,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();
|
|
||||||
};
|
};
|
||||||
@@ -7,6 +7,7 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Notification.h"
|
#include "Notification.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
@@ -219,69 +220,37 @@ void Notification::setCreatedAt(const util::Timestamp& createdAt)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the notification into a CSV-formatted string.
|
Description: Serializes the Notification object into a SerializedNotification record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized notification record
|
- SerializedNotification: Serialized representation of the notification
|
||||||
*/
|
*/
|
||||||
std::string Notification::serialize() const
|
SerializedNotification Notification::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedNotification;
|
SerializedNotification serialized = {};
|
||||||
serializedNotification << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_recipientUserId << ','
|
strcpy_s(serialized.recipientUserId, sizeof(serialized.recipientUserId), m_recipientUserId.c_str());
|
||||||
<< m_title << ','
|
strcpy_s(serialized.title, sizeof(serialized.title), m_title.c_str());
|
||||||
<< m_message << ','
|
strcpy_s(serialized.message, sizeof(serialized.message), m_message.c_str());
|
||||||
<< m_createdAt.toString();
|
serialized.createdAt = m_createdAt;
|
||||||
return serializedNotification.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a Notification object.
|
Description: Deserializes a SerializedNotification record into a Notification object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized notification record
|
- serializedNotification: const SerializedNotification&, serialized notification record
|
||||||
Returns:
|
Returns:
|
||||||
- Notification*: Pointer to the deserialized Notification object
|
- Notification*: Pointer to the deserialized Notification object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if timestamp parsing fails
|
|
||||||
*/
|
*/
|
||||||
Notification* Notification::deserialize(const std::string& record)
|
Notification* Notification::deserialize(const SerializedNotification& serializedNotification)
|
||||||
{
|
{
|
||||||
std::string id, recipientUserId, title, message, createdAtTimestampString;
|
|
||||||
std::istringstream serializedNotification(record);
|
|
||||||
getline(serializedNotification, id, ',');
|
|
||||||
getline(serializedNotification, recipientUserId, ',');
|
|
||||||
getline(serializedNotification, title, ',');
|
|
||||||
getline(serializedNotification, message, ',');
|
|
||||||
getline(serializedNotification, createdAtTimestampString, ',');
|
|
||||||
util::Timestamp createdAtTimestamp;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
createdAtTimestamp = util::Timestamp::fromString(createdAtTimestampString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid createdAt timestamp");
|
|
||||||
}
|
|
||||||
return Factory::getObject<Notification>(
|
return Factory::getObject<Notification>(
|
||||||
id,
|
serializedNotification.id,
|
||||||
recipientUserId,
|
serializedNotification.recipientUserId,
|
||||||
title,
|
serializedNotification.title,
|
||||||
message,
|
serializedNotification.message,
|
||||||
createdAtTimestamp
|
serializedNotification.createdAt);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for notification serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,RecipientID,Title,Message,Timestamp")
|
|
||||||
*/
|
|
||||||
std::string Notification::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,RecipientID,Title,Message,Timestamp";
|
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ Date: 19-May-2026
|
|||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
|
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedNotification;
|
||||||
|
|
||||||
class Notification
|
class Notification
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,6 @@ public:
|
|||||||
void setTitle(const std::string& title);
|
void setTitle(const std::string& title);
|
||||||
void setMessage(const std::string& message);
|
void setMessage(const std::string& message);
|
||||||
void setCreatedAt(const util::Timestamp& createdAt);
|
void setCreatedAt(const util::Timestamp& createdAt);
|
||||||
std::string serialize() const;
|
SerializedNotification serialize() const;
|
||||||
static Notification* deserialize(const std::string&);
|
static Notification* deserialize(const SerializedNotification&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -302,16 +302,3 @@ Service* Service::deserialize(const SerializedService& serializedService)
|
|||||||
serializedService.laborCost,
|
serializedService.laborCost,
|
||||||
serializedService.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";
|
|
||||||
}
|
|
||||||
@@ -43,5 +43,4 @@ public:
|
|||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
SerializedService serialize() const;
|
SerializedService serialize() const;
|
||||||
static Service* deserialize(const SerializedService&);
|
static Service* deserialize(const SerializedService&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
+27
-64
@@ -8,6 +8,7 @@ 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"
|
||||||
@@ -437,84 +438,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";
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ Date:19-May-2026
|
|||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedServiceBooking;
|
||||||
|
|
||||||
class ServiceBooking
|
class ServiceBooking
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,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();
|
|
||||||
};
|
};
|
||||||
@@ -365,16 +365,3 @@ User* User::deserialize(const SerializedUser& serializedUser)
|
|||||||
serializedUser.userType,
|
serializedUser.userType,
|
||||||
serializedUser.status);
|
serializedUser.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for user serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Username,Password,Name,Phone,Email,UserType,UserStatus")
|
|
||||||
*/
|
|
||||||
std::string User::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Username,Password,Name,Phone,Email,UserType,UserStatus";
|
|
||||||
}
|
|
||||||
@@ -54,5 +54,4 @@ public:
|
|||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
SerializedUser serialize() const;
|
SerializedUser serialize() const;
|
||||||
static User* deserialize(const SerializedUser& serializedUser);
|
static User* deserialize(const SerializedUser& serializedUser);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user