ba5f96c22d
- Add serialize/deserialize support for core models - Add file-based load/save functions in management services - Introduce FileManager, Config, Utility and helper utilities - Persist observer IDs for notification services - Resolve object relationships during load (services, bookings, invoices, job cards) - Add controller-level loadSystemData/saveSystemData - Load data at app startup and save on shutdown
30 lines
960 B
C++
30 lines
960 B
C++
#pragma once
|
|
#include "NotificationManagementService.h"
|
|
#include "FileHelper.h"
|
|
#include "DataStore.h"
|
|
|
|
namespace util
|
|
{
|
|
inline void loadObservers(const std::string& filePath, NotificationManagementService* service, DataStore& dataStore)
|
|
{
|
|
auto observerIDs = util::loadRecords(filePath);
|
|
auto& users = dataStore.getUsers();
|
|
for (int index = 0; index < observerIDs.getSize(); index++)
|
|
{
|
|
const std::string& observerID = observerIDs[index];
|
|
int userIndex = users.find(observerID);
|
|
if (userIndex == -1)
|
|
{
|
|
throw std::runtime_error("Invalid Observer ID");
|
|
}
|
|
service->attach(users.getValueAt(userIndex));
|
|
}
|
|
}
|
|
|
|
inline void saveObservers(const std::string& filePath, NotificationManagementService* service)
|
|
{
|
|
auto observerIDs = service->getObserverIDs();
|
|
util::saveRecords(filePath, observerIDs);
|
|
}
|
|
}
|