Add documentation headers across system modules
This commit is contained in:
@@ -141,6 +141,16 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadSystemData
|
||||
Description: Loads all system data from persistent storage into memory.
|
||||
Invokes the respective management services to load users, inventory items, services,
|
||||
combo packages, service bookings, job cards, invoices, and observers.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void Controller::loadSystemData()
|
||||
{
|
||||
m_userManagementService.loadUsers();
|
||||
@@ -155,6 +165,16 @@ void Controller::loadSystemData()
|
||||
m_inventoryManagementService.loadObservers();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveSystemData
|
||||
Description: Saves all system data from memory back to persistent storage.
|
||||
Invokes the respective management services to save users, inventory items, services,
|
||||
combo packages, service bookings, job cards, invoices, and observers.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void Controller::saveSystemData()
|
||||
{
|
||||
m_userManagementService.saveUsers();
|
||||
|
||||
@@ -27,6 +27,19 @@ ComboPackage::ComboPackage(const std::string& packageName, double discountPercen
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: ComboPackage (parameterized constructor with ID)
|
||||
Description: Initializes a combo package with an existing ID, name, discount percentage,
|
||||
service IDs, and state. Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique ID of the package
|
||||
- packageName: const std::string&, name of the package
|
||||
- discountPercentage: double, discount percentage applied
|
||||
- serviceIDs: const util::Vector<std::string>&, IDs of services included
|
||||
- status: util::State, state of the package (ACTIVE/INACTIVE)
|
||||
Returns:
|
||||
- A new ComboPackage object
|
||||
*/
|
||||
ComboPackage::ComboPackage(const std::string& id, const std::string& packageName, double discountPercentage, const util::Vector<std::string>& serviceIDs, util::State status)
|
||||
: m_id(id),
|
||||
m_packageName(packageName),
|
||||
@@ -103,6 +116,14 @@ void ComboPackage::setState(util::State status)
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getServiceIDsAsString (static helper)
|
||||
Description: Converts a vector of service IDs into a single string separated by '|'.
|
||||
Parameters:
|
||||
- serviceIDs: const util::Vector<std::string>&, vector of service IDs
|
||||
Returns:
|
||||
- std::string: Concatenated service IDs string
|
||||
*/
|
||||
static std::string getServiceIDsAsString(const util::Vector<std::string>& serviceIDs)
|
||||
{
|
||||
int numberOfServices = serviceIDs.getSize();
|
||||
@@ -118,6 +139,14 @@ static std::string getServiceIDsAsString(const util::Vector<std::string>& servic
|
||||
return serviceIDsString;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getServiceIDsAsVector (static helper)
|
||||
Description: Converts a string of service IDs separated by '|' into a vector.
|
||||
Parameters:
|
||||
- serviceIDsString: const std::string&, concatenated service IDs string
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of service IDs
|
||||
*/
|
||||
static util::Vector<std::string> getServiceIDsAsVector(const std::string& serviceIDsString)
|
||||
{
|
||||
util::Vector<std::string> serviceIDs;
|
||||
@@ -130,6 +159,14 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
||||
return serviceIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the combo package into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized combo package record
|
||||
*/
|
||||
std::string ComboPackage::serialize() const
|
||||
{
|
||||
std::ostringstream serializedComboPackage;
|
||||
@@ -141,6 +178,16 @@ std::string ComboPackage::serialize() const
|
||||
return serializedComboPackage.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a ComboPackage object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized combo package record
|
||||
Returns:
|
||||
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
||||
Throws:
|
||||
- std::runtime_error if data is invalid
|
||||
*/
|
||||
ComboPackage* ComboPackage::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, packageName;
|
||||
@@ -171,6 +218,14 @@ ComboPackage* ComboPackage::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -19,6 +19,19 @@ InventoryItem::InventoryItem(const std::string& partName, int quantity, double p
|
||||
m_status(util::State::ACTIVE),
|
||||
m_price(price) {}
|
||||
|
||||
/*
|
||||
Function: InventoryItem (parameterized constructor with ID)
|
||||
Description: Initializes an inventory item with an existing ID, part name, quantity,
|
||||
price, and state. Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique ID of the item
|
||||
- partName: const std::string&, name of the part
|
||||
- quantity: int, quantity of the part
|
||||
- price: double, price of the part
|
||||
- status: util::State, state of the item (ACTIVE/INACTIVE)
|
||||
Returns:
|
||||
- A new InventoryItem object
|
||||
*/
|
||||
InventoryItem::InventoryItem(const std::string& id, const std::string& partName, int quantity, double price, util::State status)
|
||||
: m_id(id),
|
||||
m_partName(partName),
|
||||
@@ -83,6 +96,14 @@ void InventoryItem::setState(util::State status)
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the inventory item into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized inventory item record
|
||||
*/
|
||||
std::string InventoryItem::serialize() const
|
||||
{
|
||||
std::ostringstream serializedInventoryItem;
|
||||
@@ -94,6 +115,16 @@ std::string InventoryItem::serialize() const
|
||||
return serializedInventoryItem.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into an InventoryItem object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized inventory item record
|
||||
Returns:
|
||||
- InventoryItem*: Pointer to the deserialized InventoryItem object
|
||||
Throws:
|
||||
- std::runtime_error if data is invalid
|
||||
*/
|
||||
InventoryItem* InventoryItem::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, partName;
|
||||
@@ -125,6 +156,14 @@ InventoryItem* InventoryItem::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -109,6 +109,14 @@ double Invoice::getLaborCost() const
|
||||
return m_laborCost;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getPartIDs
|
||||
Description: Retrieves the IDs of parts used in the invoice.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- const util::Vector<std::string>&: Part IDs
|
||||
*/
|
||||
const util::Vector<std::string>& Invoice::getPartIDs() const
|
||||
{
|
||||
return m_partIDs;
|
||||
@@ -216,6 +224,14 @@ void Invoice::setStatus(util::PaymentStatus status)
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getPartIDsAsString (static helper)
|
||||
Description: Converts a vector of part IDs into a single string separated by '|'.
|
||||
Parameters:
|
||||
- partIDs: const util::Vector<std::string>&, vector of part IDs
|
||||
Returns:
|
||||
- std::string: Concatenated part IDs string
|
||||
*/
|
||||
static std::string getPartIDsAsString(const util::Vector<std::string>& partIDs)
|
||||
{
|
||||
int numberOfParts = partIDs.getSize();
|
||||
@@ -231,6 +247,14 @@ static std::string getPartIDsAsString(const util::Vector<std::string>& partIDs)
|
||||
return partIDsString;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getPartIDsAsVector (static helper)
|
||||
Description: Converts a string of part IDs separated by '|' into a vector.
|
||||
Parameters:
|
||||
- partIDsString: const std::string&, concatenated part IDs string
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of part IDs
|
||||
*/
|
||||
static util::Vector<std::string> getPartIDsAsVector(const std::string& partIDsString)
|
||||
{
|
||||
util::Vector<std::string> partIDs;
|
||||
@@ -243,6 +267,14 @@ static util::Vector<std::string> getPartIDsAsVector(const std::string& partIDsSt
|
||||
return partIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the invoice into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized invoice record
|
||||
*/
|
||||
std::string Invoice::serialize() const
|
||||
{
|
||||
std::ostringstream serializedInvoice;
|
||||
@@ -260,6 +292,16 @@ std::string Invoice::serialize() const
|
||||
return serializedInvoice.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into an Invoice object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized invoice record
|
||||
Returns:
|
||||
- Invoice*: Pointer to the deserialized Invoice object
|
||||
Throws:
|
||||
- std::runtime_error if data is invalid
|
||||
*/
|
||||
Invoice* Invoice::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, bookingId;
|
||||
@@ -312,6 +354,14 @@ Invoice* Invoice::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -35,6 +35,22 @@ JobCard::JobCard(const std::string& bookingId,
|
||||
m_status(status),
|
||||
m_completionDate(completionDate) {}
|
||||
|
||||
/*
|
||||
Function: JobCard (parameterized constructor with ID)
|
||||
Description: Initializes a job card with an existing ID, booking ID, service ID,
|
||||
technician ID, assignment date, completion date, and status.
|
||||
Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique job card ID
|
||||
- bookingId: const std::string&, ID of the booking
|
||||
- serviceId: const std::string&, ID of the service
|
||||
- technicianId: const std::string&, ID of the technician
|
||||
- assignedDate: const util::Timestamp&, date of assignment
|
||||
- status: util::ServiceJobStatus, job status
|
||||
- completionDate: const util::Timestamp&, date of completion
|
||||
Returns:
|
||||
- A new JobCard object
|
||||
*/
|
||||
JobCard::JobCard(const std::string& id,
|
||||
const std::string& bookingId,
|
||||
const std::string& serviceId,
|
||||
@@ -161,6 +177,14 @@ void JobCard::setCompletionDate(const util::Timestamp& completionDate)
|
||||
m_completionDate = completionDate;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the job card into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized job card record
|
||||
*/
|
||||
std::string JobCard::serialize() const
|
||||
{
|
||||
std::ostringstream serializedJobCard;
|
||||
@@ -174,6 +198,16 @@ std::string JobCard::serialize() const
|
||||
return serializedJobCard.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a JobCard object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized job card record
|
||||
Returns:
|
||||
- JobCard*: Pointer to the deserialized JobCard object
|
||||
Throws:
|
||||
- std::runtime_error if timestamp parsing fails
|
||||
*/
|
||||
JobCard* JobCard::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, bookingId, serviceId, technicianId;
|
||||
@@ -209,6 +243,14 @@ JobCard* JobCard::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -17,6 +17,19 @@ Notification::Notification(const std::string& recipientUserId, User* recipient,
|
||||
m_message(message),
|
||||
m_createdAt(createdAt) {}
|
||||
|
||||
/*
|
||||
Function: Notification (parameterized constructor with ID)
|
||||
Description: Initializes a notification with an existing ID, recipient details,
|
||||
title, message, and creation timestamp. Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique notification ID
|
||||
- recipientUserId: const std::string&, ID of the recipient user
|
||||
- title: const std::string&, notification title
|
||||
- message: const std::string&, notification message
|
||||
- createdAt: const util::Timestamp&, timestamp of creation
|
||||
Returns:
|
||||
- A new Notification object
|
||||
*/
|
||||
Notification::Notification(const std::string& id, const std::string& recipientUserId, const std::string& title, const std::string& message, const util::Timestamp& createdAt)
|
||||
: m_id(id),
|
||||
m_recipientUserId(recipientUserId),
|
||||
@@ -92,6 +105,14 @@ void Notification::setCreatedAt(const util::Timestamp& createdAt)
|
||||
m_createdAt = createdAt;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the notification into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized notification record
|
||||
*/
|
||||
std::string Notification::serialize() const
|
||||
{
|
||||
std::ostringstream serializedNotification;
|
||||
@@ -103,6 +124,16 @@ std::string Notification::serialize() const
|
||||
return serializedNotification.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a Notification object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized notification record
|
||||
Returns:
|
||||
- Notification*: Pointer to the deserialized Notification object
|
||||
Throws:
|
||||
- std::runtime_error if timestamp parsing fails
|
||||
*/
|
||||
Notification* Notification::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, recipientUserId, title, message, createdAtTimestampString;
|
||||
@@ -130,6 +161,14 @@ Notification* Notification::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -26,6 +26,19 @@ Service::Service(const std::string& name, const util::Map<std::string, Inventory
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: Service (parameterized constructor with ID)
|
||||
Description: Initializes a service with an existing ID, name, inventory item IDs,
|
||||
labor cost, and state. Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique service ID
|
||||
- name: const std::string&, name of the service
|
||||
- requiredInventoryItemIDs: const util::Vector<std::string>&, IDs of required inventory items
|
||||
- laborCost: double, labor cost of the service
|
||||
- status: util::State, state of the service (ACTIVE/INACTIVE)
|
||||
Returns:
|
||||
- A new Service object
|
||||
*/
|
||||
Service::Service(const std::string& id, const std::string& name, const util::Vector<std::string>& requiredInventoryItemIDs, double laborCost, util::State status)
|
||||
: m_id(id),
|
||||
m_name(name),
|
||||
@@ -50,6 +63,14 @@ const std::string& Service::getName() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getRequiredInventoryItemIDs
|
||||
Description: Retrieves the IDs of required inventory items for the service.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- const util::Vector<std::string>&: Inventory item IDs
|
||||
*/
|
||||
const util::Vector<std::string>& Service::getRequiredInventoryItemIDs() const
|
||||
{
|
||||
return m_requiredInventoryItemIDs;
|
||||
@@ -102,6 +123,14 @@ void Service::setState(util::State status)
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getInventoryItemIDsAsString (static helper)
|
||||
Description: Converts a vector of inventory item IDs into a single string separated by '|'.
|
||||
Parameters:
|
||||
- inventoryItemIds: const util::Vector<std::string>&, vector of inventory item IDs
|
||||
Returns:
|
||||
- std::string: Concatenated inventory item IDs string
|
||||
*/
|
||||
static std::string getInventoryItemIDsAsString(const util::Vector<std::string>& inventoryItemIds)
|
||||
{
|
||||
int numberOfInventoryItems = inventoryItemIds.getSize();
|
||||
@@ -117,6 +146,14 @@ static std::string getInventoryItemIDsAsString(const util::Vector<std::string>&
|
||||
return inventoryItemIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getInventoryItemIDsAsVector (static helper)
|
||||
Description: Converts a string of inventory item IDs separated by '|' into a vector.
|
||||
Parameters:
|
||||
- inventoryItemIDsString: const std::string&, concatenated inventory item IDs string
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of inventory item IDs
|
||||
*/
|
||||
static util::Vector<std::string> getInventoryItemIDsAsVector(const std::string& inventoryItemIDsString)
|
||||
{
|
||||
util::Vector<std::string> inventoryItemIDs;
|
||||
@@ -129,6 +166,14 @@ static util::Vector<std::string> getInventoryItemIDsAsVector(const std::string&
|
||||
return inventoryItemIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the service into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized service record
|
||||
*/
|
||||
std::string Service::serialize() const
|
||||
{
|
||||
std::ostringstream serializedService;
|
||||
@@ -140,6 +185,16 @@ std::string Service::serialize() const
|
||||
return serializedService.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a Service object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized service record
|
||||
Returns:
|
||||
- Service*: Pointer to the deserialized Service object
|
||||
Throws:
|
||||
- std::runtime_error if labor cost parsing fails
|
||||
*/
|
||||
Service* Service::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, name;
|
||||
@@ -170,6 +225,14 @@ Service* Service::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -47,6 +47,24 @@ ServiceBooking::ServiceBooking(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: ServiceBooking (parameterized constructor with ID)
|
||||
Description: Initializes a service booking with an existing ID, status, service IDs,
|
||||
customer details, vehicle details, technician ID, and discount percentage.
|
||||
Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique booking ID
|
||||
- status: util::ServiceJobStatus, job status of the booking
|
||||
- serviceIDs: const util::Vector<std::string>&, IDs of booked services
|
||||
- customerId: const std::string&, ID of the customer
|
||||
- vehicleNumber: const std::string&, vehicle number
|
||||
- vehicleBrand: const std::string&, vehicle brand
|
||||
- vehicleModel: const std::string&, vehicle model
|
||||
- assignedTechnicianId: const std::string&, ID of the assigned technician
|
||||
- discountPercentage: double, discount applied
|
||||
Returns:
|
||||
- A new ServiceBooking object
|
||||
*/
|
||||
ServiceBooking::ServiceBooking(
|
||||
const std::string& id,
|
||||
util::ServiceJobStatus status,
|
||||
@@ -87,6 +105,14 @@ util::ServiceJobStatus ServiceBooking::getStatus() const
|
||||
return m_status;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getServiceIDs
|
||||
Description: Retrieves the IDs of services booked.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- const util::Vector<std::string>&: Service IDs
|
||||
*/
|
||||
const util::Vector<std::string>& ServiceBooking::getServiceIDs() const
|
||||
{
|
||||
return m_serviceIDs;
|
||||
@@ -199,6 +225,14 @@ void ServiceBooking::setDiscountPercentage(double discountPercentage)
|
||||
m_discountPercentage = discountPercentage;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getServiceIDsAsString (static helper)
|
||||
Description: Converts a vector of service IDs into a single string separated by '|'.
|
||||
Parameters:
|
||||
- serviceIDs: const util::Vector<std::string>&, vector of service IDs
|
||||
Returns:
|
||||
- std::string: Concatenated service IDs string
|
||||
*/
|
||||
static std::string getServiceIDsAsString(const util::Vector<std::string>& serviceIDs)
|
||||
{
|
||||
int numberOfServices = serviceIDs.getSize();
|
||||
@@ -214,6 +248,14 @@ static std::string getServiceIDsAsString(const util::Vector<std::string>& servic
|
||||
return serviceIDsString;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getServiceIDsAsVector (static helper)
|
||||
Description: Converts a string of service IDs separated by '|' into a vector.
|
||||
Parameters:
|
||||
- serviceIDsString: const std::string&, concatenated service IDs string
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of service IDs
|
||||
*/
|
||||
static util::Vector<std::string> getServiceIDsAsVector(const std::string& serviceIDsString)
|
||||
{
|
||||
util::Vector<std::string> serviceIDs;
|
||||
@@ -226,6 +268,14 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
||||
return serviceIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the service booking into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized booking record
|
||||
*/
|
||||
std::string ServiceBooking::serialize() const
|
||||
{
|
||||
std::ostringstream serializedBooking;
|
||||
@@ -241,6 +291,16 @@ std::string ServiceBooking::serialize() const
|
||||
return serializedBooking.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a ServiceBooking object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized booking record
|
||||
Returns:
|
||||
- ServiceBooking*: Pointer to the deserialized ServiceBooking object
|
||||
Throws:
|
||||
- std::runtime_error if discount percentage parsing fails
|
||||
*/
|
||||
ServiceBooking* ServiceBooking::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, customerId, vehicleNumber, vehicleBrand, vehicleModel, assignedTechnicianId;
|
||||
@@ -279,6 +339,14 @@ ServiceBooking* ServiceBooking::deserialize(const std::string& record)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
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";
|
||||
|
||||
@@ -22,6 +22,22 @@ User::User(const std::string& userName, const std::string& password, const std::
|
||||
m_type(role),
|
||||
m_status(util::State::ACTIVE) {}
|
||||
|
||||
/*
|
||||
Function: User (parameterized constructor with ID)
|
||||
Description: Initializes a user with an existing ID, credentials, personal details,
|
||||
role, and state. Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- userId: const std::string&, unique user ID
|
||||
- userName: const std::string&, username
|
||||
- password: const std::string&, password
|
||||
- name: const std::string&, full name
|
||||
- phone: const std::string&, phone number
|
||||
- email: const std::string&, email address
|
||||
- role: util::UserType, role of the user
|
||||
- status: util::State, state of the user (ACTIVE/INACTIVE)
|
||||
Returns:
|
||||
- A new User object
|
||||
*/
|
||||
User::User(const std::string& userId, const std::string& userName, const std::string& password, const std::string& name, const std::string& phone, const std::string& email, util::UserType role, util::State status)
|
||||
: m_id(userId),
|
||||
m_userName(userName),
|
||||
@@ -142,6 +158,14 @@ void User::update(Notification* notification)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the user into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized user record
|
||||
*/
|
||||
std::string User::serialize() const
|
||||
{
|
||||
std::ostringstream serializedUser;
|
||||
@@ -156,6 +180,14 @@ std::string User::serialize() const
|
||||
return serializedUser.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a User object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized user record
|
||||
Returns:
|
||||
- User*: Pointer to the deserialized User object
|
||||
*/
|
||||
User* User::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, name, username, phone, password, email;
|
||||
@@ -181,8 +213,15 @@ User* User::deserialize(const std::string& record)
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
+55
@@ -1,9 +1,28 @@
|
||||
/*
|
||||
File: InventoryManagementService.cpp
|
||||
Description: Implements the InventoryManagementService class, which manages inventory
|
||||
items and observer relationships within the system. Provides methods
|
||||
for loading and saving inventory items from persistent storage, as well
|
||||
as attaching and persisting observers for notification handling.
|
||||
Author: Trenser
|
||||
Date: 22-May-2026
|
||||
*/
|
||||
|
||||
#include "InventoryManagementService.h"
|
||||
#include "FileManager.h"
|
||||
#include "InventoryItem.h"
|
||||
#include "Utility.h"
|
||||
#include "Config.h"
|
||||
|
||||
/*
|
||||
Function: getObserverIDs
|
||||
Description: Retrieves the IDs of all observers currently attached to the
|
||||
InventoryManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of observer user IDs
|
||||
*/
|
||||
util::Vector<std::string> InventoryManagementService::getObserverIDs()
|
||||
{
|
||||
util::Vector<std::string> observerIDs;
|
||||
@@ -19,6 +38,15 @@ util::Vector<std::string> InventoryManagementService::getObserverIDs()
|
||||
return observerIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadInventoryItems
|
||||
Description: Loads inventory items from persistent storage into the datastore.
|
||||
Uses FileManager to deserialize inventory items from the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void InventoryManagementService::loadInventoryItems()
|
||||
{
|
||||
util::FileManager<InventoryItem> inventoryItemFileManager(config::file::INVENTORYITEM_FILE);
|
||||
@@ -31,6 +59,15 @@ void InventoryManagementService::loadInventoryItems()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveInventoryItems
|
||||
Description: Saves inventory items from the datastore to persistent storage.
|
||||
Uses FileManager to serialize inventory items into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void InventoryManagementService::saveInventoryItems()
|
||||
{
|
||||
util::FileManager<InventoryItem> inventoryItemFileManager(config::file::INVENTORYITEM_FILE);
|
||||
@@ -38,11 +75,29 @@ void InventoryManagementService::saveInventoryItems()
|
||||
inventoryItemFileManager.save(inventoryItems);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadObservers
|
||||
Description: Loads observer IDs from persistent storage and attaches corresponding
|
||||
users as observers to the InventoryManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void InventoryManagementService::loadObservers()
|
||||
{
|
||||
util::loadObservers(config::file::INVENTORYMANAGEMENTOBSERVERS, this, m_dataStore);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveObservers
|
||||
Description: Saves the current observer IDs of the InventoryManagementService
|
||||
to persistent storage for future retrieval.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void InventoryManagementService::saveObservers()
|
||||
{
|
||||
util::saveObservers(config::file::INVENTORYMANAGEMENTOBSERVERS, this);
|
||||
|
||||
+52
@@ -5,6 +5,15 @@
|
||||
#include "Utility.h"
|
||||
#include "Config.h"
|
||||
|
||||
/*
|
||||
Function: getObserverIDs
|
||||
Description: Retrieves the IDs of all observers currently attached to the
|
||||
PaymentManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of observer user IDs
|
||||
*/
|
||||
util::Vector<std::string> PaymentManagementService::getObserverIDs()
|
||||
{
|
||||
util::Vector<std::string> observerIDs;
|
||||
@@ -20,6 +29,19 @@ util::Vector<std::string> PaymentManagementService::getObserverIDs()
|
||||
return observerIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadInvoices
|
||||
Description: Loads invoices from persistent storage into the datastore.
|
||||
Validates associated service bookings and inventory parts before
|
||||
attaching them to each invoice. Throws exceptions if invalid IDs
|
||||
are encountered.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if a booking ID or part ID is invalid
|
||||
*/
|
||||
void PaymentManagementService::loadInvoices()
|
||||
{
|
||||
util::FileManager<Invoice> invoiceFileManager(config::file::INVOICE_FILE);
|
||||
@@ -53,6 +75,16 @@ void PaymentManagementService::loadInvoices()
|
||||
invoices[invoice->getId()] = invoice;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveInvoices
|
||||
Description: Saves invoices from the datastore to persistent storage.
|
||||
Uses FileManager to serialize invoices into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void PaymentManagementService::saveInvoices()
|
||||
{
|
||||
util::FileManager<Invoice> invoiceFileManager(config::file::INVOICE_FILE);
|
||||
@@ -60,11 +92,31 @@ void PaymentManagementService::saveInvoices()
|
||||
invoiceFileManager.save(invoices);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadObservers
|
||||
Description: Loads observer IDs from persistent storage and attaches corresponding
|
||||
users as observers to the PaymentManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if an observer ID is invalid (not found in datastore)
|
||||
*/
|
||||
void PaymentManagementService::loadObservers()
|
||||
{
|
||||
util::loadObservers(config::file::PAYMENTMANAGEMENTOBSERVERS, this, m_dataStore);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveObservers
|
||||
Description: Saves the current observer IDs of the PaymentManagementService
|
||||
to persistent storage for future retrieval.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void PaymentManagementService::saveObservers()
|
||||
{
|
||||
util::saveObservers(config::file::PAYMENTMANAGEMENTOBSERVERS, this);
|
||||
|
||||
+115
@@ -8,6 +8,15 @@
|
||||
#include "Config.h"
|
||||
#include "Utility.h"
|
||||
|
||||
/*
|
||||
Function: getObserverIDs
|
||||
Description: Retrieves the IDs of all observers currently attached to the
|
||||
ServiceManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector of observer user IDs
|
||||
*/
|
||||
util::Vector<std::string> ServiceManagementService::getObserverIDs()
|
||||
{
|
||||
util::Vector<std::string> observerIDs;
|
||||
@@ -23,6 +32,17 @@ util::Vector<std::string> ServiceManagementService::getObserverIDs()
|
||||
return observerIDs;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadServices
|
||||
Description: Loads services from persistent storage into the datastore.
|
||||
Validates required inventory items and attaches them to each service.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if an inventory item ID is invalid
|
||||
*/
|
||||
void ServiceManagementService::loadServices()
|
||||
{
|
||||
util::FileManager<Service> serviceFileManager(config::file::SERVICE_FILE);
|
||||
@@ -49,6 +69,15 @@ void ServiceManagementService::loadServices()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveServices
|
||||
Description: Saves services from the datastore to persistent storage.
|
||||
Uses FileManager to serialize services into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void ServiceManagementService::saveServices()
|
||||
{
|
||||
util::FileManager<Service> serviceFileManager(config::file::SERVICE_FILE);
|
||||
@@ -56,6 +85,17 @@ void ServiceManagementService::saveServices()
|
||||
serviceFileManager.save(services);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadComboPackages
|
||||
Description: Loads combo packages from persistent storage into the datastore.
|
||||
Validates associated services and attaches them to each package.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if a service ID is invalid
|
||||
*/
|
||||
void ServiceManagementService::loadComboPackages()
|
||||
{
|
||||
util::FileManager<ComboPackage> comboPackageFileManager(config::file::COMBOPACKAGE_FILE);
|
||||
@@ -82,6 +122,15 @@ void ServiceManagementService::loadComboPackages()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveComboPackages
|
||||
Description: Saves combo packages from the datastore to persistent storage.
|
||||
Uses FileManager to serialize combo packages into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void ServiceManagementService::saveComboPackages()
|
||||
{
|
||||
util::FileManager<ComboPackage> comboPackageFileManager(config::file::COMBOPACKAGE_FILE);
|
||||
@@ -89,6 +138,19 @@ void ServiceManagementService::saveComboPackages()
|
||||
comboPackageFileManager.save(comboPackages);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadServiceBookings
|
||||
Description: Loads service bookings from persistent storage into the datastore.
|
||||
Validates associated services, customers, and technicians before
|
||||
attaching them to each booking.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if a service ID, customer ID, or technician ID is invalid
|
||||
- std::runtime_error if a user is not of the expected type (customer/technician)
|
||||
*/
|
||||
void ServiceManagementService::loadServiceBookings()
|
||||
{
|
||||
util::FileManager<ServiceBooking> bookingFileManager(config::file::SERVICEBOOKING_FILE);
|
||||
@@ -143,6 +205,15 @@ void ServiceManagementService::loadServiceBookings()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveServiceBookings
|
||||
Description: Saves service bookings from the datastore to persistent storage.
|
||||
Uses FileManager to serialize bookings into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void ServiceManagementService::saveServiceBookings()
|
||||
{
|
||||
util::FileManager<ServiceBooking> bookingFileManager(config::file::SERVICEBOOKING_FILE);
|
||||
@@ -150,6 +221,20 @@ void ServiceManagementService::saveServiceBookings()
|
||||
bookingFileManager.save(serviceBookings);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadJobCards
|
||||
Description: Loads job cards from persistent storage into the datastore.
|
||||
Validates associated bookings, services, and technicians before
|
||||
attaching them to each job card.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if a booking ID, service ID, or technician ID is invalid
|
||||
- std::runtime_error if a service does not belong to the booking
|
||||
- std::runtime_error if a user is not a technician
|
||||
*/
|
||||
void ServiceManagementService::loadJobCards()
|
||||
{
|
||||
util::FileManager<JobCard> jobCardFileManager(config::file::JOBCARD_FILE);
|
||||
@@ -193,6 +278,16 @@ void ServiceManagementService::loadJobCards()
|
||||
jobCards[jobCard->getId()] = jobCard;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveJobCards
|
||||
Description: Saves job cards from the datastore to persistent storage.
|
||||
Uses FileManager to serialize job cards into the configured file.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void ServiceManagementService::saveJobCards()
|
||||
{
|
||||
util::FileManager<JobCard> jobCardFileManager(config::file::JOBCARD_FILE);
|
||||
@@ -200,11 +295,31 @@ void ServiceManagementService::saveJobCards()
|
||||
jobCardFileManager.save(jobCards);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: loadObservers
|
||||
Description: Loads observer IDs from persistent storage and attaches corresponding
|
||||
users as observers to the ServiceManagementService.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if an observer ID is invalid (not found in datastore)
|
||||
*/
|
||||
void ServiceManagementService::loadObservers()
|
||||
{
|
||||
util::loadObservers(config::file::SERVICEMANAGEMENTOBSERVERS, this, m_dataStore);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveObservers
|
||||
Description: Saves the current observer IDs of the ServiceManagementService
|
||||
to persistent storage for future retrieval.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void ServiceManagementService::saveObservers()
|
||||
{
|
||||
util::saveObservers(config::file::SERVICEMANAGEMENTOBSERVERS, this);
|
||||
|
||||
+21
@@ -4,6 +4,18 @@
|
||||
#include "Notification.h"
|
||||
#include "Config.h"
|
||||
|
||||
/*
|
||||
Function: loadUsers
|
||||
Description: Loads users and notifications from persistent storage into the datastore.
|
||||
Validates that each notification’s recipient exists and attaches the
|
||||
notification to the corresponding user.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if a notification recipient user ID is invalid
|
||||
*/
|
||||
void UserManagementService::loadUsers()
|
||||
{
|
||||
util::FileManager<User> userFileManager(config::file::USER_FILE);
|
||||
@@ -31,6 +43,15 @@ void UserManagementService::loadUsers()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveUsers
|
||||
Description: Saves users and their notifications from the datastore to persistent storage.
|
||||
Collects notifications from all users into a single map before saving.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void UserManagementService::saveUsers()
|
||||
{
|
||||
util::FileManager<User> userFileManager(config::file::USER_FILE);
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
File: FileHelper.h
|
||||
Description: Provides utility functions for loading and saving records
|
||||
from and to CSV-like text files. Ensures files are created
|
||||
if missing and supports simple record persistence.
|
||||
Author: Trenser
|
||||
Date: 22-May-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -6,6 +15,17 @@
|
||||
|
||||
namespace util
|
||||
{
|
||||
/*
|
||||
Function: loadRecords
|
||||
Description: Loads records from a given file path into a vector of strings.
|
||||
Skips the header line if present. Creates the file if it does not exist.
|
||||
Parameters:
|
||||
- filePath: const std::string&, path to the file
|
||||
Returns:
|
||||
- util::Vector<std::string>: Vector containing all records (excluding header)
|
||||
Throws:
|
||||
- None (creates file if missing)
|
||||
*/
|
||||
inline util::Vector<std::string> loadRecords(const std::string& filePath)
|
||||
{
|
||||
util::Vector<std::string> records;
|
||||
@@ -30,6 +50,18 @@ namespace util
|
||||
return records;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveRecords
|
||||
Description: Saves records to a given file path. Overwrites existing content
|
||||
and writes a header line followed by all records.
|
||||
Parameters:
|
||||
- filePath: const std::string&, path to the file
|
||||
- records: const util::Vector<std::string>&, vector of records to save
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if the file cannot be opened for writing
|
||||
*/
|
||||
inline void saveRecords(const std::string& filePath, const util::Vector<std::string>& records)
|
||||
{
|
||||
std::ofstream file(filePath, std::ios::trunc);
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
/*
|
||||
File: FileManager.h
|
||||
Description: Declares and implements a generic FileManager template class for
|
||||
loading and saving objects to and from files. Uses serialization
|
||||
and deserialization methods defined in the object type T.
|
||||
Provides persistence support for system entities such as Users,
|
||||
Services, InventoryItems, etc.
|
||||
Author: Trenser
|
||||
Date: 22-May-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
@@ -20,6 +31,18 @@ namespace util
|
||||
void save(const objects<T>&);
|
||||
};
|
||||
|
||||
/*
|
||||
Function: load
|
||||
Description: Loads records from the file into a map of objects.
|
||||
Skips the header line, deserializes each record into an object of type T,
|
||||
and stores them in a map keyed by object ID.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- util::Map<std::string, T*> containing deserialized objects
|
||||
Throws:
|
||||
- std::runtime_error if deserialization fails for any record
|
||||
*/
|
||||
template <typename T>
|
||||
objects<T> FileManager<T>::load()
|
||||
{
|
||||
@@ -57,6 +80,17 @@ namespace util
|
||||
return records;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: save
|
||||
Description: Saves records to the file. Serializes each object of type T into a string,
|
||||
writes a header line, and then writes all serialized records to the file.
|
||||
Parameters:
|
||||
- records: const util::Map<std::string, T*>&, map of objects to save
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if the file cannot be opened for writing
|
||||
*/
|
||||
template <typename T>
|
||||
void FileManager<T>::save(const objects<T>& records)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
/*
|
||||
File: StringHelper.h
|
||||
Description: Provides utility functions for extracting numeric values from strings.
|
||||
Useful for parsing IDs, codes, or mixed alphanumeric inputs where
|
||||
digits need to be isolated and converted into integers.
|
||||
Author: Trenser
|
||||
Date: 22-May-2026
|
||||
*/
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
namespace util
|
||||
{
|
||||
/*
|
||||
Function: extractNumber
|
||||
Description: Extracts all digits from the given string and converts them into an integer.
|
||||
Ignores non-digit characters. For example, "abc123xyz" returns 123.
|
||||
Parameters:
|
||||
- input: const std::string&, the input string containing digits and/or other characters
|
||||
Returns:
|
||||
- int: The integer value formed by concatenating all digits in the string
|
||||
*/
|
||||
inline int extractNumber(const std::string& input)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/*
|
||||
File: ObserversHelper.h
|
||||
Description: Provides utility functions for loading and saving observers
|
||||
in the notification management system. Ensures that observer
|
||||
IDs are validated against existing users in the datastore
|
||||
before attaching them to the notification service.
|
||||
Author: Trenser
|
||||
Date: 22-May-2026
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "NotificationManagementService.h"
|
||||
#include "FileHelper.h"
|
||||
@@ -5,6 +15,20 @@
|
||||
|
||||
namespace util
|
||||
{
|
||||
/*
|
||||
Function: loadObservers
|
||||
Description: Loads observer IDs from a file and attaches the corresponding users
|
||||
to the notification management service. Validates that each observer ID
|
||||
exists in the datastore before attaching.
|
||||
Parameters:
|
||||
- filePath: const std::string&, path to the file containing observer IDs
|
||||
- service: NotificationManagementService*, pointer to the notification service
|
||||
- dataStore: DataStore&, reference to the datastore containing users
|
||||
Returns:
|
||||
- void
|
||||
Throws:
|
||||
- std::runtime_error if an observer ID is invalid (not found in datastore)
|
||||
*/
|
||||
inline void loadObservers(const std::string& filePath, NotificationManagementService* service, DataStore& dataStore)
|
||||
{
|
||||
auto observerIDs = util::loadRecords(filePath);
|
||||
@@ -21,6 +45,16 @@ namespace util
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: saveObservers
|
||||
Description: Saves the current observer IDs from the notification management service
|
||||
to a file for persistence.
|
||||
Parameters:
|
||||
- filePath: const std::string&, path to the file where observer IDs will be saved
|
||||
- service: NotificationManagementService*, pointer to the notification service
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
inline void saveObservers(const std::string& filePath, NotificationManagementService* service)
|
||||
{
|
||||
auto observerIDs = service->getObserverIDs();
|
||||
|
||||
Reference in New Issue
Block a user