Add private Controller helper method getRestaurantFromRestaurants()
This commit is contained in:
@@ -28,6 +28,44 @@ bool checkAccess(std::shared_ptr<User> user, const std::string& userWithAccess)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restaurants::iterator pickRestaurantFromRestaurants(RestaurantOwner& restaurantOwner)
|
||||||
|
{
|
||||||
|
util::clear();
|
||||||
|
int restaurantIndex = 1, restaurantChoiceIndex;
|
||||||
|
restaurants& ownerRestaurants = restaurantOwner.getRestaurants();
|
||||||
|
if (ownerRestaurants.empty())
|
||||||
|
{
|
||||||
|
std::cout << "You do not own any Restaurants!\n";
|
||||||
|
return ownerRestaurants.end();
|
||||||
|
}
|
||||||
|
std::cout << "Pick a Restaurant\n";
|
||||||
|
std::cout << std::left << std::setw(8) << "Index"
|
||||||
|
<< std::left << std::setw(5) << "ID"
|
||||||
|
<< std::left << std::setw(25) << "Name"
|
||||||
|
<< std::left << std::setw(10) << "Status"
|
||||||
|
<< "\n";
|
||||||
|
for (restaurants::iterator restaurantIterator = ownerRestaurants.begin(); restaurantIterator != ownerRestaurants.end(); restaurantIterator++, restaurantIndex++)
|
||||||
|
{
|
||||||
|
auto& restaurant = *(restaurantIterator->second);
|
||||||
|
std::cout
|
||||||
|
<< std::left << std::setw(8) << restaurantIndex
|
||||||
|
<< std::left << std::setw(5) << restaurant.getId()
|
||||||
|
<< std::left << std::setw(25) << restaurant.getName()
|
||||||
|
<< std::left << std::setw(10) << (restaurant.getStatus() ? "Open" : "Closed")
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
std::cout << "\nSelect Index: ";
|
||||||
|
util::readValue<int>(restaurantChoiceIndex);
|
||||||
|
restaurantChoiceIndex--;
|
||||||
|
if (restaurantChoiceIndex < 0 || restaurantChoiceIndex >= ownerRestaurants.size())
|
||||||
|
{
|
||||||
|
return ownerRestaurants.end();
|
||||||
|
}
|
||||||
|
restaurants::iterator restaurantIterator = ownerRestaurants.begin();
|
||||||
|
std::advance(restaurantIterator, restaurantChoiceIndex);
|
||||||
|
return restaurantIterator;
|
||||||
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::run()
|
void FoodDeliveryController::run()
|
||||||
{
|
{
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
@@ -230,50 +268,25 @@ void FoodDeliveryController::updateRestaurantStatus()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
restaurants& ownerRestaurants = restaurantOwner.getRestaurants();
|
restaurants::iterator restaurantIterator = pickRestaurantFromRestaurants(restaurantOwner);
|
||||||
int restaurantChoiceIndex;
|
if (restaurantIterator != restaurantOwner.getRestaurants().end())
|
||||||
if (ownerRestaurants.empty())
|
|
||||||
{
|
{
|
||||||
std::cout << "You do not own any Restaurants!\n";
|
if (restaurantIterator->second->getStatus() == true)
|
||||||
return;
|
{
|
||||||
|
restaurantIterator->second->setStatus(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
restaurantIterator->second->setStatus(true);
|
||||||
|
}
|
||||||
|
listRestaurants();
|
||||||
|
std::cout << "Updated Restaurant " << restaurantIterator->second->getName() << " successfully\n";
|
||||||
}
|
}
|
||||||
std::cout << "Pick a Restaurant to Open/Close\n";
|
else
|
||||||
std::cout << std::left << std::setw(8) << "Index"
|
|
||||||
<< std::left << std::setw(5) << "ID"
|
|
||||||
<< std::left << std::setw(25) << "Name"
|
|
||||||
<< std::left << std::setw(10) << "Status"
|
|
||||||
<< "\n";
|
|
||||||
int restaurantIndex = 1;
|
|
||||||
for (restaurants::iterator restaurantIterator = ownerRestaurants.begin(); restaurantIterator != ownerRestaurants.end(); restaurantIterator++, restaurantIndex++)
|
|
||||||
{
|
|
||||||
auto& restaurant = *(restaurantIterator->second);
|
|
||||||
std::cout
|
|
||||||
<< std::left << std::setw(8) << restaurantIndex
|
|
||||||
<< std::left << std::setw(5) << restaurant.getId()
|
|
||||||
<< std::left << std::setw(25) << restaurant.getName()
|
|
||||||
<< std::left << std::setw(10) << (restaurant.getStatus() ? "Open" : "Closed")
|
|
||||||
<< "\n";
|
|
||||||
}
|
|
||||||
std::cout << "\nSelect Index: ";
|
|
||||||
util::readValue<int>(restaurantChoiceIndex);
|
|
||||||
restaurantChoiceIndex--;
|
|
||||||
if (restaurantChoiceIndex < 0 || restaurantChoiceIndex >= ownerRestaurants.size())
|
|
||||||
{
|
{
|
||||||
std::cout << "Invalid Index. Cannot update Restaurant status!\n";
|
std::cout << "Invalid Index. Cannot update Restaurant status!\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
restaurants::iterator restaurantIterator = ownerRestaurants.begin();
|
|
||||||
std::advance(restaurantIterator, restaurantChoiceIndex);
|
|
||||||
if (restaurantIterator->second->getStatus() == true)
|
|
||||||
{
|
|
||||||
restaurantIterator->second->setStatus(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
restaurantIterator->second->setStatus(true);
|
|
||||||
}
|
|
||||||
listRestaurants();
|
|
||||||
std::cout << "Updated Restaurant " << restaurantIterator->second->getName() << " successfully\n";
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user