Added FileManager DLL and cleanup code
<SRS> SRS02 : Employee Management </SRS> <Changes> - Created FileIO for reading and writing files - Created FileManager to use FileIO - Set up Trenser.FileManager as a DLL - Linked DLL with Trenser.Zenvy project - Fixed duplicate function issue by marking deactivateEmployee as inline - Cleaned up unused methods in controller and service </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include "pch.h"
|
||||
#include "FileIO.h"
|
||||
|
||||
std::vector<std::string> FileIO::readAllLines(const std::string& path)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file.is_open())
|
||||
throw std::runtime_error("Failed to open file " + path);
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line))
|
||||
lines.push_back(line);
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
void FileIO::writeAllLines(const std::string& path,
|
||||
const std::vector<std::string>& lines)
|
||||
{
|
||||
std::ofstream file(path, std::ios::trunc);
|
||||
if (!file.is_open())
|
||||
throw std::runtime_error("Failed to open file " + path);
|
||||
|
||||
for (const auto& line : lines)
|
||||
file << line << '\n';
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include<memory>
|
||||
#include<vector>
|
||||
#include<fstream>
|
||||
#include<string>
|
||||
#include<stdexcept>
|
||||
|
||||
#ifdef TRENSERFILEMANAGER_EXPORTS
|
||||
#define TRENSERFILEMANAGER_API __declspec(dllexport)
|
||||
#else
|
||||
#define TRENSERFILEMANAGER_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
class TRENSERFILEMANAGER_API FileIO {
|
||||
public:
|
||||
static std::vector<std::string> readAllLines(const std::string& path);
|
||||
static void writeAllLines(const std::string& path, const std::vector<std::string>& lines);
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "FileIO.h"
|
||||
|
||||
template <typename T> using objects = std::map<int, std::shared_ptr<T>>;
|
||||
|
||||
template <typename T>
|
||||
class FileManager
|
||||
{
|
||||
private:
|
||||
std::string m_filePath;
|
||||
public:
|
||||
FileManager() : m_filePath("") {}
|
||||
FileManager(const std::string& filePath) : m_filePath(filePath) {}
|
||||
objects<T> load();
|
||||
void save(const objects<T>&);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
objects<T> FileManager<T>::load()
|
||||
{
|
||||
objects<T> records;
|
||||
auto lines = FileIO::readAllLines(m_filePath);
|
||||
for (const auto& record : lines)
|
||||
{
|
||||
auto object = T::deserialize(record);
|
||||
records[object->getId()] = object;
|
||||
}
|
||||
return records;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void FileManager<T>::save(const objects<T>& records)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
|
||||
for (const auto& recordPair : records)
|
||||
{
|
||||
lines.push_back(recordPair.second->serialize());
|
||||
}
|
||||
FileIO::writeAllLines(m_filePath, lines);
|
||||
}
|
||||
@@ -135,11 +135,14 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="FileIO.h" />
|
||||
<ClInclude Include="FileManager.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
<ClCompile Include="FileIO.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FileManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FileIO.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
@@ -29,5 +35,8 @@
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FileIO.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -9,5 +9,10 @@
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
#include "framework.h"
|
||||
#include<memory>
|
||||
#include<vector>
|
||||
#include<fstream>
|
||||
#include<string>
|
||||
#include<stdexcept>
|
||||
|
||||
#endif //PCH_H
|
||||
|
||||
@@ -102,12 +102,17 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)factories;$(ProjectDir)datastores;$(ProjectDir)views;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)factories;$(ProjectDir)datastores;$(ProjectDir)views;%(AdditionalIncludeDirectories);..\..\Trenser.FileManager\Trenser.FileManager</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\Trenser.FileManager\$(IntDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>Trenser.FileManager.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /y /d "..\..\Trenser.FileManager\$(IntDir)Trenser.FileManager.dll" "$(OutDir)"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
@@ -117,11 +122,17 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>;..\..\Trenser.FileManager\Trenser.FileManager</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\Trenser.FileManager\$(IntDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>Trenser.FileManager.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /y /d "..\..\Trenser.FileManager\$(IntDir)Trenser.FileManager.dll" "$(OutDir)"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="controllers\ZenvyController.cpp" />
|
||||
|
||||
@@ -195,6 +195,9 @@
|
||||
<ClCompile Include="views\MenuHelper.cpp">
|
||||
<Filter>Views</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="utilities\AuthorizationHelper.cpp">
|
||||
<Filter>Services</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="services\AuthenticationManagementService.h">
|
||||
@@ -344,6 +347,9 @@
|
||||
<ClInclude Include="views\MenuHelper.h">
|
||||
<Filter>Views</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="utilities\AuthorizationHelper.h">
|
||||
<Filter>Services</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="models\Employee.h">
|
||||
|
||||
@@ -42,10 +42,6 @@ std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
|
||||
return m_employeeManagementService->getCurrentEmployee();
|
||||
}
|
||||
|
||||
std::shared_ptr<const Employee> ZenvyController::getEmployee(const std::string& id)
|
||||
{
|
||||
}
|
||||
|
||||
Employees ZenvyController::getEmployees()
|
||||
{
|
||||
return m_employeeManagementService->getEmployees();
|
||||
|
||||
@@ -48,7 +48,6 @@ public:
|
||||
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
||||
bool deactivateEmployee(const std::string&);
|
||||
Employees getEmployees();
|
||||
std::shared_ptr<const Employee> getEmployee(const std::string&);
|
||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||
void updateProfile(const std::string&,const std::string&);
|
||||
|
||||
|
||||
@@ -116,11 +116,20 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
||||
|
||||
Employees EmployeeManagementService::getEmployees()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<const Employee> EmployeeManagementService::getEmployee(const std::string& id)
|
||||
{
|
||||
Employees result;
|
||||
auto& employees = m_dataStore.getEmployees();
|
||||
if (employees.size() <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (const auto& iterator : employees)
|
||||
{
|
||||
if (iterator.second->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE)
|
||||
{
|
||||
result.push_back(iterator.second);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
||||
bool deactivateEmployee(const std::string&);
|
||||
Employees getEmployees();
|
||||
std::shared_ptr<const Employee> getEmployee(const std::string&);
|
||||
void updateProfile(const std::string&,const std::string&);
|
||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ inline std::map<int, std::shared_ptr<const Employee>> listEmployees(const std::s
|
||||
return employeeList;
|
||||
}
|
||||
|
||||
void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
||||
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
||||
{
|
||||
auto employeeList = listEmployees(controller);
|
||||
if (employeeList.empty())
|
||||
|
||||
Reference in New Issue
Block a user