Refactor shortlisted candidates access and fix index check

<UserStory> EMP0012 : Employee Management </UserStory>

<Changes>
 - 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
</Changes>

<Review>
Smitha Mohan
</Review>
This commit is contained in:
2026-04-16 10:05:19 +05:30
parent f15d5b7f1d
commit 7351186baf
5 changed files with 5 additions and 5 deletions
@@ -47,7 +47,7 @@ bool ZenvyController::updateDesignation(const std::string& id,Enums::EmployeeDes
return m_employeeManagementService->updateDesignation(id,designation);
}
std::vector<std::shared_ptr<Candidate>>& ZenvyController::getShorlistedCandidates()
std::vector<std::shared_ptr<Candidate>> ZenvyController::getShorlistedCandidates()
{
return m_employeeManagementService->getShorlistedCandidates();
}
@@ -51,7 +51,7 @@ public:
void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
bool updateDesignation(const std::string&,Enums::EmployeeDesignation);
std::vector<std::shared_ptr<Candidate>>& getShorlistedCandidates();
std::vector<std::shared_ptr<Candidate>> getShorlistedCandidates();
template <typename ...Types>
Employees getEmployees(Types ...types)
@@ -236,7 +236,7 @@ void EmployeeManagementService::saveEmployees()
generalEmployeeFileManager.save(generalEmployees);
}
std::vector<std::shared_ptr<Candidate>>& EmployeeManagementService::getShorlistedCandidates()
std::vector<std::shared_ptr<Candidate>> EmployeeManagementService::getShorlistedCandidates()
{
candidateMap candidates = m_dataStore.getCandidates();
std::vector<std::shared_ptr<Candidate>> shortlistedCandidates;
@@ -21,7 +21,7 @@ public:
void updateProfile(const std::string&,const std::string&);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchEmployee(const std::string&);
std::shared_ptr<const Employee> getCurrentEmployee();
std::vector<std::shared_ptr<Candidate>>& getShorlistedCandidates();
std::vector<std::shared_ptr<Candidate>> getShorlistedCandidates();
void loadEmployees();
void saveEmployees();
@@ -166,7 +166,7 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& 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> candidate = shortlistedCandidates[index - 1];