Implement controller listRestaurants and addNewRestaurant()
- Implement Controller listRestaurants()
- Add and Implement new controller method addNewRestaurant()
- Add new controller helper method checkAccess()
- Add static unique id counter in Restaurant class
- Add new Restaurant class method getName()
- Add new option in RestaurantOwnerMenu: Add New Restaurant
This commit is contained in:
@@ -4,6 +4,7 @@ Date: 19-02-2026
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iomanip>
|
||||
#include "FoodDeliveryController.h"
|
||||
#include "Menu.h"
|
||||
#include "RestaurantOwnerMenu.h"
|
||||
@@ -13,9 +14,20 @@ Date: 19-02-2026
|
||||
#include "RestaurantOwner.h"
|
||||
#include "Customer.h"
|
||||
#include "DeliveryPartner.h"
|
||||
#include "Restaurant.h"
|
||||
#include "inputHelper.h"
|
||||
#include "outputHelper.h"
|
||||
|
||||
bool checkAccess(std::shared_ptr<User> user, const std::string& userWithAccess)
|
||||
{
|
||||
if (!user || user->getType() != userWithAccess)
|
||||
{
|
||||
std::cout << "You do not have permission to do this operation!\n";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FoodDeliveryController::run()
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
@@ -149,7 +161,48 @@ void FoodDeliveryController::registerUser()
|
||||
|
||||
void FoodDeliveryController::listRestaurants()
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||
restaurants ownerRestaurants = restaurantOwner.getRestaurants();
|
||||
if (ownerRestaurants.empty())
|
||||
{
|
||||
std::cout << "You do not own any Restaurants!\n";
|
||||
return;
|
||||
}
|
||||
std::cout << "My Restaurants\n";
|
||||
std::cout << std::left << std::setw(5) << "ID"
|
||||
<< std::left << std::setw(25) << "Name"
|
||||
<< std::left << std::setw(20) << "Status"
|
||||
<< "\n";
|
||||
for (auto& restaurantPair : ownerRestaurants)
|
||||
{
|
||||
auto& restaurant = *(restaurantPair.second);
|
||||
std::cout << std::left << std::setw(5) << restaurant.getId()
|
||||
<< std::left << std::setw(25) << restaurant.getName()
|
||||
<< std::left << std::setw(20) << (restaurant.getStatus() ? "Open" : "Closed")
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void FoodDeliveryController::addNewRestaurant()
|
||||
{
|
||||
std::string name;
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
RestaurantOwner& restaurantOwner = *(std::dynamic_pointer_cast<RestaurantOwner>(m_authenticatedUser));
|
||||
std::cout << "Enter Restaurant Name: ";
|
||||
util::readString(name);
|
||||
std::shared_ptr<Restaurant> restaurant = std::make_shared<Restaurant>(name);
|
||||
m_restaurants[restaurant->getId()] = restaurant;
|
||||
restaurantOwner.addRestaurant(restaurant);
|
||||
std::cout << "Restaurant " << restaurant->getName() << " with ID " << restaurant->getId() << " created successfully\n";
|
||||
}
|
||||
|
||||
void FoodDeliveryController::updateRestaurantStatus()
|
||||
|
||||
@@ -9,20 +9,23 @@ Date: 18-02-2026
|
||||
#include <map>
|
||||
|
||||
class User;
|
||||
class Restaurant;
|
||||
|
||||
using users = std::map<std::string, std::shared_ptr<User>>;
|
||||
|
||||
using restaurants = std::map<int, std::shared_ptr<Restaurant>>;
|
||||
|
||||
class FoodDeliveryController
|
||||
{
|
||||
private:
|
||||
users m_users;
|
||||
restaurants m_restaurants;
|
||||
std::shared_ptr<User> m_authenticatedUser;
|
||||
public:
|
||||
void run();
|
||||
void login();
|
||||
void registerUser();
|
||||
void listRestaurants();
|
||||
void addNewRestaurant();
|
||||
void updateRestaurantStatus();
|
||||
void listRestaurantOrders();
|
||||
void markOrderReady();
|
||||
|
||||
@@ -5,6 +5,8 @@ Date: 18-02-2026
|
||||
|
||||
#include "Restaurant.h"
|
||||
|
||||
int Restaurant::m_uid = 0;
|
||||
|
||||
int Restaurant::getId() const
|
||||
{
|
||||
return m_id;
|
||||
@@ -15,6 +17,11 @@ menuItems& Restaurant::getMenuItems()
|
||||
return m_menuItems;
|
||||
}
|
||||
|
||||
const std::string& Restaurant::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
orders& Restaurant::getOrders()
|
||||
{
|
||||
return m_orders;
|
||||
|
||||
@@ -16,6 +16,7 @@ using orders= std::map<int, std::shared_ptr<Order>>;
|
||||
class Restaurant
|
||||
{
|
||||
private:
|
||||
static int m_uid;
|
||||
int m_id;
|
||||
std::string m_name;
|
||||
menuItems m_menuItems;
|
||||
@@ -23,17 +24,18 @@ private:
|
||||
bool m_isOpen;
|
||||
public:
|
||||
Restaurant() :
|
||||
m_id(0),
|
||||
m_id(++m_uid),
|
||||
m_name(""),
|
||||
m_isOpen(true)
|
||||
{}
|
||||
Restaurant(int id, const std::string& name) :
|
||||
m_id(id),
|
||||
Restaurant(const std::string& name) :
|
||||
m_id(++m_uid),
|
||||
m_name(name),
|
||||
m_isOpen(true)
|
||||
{}
|
||||
int getId() const;
|
||||
menuItems& getMenuItems();
|
||||
const std::string& getName() const;
|
||||
orders& getOrders();
|
||||
bool getStatus() const;
|
||||
void setStatus(bool);
|
||||
|
||||
@@ -19,14 +19,15 @@ void RestaurantOwnerMenu::showMenu()
|
||||
std::cout << "Welcome " << m_userFullName << "\n";
|
||||
std::cout << "Restaurant Owner Menu\n"
|
||||
"1. List My Restaurants\n"
|
||||
"2. Update Restaurant Status\n"
|
||||
"3. List Orders\n"
|
||||
"4. Mark Order Ready for Delivery\n"
|
||||
"5. List Menu Items\n"
|
||||
"6. Add New Item to Menu\n"
|
||||
"7. Remove Item from Menu\n"
|
||||
"8. View My Profile\n"
|
||||
"9. Logout\n"
|
||||
"2. Add New Restaurant\n"
|
||||
"3. Update Restaurant Status\n"
|
||||
"4. List Orders\n"
|
||||
"5. Mark Order Ready for Delivery\n"
|
||||
"6. List Menu Items\n"
|
||||
"7. Add New Item to Menu\n"
|
||||
"8. Remove Item from Menu\n"
|
||||
"9. View My Profile\n"
|
||||
"10. Logout\n"
|
||||
"Choice?: ";
|
||||
util::readValue<int>(choice);
|
||||
if (!handleOperation(choice))
|
||||
@@ -46,27 +47,30 @@ bool RestaurantOwnerMenu::handleOperation(int choice)
|
||||
m_foodDeliveryController.listRestaurants();
|
||||
break;
|
||||
case 2:
|
||||
m_foodDeliveryController.updateRestaurantStatus();
|
||||
m_foodDeliveryController.addNewRestaurant();
|
||||
break;
|
||||
case 3:
|
||||
m_foodDeliveryController.listRestaurantOrders();
|
||||
m_foodDeliveryController.updateRestaurantStatus();
|
||||
break;
|
||||
case 4:
|
||||
m_foodDeliveryController.markOrderReady();
|
||||
m_foodDeliveryController.listRestaurantOrders();
|
||||
break;
|
||||
case 5:
|
||||
m_foodDeliveryController.listMenuItems();
|
||||
m_foodDeliveryController.markOrderReady();
|
||||
break;
|
||||
case 6:
|
||||
m_foodDeliveryController.addMenuItem();
|
||||
m_foodDeliveryController.listMenuItems();
|
||||
break;
|
||||
case 7:
|
||||
m_foodDeliveryController.removeMenuItem();
|
||||
m_foodDeliveryController.addMenuItem();
|
||||
break;
|
||||
case 8:
|
||||
m_foodDeliveryController.viewProfile();
|
||||
m_foodDeliveryController.removeMenuItem();
|
||||
break;
|
||||
case 9:
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case 10:
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Invalid Choice!\n";
|
||||
|
||||
Reference in New Issue
Block a user