Add logging service and datastore setup, refactor inputHelper
<SRS> SRS01 : Authentication </SRS> <Changes> - Set up DataStore singleton and added basic employee + log storage - Added LogService - Refactor InputHelper - Updated include paths in project config </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -102,7 +102,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)controllers;$(ProjectDir)services;$(ProjectDir)utilities;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)factories;$(ProjectDir)datastores;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
@@ -1 +1,17 @@
|
||||
#include "DataStore.h"
|
||||
|
||||
DataStore& DataStore::getInstance()
|
||||
{
|
||||
static DataStore dataStore;
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
logMap& DataStore::getLogs()
|
||||
{
|
||||
return m_logs;
|
||||
}
|
||||
|
||||
employeeMap& DataStore::getEmployees()
|
||||
{
|
||||
return m_employees;
|
||||
}
|
||||
@@ -1,5 +1,39 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include "Employee.h"
|
||||
#include "Log.h"
|
||||
#include "Timestamp.h"
|
||||
#include "Admin.h"
|
||||
#include "HRManager.h"
|
||||
#include "GeneralEmployee.h"
|
||||
#include "ITExecutive.h"
|
||||
#include "FinanceExecutive.h"
|
||||
#include "TeamExecutive.h"
|
||||
#include "TalentExecutive.h"
|
||||
#include "Team.h"
|
||||
#include "Room.h"
|
||||
#include "Ticket.h"
|
||||
#include "JobListing.h"
|
||||
#include "Notification.h"
|
||||
#include "Announcement.h"
|
||||
|
||||
using employeeMap = std::map<std::string, std::shared_ptr<Employee>>;
|
||||
using logMap = std::map<util::Timestamp, std::shared_ptr<Log>>;
|
||||
|
||||
class DataStore
|
||||
{
|
||||
};
|
||||
|
||||
private:
|
||||
std::shared_ptr<Employee> m_authenticatedEmployee;
|
||||
employeeMap m_employees;
|
||||
logMap m_logs;
|
||||
DataStore() = default;
|
||||
public:
|
||||
static DataStore& getInstance();
|
||||
DataStore(const DataStore&) = delete;
|
||||
DataStore& operator=(const DataStore&) = delete;
|
||||
DataStore(DataStore&&) = delete;
|
||||
DataStore& operator=(DataStore&&) = delete;
|
||||
employeeMap& getEmployees();
|
||||
logMap& getLogs();
|
||||
};
|
||||
@@ -9,8 +9,8 @@ private:
|
||||
std::string m_message;
|
||||
public:
|
||||
Log() : m_timestamp(), m_message("") {}
|
||||
Log(const util::Timestamp& timestamp, const std::string& message)
|
||||
: m_timestamp(timestamp), m_message(message) {}
|
||||
Log(const std::string& message)
|
||||
: m_timestamp(), m_message(message) {}
|
||||
const util::Timestamp& getTimestamp() const;
|
||||
const std::string& getMessage() const;
|
||||
void setTimestamp(const util::Timestamp& timestamp);
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
#include "LogService.h"
|
||||
#include "Log.h"
|
||||
#include "Factory.h"
|
||||
#include "DataStore.h"
|
||||
|
||||
void LogService::log(const std::string& message)
|
||||
{
|
||||
DataStore& dataStore = DataStore::getInstance();
|
||||
logMap& logs = dataStore.getLogs();
|
||||
std::shared_ptr<Log> log = Factory::getObject<Log>(message);
|
||||
logs.emplace(std::make_pair(log->getTimestamp(), log));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#include "Log.h"
|
||||
|
||||
class LogService
|
||||
{
|
||||
public:
|
||||
static void log(const std::string&);
|
||||
};
|
||||
|
||||
@@ -1,11 +1 @@
|
||||
#include "inputHelper.h"
|
||||
|
||||
void util::readString(std::string& value)
|
||||
{
|
||||
getline(std::cin >> std::ws, value);
|
||||
}
|
||||
|
||||
void util::pressEnter()
|
||||
{
|
||||
system("pause");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
@@ -6,18 +7,24 @@
|
||||
|
||||
namespace util
|
||||
{
|
||||
template <typename T>
|
||||
void readValue(T& value)
|
||||
{
|
||||
std::cin >> value;
|
||||
if (std::cin.fail())
|
||||
{
|
||||
std::cin.clear();
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
throw std::runtime_error("Invalid Console Input");
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
inline void read(T& value)
|
||||
{
|
||||
if (!(std::cin >> value))
|
||||
{
|
||||
std::cin.clear();
|
||||
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
throw std::runtime_error("Invalid console input");
|
||||
}
|
||||
}
|
||||
|
||||
void readString(std::string&);
|
||||
void pressEnter();
|
||||
inline void read(std::string& value)
|
||||
{
|
||||
std::getline(std::cin >> std::ws, value);
|
||||
}
|
||||
|
||||
inline void pressEnter()
|
||||
{
|
||||
system("pause");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user