Implement Controller updateRestaurantStatus()
- Implement Controller updateRestaurantStatus() - Avoid unecessary copies, keep ownerRestaurant reference
This commit is contained in:
@@ -167,7 +167,7 @@ void FoodDeliveryController::listRestaurants()
|
|||||||
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& 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";
|
||||||
@@ -207,7 +207,56 @@ void FoodDeliveryController::addNewRestaurant()
|
|||||||
|
|
||||||
void FoodDeliveryController::updateRestaurantStatus()
|
void FoodDeliveryController::updateRestaurantStatus()
|
||||||
{
|
{
|
||||||
|
util::clear();
|
||||||
|
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||||
|
restaurants& ownerRestaurants = restaurantOwner.getRestaurants();
|
||||||
|
int restaurantChoiceIndex;
|
||||||
|
if (ownerRestaurants.empty())
|
||||||
|
{
|
||||||
|
std::cout << "You do not own any Restaurants!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cout << "Pick a Restaurant to Open/Close\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";
|
||||||
|
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";
|
||||||
|
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";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::listRestaurantOrders()
|
void FoodDeliveryController::listRestaurantOrders()
|
||||||
|
|||||||
Reference in New Issue
Block a user