Make controller helper pickRestaurantFromRestaurants() generic
This commit is contained in:
@@ -28,11 +28,10 @@ static bool checkAccess(std::shared_ptr<User> user, const std::string& userWithA
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static restaurants::iterator pickRestaurantFromRestaurants(RestaurantOwner& restaurantOwner)
|
static restaurants::iterator pickRestaurantFromRestaurants(restaurants& ownerRestaurants)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
int restaurantIndex = 1, restaurantChoiceIndex;
|
int restaurantIndex = 1, restaurantChoiceIndex;
|
||||||
restaurants& ownerRestaurants = restaurantOwner.getRestaurants();
|
|
||||||
if (ownerRestaurants.empty())
|
if (ownerRestaurants.empty())
|
||||||
{
|
{
|
||||||
std::cout << "You do not own any Restaurants!\n";
|
std::cout << "You do not own any Restaurants!\n";
|
||||||
@@ -307,7 +306,7 @@ void FoodDeliveryController::updateRestaurantStatus() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner);
|
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants());
|
||||||
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
||||||
{
|
{
|
||||||
if (restaurantIterator->second->getStatus() == true)
|
if (restaurantIterator->second->getStatus() == true)
|
||||||
@@ -353,7 +352,7 @@ void FoodDeliveryController::listMenuItems() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner);
|
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants());
|
||||||
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -400,7 +399,7 @@ void FoodDeliveryController::addMenuItem() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner);
|
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants());
|
||||||
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -438,7 +437,7 @@ void FoodDeliveryController::removeMenuItem() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner);
|
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner.getRestaurants());
|
||||||
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
||||||
{
|
{
|
||||||
menuItems& restaurantMenuItems = restaurantIterator->second->getMenuItems();
|
menuItems& restaurantMenuItems = restaurantIterator->second->getMenuItems();
|
||||||
|
|||||||
Reference in New Issue
Block a user