Added CSV header support and persistence for employees
<SRS> SRS02 : Employee Management </SRS> <Changes> - Added header handling in FileManager load by skipping first line during deserialization - Added support for writing headers using T::getHeaders() in FileManager save - Implemented getHeaders() for Employee and GeneralEmployee models - Added saveEmployees functionality in EmployeeManagementService - Added persistStates method in ZenvyController - Added deserialization failure check with exception handling - Minor formatting cleanup in FileIO </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -51,3 +51,8 @@ void ZenvyController::loadStates()
|
||||
{
|
||||
m_employeeManagementService->loadEmployees();
|
||||
}
|
||||
|
||||
void ZenvyController::persistStates()
|
||||
{
|
||||
m_employeeManagementService->saveEmployees();
|
||||
}
|
||||
|
||||
@@ -56,4 +56,5 @@ public:
|
||||
|
||||
//File Management
|
||||
void loadStates();
|
||||
void persistStates();
|
||||
};
|
||||
|
||||
@@ -263,3 +263,8 @@ std::shared_ptr<Employee> Employee::deserialize(const std::string& record)
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Employee::getHeaders()
|
||||
{
|
||||
return "EmployeeId,Email,Name,Phone,Password,TeamID,TeamStatus,AccountStatus,EmployeeType";
|
||||
}
|
||||
|
||||
@@ -90,5 +90,6 @@ public:
|
||||
Enums::EmployeeType getEmployeeType() const;
|
||||
virtual std::string serialize() const;
|
||||
static std::shared_ptr<Employee> deserialize(const std::string&);
|
||||
static std::string getHeaders();
|
||||
virtual ~Employee() = default;
|
||||
};
|
||||
@@ -58,4 +58,9 @@ std::shared_ptr<GeneralEmployee> GeneralEmployee::deserialize(const std::string&
|
||||
employeeDesignation,
|
||||
accountStatus
|
||||
);
|
||||
}
|
||||
|
||||
std::string GeneralEmployee::getHeaders()
|
||||
{
|
||||
return "EmployeeId,Email,Name,Phone,Password,TeamID,TeamStatus,AccountStatus,EmployeeType,EmployeeDesignation";
|
||||
}
|
||||
@@ -43,5 +43,6 @@ public:
|
||||
void setDesignation(Enums::EmployeeDesignation designation);
|
||||
std::string serialize() const override;
|
||||
static std::shared_ptr<GeneralEmployee> deserialize(const std::string&);
|
||||
static std::string getHeaders();
|
||||
~GeneralEmployee() = default;
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include "EmployeeManagementService.h"
|
||||
#include "Factory.h"
|
||||
@@ -221,3 +222,25 @@ void EmployeeManagementService::loadEmployees()
|
||||
employees.emplace(std::make_pair(admin->getId(), admin));
|
||||
}
|
||||
}
|
||||
|
||||
void EmployeeManagementService::saveEmployees()
|
||||
{
|
||||
FileManager<Employee> employeeFileManager(Config::File::EMPLOYEES_FILE);
|
||||
FileManager<GeneralEmployee> generalEmployeeFileManager(Config::File::GENERAL_EMPLOYEES_FILE);
|
||||
const auto& allEmployees = m_dataStore.getEmployees();
|
||||
employeeMap employees;
|
||||
std::map<std::string, std::shared_ptr<GeneralEmployee>> generalEmployees;
|
||||
for (auto& employeePair : allEmployees)
|
||||
{
|
||||
if (employeePair.second->getEmployeeType() == Enums::EmployeeType::GENERAL)
|
||||
{
|
||||
generalEmployees.emplace(employeePair.first, std::static_pointer_cast<GeneralEmployee>(employeePair.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
employees.emplace(employeePair);
|
||||
}
|
||||
}
|
||||
employeeFileManager.save(employees);
|
||||
generalEmployeeFileManager.save(generalEmployees);
|
||||
}
|
||||
|
||||
@@ -18,4 +18,5 @@ public:
|
||||
void updateProfile(const std::string&,const std::string&);
|
||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||
void loadEmployees();
|
||||
void saveEmployees();
|
||||
};
|
||||
|
||||
@@ -47,6 +47,15 @@ void UserInterface::run()
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
m_controller->persistStates();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool UserInterface::handleOperation(int choice)
|
||||
|
||||
Reference in New Issue
Block a user