From 1fb2e57404de8bbbf8883d9a9b7bafa00267010c Mon Sep 17 00:00:00 2001 From: Joel Thomas <1914@trenser.com> Date: Fri, 20 Feb 2026 09:46:02 +0530 Subject: [PATCH] Make controller helper pickRestaurantFromRestaurants() generic --- .../FoodDeliveryController.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Trenser.FoodDeliveryApp/Trenser.FoodDeliveryApp/FoodDeliveryController.cpp b/Trenser.FoodDeliveryApp/Trenser.FoodDeliveryApp/FoodDeliveryController.cpp index 9c361ac..723de3d 100644 --- a/Trenser.FoodDeliveryApp/Trenser.FoodDeliveryApp/FoodDeliveryController.cpp +++ b/Trenser.FoodDeliveryApp/Trenser.FoodDeliveryApp/FoodDeliveryController.cpp @@ -28,11 +28,10 @@ static bool checkAccess(std::shared_ptr user, const std::string& userWithA return true; } -static restaurants::iterator pickRestaurantFromRestaurants(RestaurantOwner& restaurantOwner) +static restaurants::iterator pickRestaurantFromRestaurants(restaurants& ownerRestaurants) { util::clear(); int restaurantIndex = 1, restaurantChoiceIndex; - restaurants& ownerRestaurants = restaurantOwner.getRestaurants(); if (ownerRestaurants.empty()) { std::cout << "You do not own any Restaurants!\n"; @@ -307,7 +306,7 @@ void FoodDeliveryController::updateRestaurantStatus() const return; } RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast(m_authenticatedUser)); - restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner); + restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants()); if (restaurantIterator != restaurantOwner.getRestaurants().end()) { if (restaurantIterator->second->getStatus() == true) @@ -353,7 +352,7 @@ void FoodDeliveryController::listMenuItems() const return; } RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast(m_authenticatedUser)); - restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner); + restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants()); if (restaurantIterator != restaurantOwner.getRestaurants().end()) { util::clear(); @@ -400,7 +399,7 @@ void FoodDeliveryController::addMenuItem() const return; } RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast(m_authenticatedUser)); - restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner); + restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants()); if (restaurantIterator != restaurantOwner.getRestaurants().end()) { util::clear(); @@ -438,7 +437,7 @@ void FoodDeliveryController::removeMenuItem() const return; } RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast(m_authenticatedUser)); - restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner); + restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants()); if (restaurantIterator != restaurantOwner.getRestaurants().end()) { menuItems& restaurantMenuItems = restaurantIterator->second->getMenuItems();