From 7351186baf7251c287353275885793a4668626dd Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Thu, 16 Apr 2026 10:05:19 +0530 Subject: [PATCH] Refactor shortlisted candidates access and fix index check EMP0012 : Employee Management - Changed getShorlistedCandidates() to return by value instead of reference - Updated controller and service method signatures accordingly - Fixed off-by-one error when selecting shortlisted candidate Smitha Mohan --- Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp | 2 +- Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h | 2 +- .../Trenser.Zenvy/services/EmployeeManagementService.cpp | 2 +- .../Trenser.Zenvy/services/EmployeeManagementService.h | 2 +- Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp index 1f095ee..ee04e1c 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp @@ -47,7 +47,7 @@ bool ZenvyController::updateDesignation(const std::string& id,Enums::EmployeeDes return m_employeeManagementService->updateDesignation(id,designation); } -std::vector>& ZenvyController::getShorlistedCandidates() +std::vector> ZenvyController::getShorlistedCandidates() { return m_employeeManagementService->getShorlistedCandidates(); } diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h index 78b3123..0fbe2b8 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h @@ -51,7 +51,7 @@ public: void updateProfile(const std::string&,const std::string&); std::pair>> searchEmployee(const std::string&); bool updateDesignation(const std::string&,Enums::EmployeeDesignation); - std::vector>& getShorlistedCandidates(); + std::vector> getShorlistedCandidates(); template Employees getEmployees(Types ...types) diff --git a/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.cpp b/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.cpp index d9add47..855e445 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.cpp @@ -236,7 +236,7 @@ void EmployeeManagementService::saveEmployees() generalEmployeeFileManager.save(generalEmployees); } -std::vector>& EmployeeManagementService::getShorlistedCandidates() +std::vector> EmployeeManagementService::getShorlistedCandidates() { candidateMap candidates = m_dataStore.getCandidates(); std::vector> shortlistedCandidates; diff --git a/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.h b/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.h index 4cd2da2..a292c31 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.h +++ b/Trenser.Zenvy/Trenser.Zenvy/services/EmployeeManagementService.h @@ -21,7 +21,7 @@ public: void updateProfile(const std::string&,const std::string&); std::pair>> searchEmployee(const std::string&); std::shared_ptr getCurrentEmployee(); - std::vector>& getShorlistedCandidates(); + std::vector> getShorlistedCandidates(); void loadEmployees(); void saveEmployees(); diff --git a/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp b/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp index d1d4ba3..bba68d0 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp @@ -166,7 +166,7 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr& c auto currentEmployee = controller->getCurrentEmployee(); Enums::EmployeeType employeeType; Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID; - if (index > 0 && index < shortlistedCandidates.size()) + if (index > 0 && index <= shortlistedCandidates.size()) { employeeType = getEmployeeType(currentEmployee->getEmployeeType()); std::shared_ptr candidate = shortlistedCandidates[index - 1];