Change shared pointer to raw pointer in views

This commit is contained in:
Tinu Johnson
2026-04-16 18:02:07 +05:30
parent 9e05bac97c
commit 6a373b48df
20 changed files with 42 additions and 52 deletions
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "AdminMenu.h"
#include"InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include<iomanip>
#include "EmployeeMenu.h"
@@ -4,14 +4,13 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
class EmployeeMenu
{
private:
ZenvyController m_zenvyController;
ZenvyController* m_zenvyController;
public:
EmployeeMenu() : m_zenvyController(new ZenvyController()) {};
void run();
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "FinanceExecutiveMenu.h"
#include "InputHelper.h"
@@ -67,6 +66,15 @@ void FinanceExecutiveMenu::updatePayroll()
}
}
void FinanceExecutiveMenu::generatePayslips()
{
util::Timestamp currentTimestamp;
util::clear();
m_zenvyController->generatePayslips();
std::cout << "Generated payslips for the month of " << currentTimestamp.getMonth() << "-" << currentTimestamp.getYear() << " successfully.";
util::pressEnter();
}
/*
* Function: FinanceExecutiveMenu::handleOperation
* Description: Handles the finance executives menu choice and executes the corresponding action
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include<memory>
#include<iostream>
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "HRManagerMenu.h"
#include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "ITExecutiveMenu.h"
#include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -70,9 +70,9 @@ static Enums::EmployeeDesignation getEmployeeDesignation()
}
}
void createEmployee(std::shared_ptr<ZenvyController> controller)
void createEmployee(ZenvyController* m_zenvyController)
{
auto currentEmployee = controller->getCurrentEmployee();
auto currentEmployee = m_zenvyController->getCurrentEmployee();
Enums::EmployeeType employeeType = getEmployeeType(currentEmployee->getEmployeeType());
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
std::string name, email, phone;
@@ -98,12 +98,12 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
util::read(email);
std::cout << "Enter Phone: ";
util::read(phone);
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
}
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController)
void updateDesignation(ZenvyController* m_zenvyController)
{
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees(Enums::EmployeeType::GENERAL));
if (selectedEmployeeId.empty())
@@ -123,7 +123,7 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
}
}
void displayCandidateDetails(const std::vector<std::shared_ptr<Candidate>>& shorlistedCandidates)
void displayCandidateDetails(const std::vector<Candidate*> shorlistedCandidates)
{
util::clear();
std::cout << std::left
@@ -148,12 +148,12 @@ void displayCandidateDetails(const std::vector<std::shared_ptr<Candidate>>& shor
}
}
void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& controller)
void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController)
{
int index;
std::string name, email, phone;
util::clear();
std::vector<std::shared_ptr<Candidate>> shortlistedCandidates = controller->getShorlistedCandidates();
std::vector<Candidate*> shortlistedCandidates = m_zenvyController->getShorlistedCandidates();
if (shortlistedCandidates.empty())
{
std::cout << "No candidates Found!";
@@ -163,13 +163,13 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& c
displayCandidateDetails(shortlistedCandidates);
std::cout << "Enter the Index: ";
util::read(index);
auto currentEmployee = controller->getCurrentEmployee();
auto currentEmployee = m_zenvyController->getCurrentEmployee();
Enums::EmployeeType employeeType;
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
if (index > 0 && index <= shortlistedCandidates.size())
{
employeeType = getEmployeeType(currentEmployee->getEmployeeType());
std::shared_ptr<Candidate> candidate = shortlistedCandidates[index - 1];
Candidate* candidate = shortlistedCandidates[index - 1];
switch (employeeType)
{
case Enums::EmployeeType::INVALID:
@@ -190,7 +190,7 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& c
util::read(email);
name = candidate->getCandidateName();
phone = candidate->getCandidatePhone();
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
candidate->setCandidateStatus(Enums::CandidateStatus::HIRED);
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
+22 -23
View File
@@ -15,12 +15,14 @@
#include "MenuHelper.h"
#include "Validator.h"
void createEmployee(std::shared_ptr<ZenvyController> controller);
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController);
void createEmployee(ZenvyController* m_zenvyController);
void updateDesignation(ZenvyController* m_zenvyController);
void displayCandidateDetails(const std::vector<const Candidate*> shorlistedCandidates);
void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController);
inline void viewPayslipHistory(std::shared_ptr<ZenvyController> controller)
inline void viewPayslipHistory(ZenvyController* m_zenvyController)
{
auto employeePayslips = controller->getCurrentEmployee()->getEmployeePayslips();
auto employeePayslips = m_zenvyController->getCurrentEmployee()->getEmployeePayslips();
util::clear();
if (employeePayslips.empty())
{
@@ -51,10 +53,10 @@ inline void viewPayslipHistory(std::shared_ptr<ZenvyController> controller)
util::pressEnter();
}
inline void viewProfile(std::shared_ptr<ZenvyController> controller)
inline void viewProfile(ZenvyController* m_zenvyController)
{
util::clear();
std::shared_ptr<const Employee> currentEmployee = controller->getCurrentEmployee();
const Employee* currentEmployee = m_zenvyController->getCurrentEmployee();
if (currentEmployee)
{
std::cout << std::left
@@ -64,7 +66,7 @@ inline void viewProfile(std::shared_ptr<ZenvyController> controller)
<< "Email: " << currentEmployee->getEmployeeEmail() << std::endl
<< "Phone: " << currentEmployee->getEmployeePhone() << std::endl;
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::GENERAL) {
if (auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(currentEmployee))
if (auto generalEmployee = dynamic_cast<const GeneralEmployee*>(currentEmployee))
{
std::cout << "Designation: " << Enums::getEmployeeDesignationString(generalEmployee->getDesignation()) << std::endl;
}
@@ -94,10 +96,7 @@ inline void viewProfile(std::shared_ptr<ZenvyController> controller)
}
}
void displayCandidateDetails(const std::vector<std::shared_ptr<const Candidate>>& shorlistedCandidates);
void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& controller);
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
inline void updateProfile(ZenvyController* m_zenvyController)
{
int choice;
std::string name, phone;
@@ -148,10 +147,10 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
}
}
inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>> allEmployees)
inline std::string selectEmployeeId(std::vector<const Employee*>& allEmployees)
{
int choice;
std::map<int, std::shared_ptr<const Employee>> employeeList;
std::map<int, const Employee*> employeeList;
int index = 0;
util::clear();
if (allEmployees.empty())
@@ -177,7 +176,7 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
<< std::setw(20) << "Employee Designation" << std::endl;
for (const auto& employee : employeeList)
{
auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(employee.second);
auto generalEmployee = dynamic_cast<const GeneralEmployee*>(employee.second);
std::cout << std::left
<< std::setw(10) << employee.first
<< std::setw(15) << employee.second->getId()
@@ -209,14 +208,14 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
}
}
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
inline void deactivateEmployee(const ZenvyController* m_zenvyController)
{
std::string selectedEmployeeId = selectEmployeeId(controller->getEmployees());
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees());
if (selectedEmployeeId.empty())
{
return;
}
if (controller->deactivateEmployee(selectedEmployeeId))
if (m_zenvyController->deactivateEmployee(selectedEmployeeId))
{
std::cout << "Employee deactivated successfully\n";
util::pressEnter();
@@ -228,7 +227,7 @@ inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controlle
}
}
inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
inline void viewEmployees(ZenvyController* m_zenvyController)
{
util::clear();
std::cout << "Employee List\n";
@@ -261,13 +260,13 @@ inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
util::pressEnter();
}
inline void searchEmployee(std::shared_ptr<ZenvyController> m_zenvyController)
inline void searchEmployee(ZenvyController* m_zenvyController)
{
std::string name;
util::clear();
std::cout << "Enter Employee Name: ";
util::read(name);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchResults = m_zenvyController->searchEmployee(name);
std::pair<Enums::EmployeeType, std::vector<const Employee*>> searchResults = m_zenvyController->searchEmployee(name);
if (!(searchResults.second).empty())
{
std::cout << std::left
@@ -333,7 +332,7 @@ inline void searchEmployee(std::shared_ptr<ZenvyController> m_zenvyController)
util::pressEnter();
}
inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
inline void viewPayslip(ZenvyController* m_zenvyController)
{
int year, month;
util::clear();
@@ -341,14 +340,14 @@ inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
util::read(year);
std::cout << "Enter the month: ";
util::read(month);
auto employee = controller->getCurrentEmployee();
auto employee = m_zenvyController->getCurrentEmployee();
if (!employee)
{
std::cout << "No authenticated employee.\n";
util::pressEnter();
return;
}
auto result = controller->getPayslipForMonth(employee->getId(), year, month);
auto result = m_zenvyController->getPayslipForMonth(employee->getId(), year, month);
auto payroll = result.first;
auto payslip = result.second;
if (payroll && payslip)
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "TalentExecutiveMenu.h"
#include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "TeamExecutiveMenu.h"
#include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include "TeamLeadMenu.h"
#include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#include <iostream>
#include <utility>
#include <stdexcept>
@@ -4,7 +4,6 @@
* Author: Trenser
* Created: 02-Apr-2026
*/
#pragma once
#include <utility>
#include "AdminMenu.h"