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 <stdexcept>
|
||||||
|
#include <iomanip>
|
||||||
#include "FoodDeliveryController.h"
|
#include "FoodDeliveryController.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "RestaurantOwnerMenu.h"
|
#include "RestaurantOwnerMenu.h"
|
||||||
@@ -13,9 +14,20 @@ Date: 19-02-2026
|
|||||||
#include "RestaurantOwner.h"
|
#include "RestaurantOwner.h"
|
||||||
#include "Customer.h"
|
#include "Customer.h"
|
||||||
#include "DeliveryPartner.h"
|
#include "DeliveryPartner.h"
|
||||||
|
#include "Restaurant.h"
|
||||||
#include "inputHelper.h"
|
#include "inputHelper.h"
|
||||||
#include "outputHelper.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()
|
void FoodDeliveryController::run()
|
||||||
{
|
{
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
@@ -149,7 +161,48 @@ void FoodDeliveryController::registerUser()
|
|||||||
|
|
||||||
void FoodDeliveryController::listRestaurants()
|
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()
|
void FoodDeliveryController::updateRestaurantStatus()
|
||||||
|
|||||||
@@ -9,20 +9,23 @@ Date: 18-02-2026
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class User;
|
class User;
|
||||||
|
class Restaurant;
|
||||||
|
|
||||||
using users = std::map<std::string, std::shared_ptr<User>>;
|
using users = std::map<std::string, std::shared_ptr<User>>;
|
||||||
|
using restaurants = std::map<int, std::shared_ptr<Restaurant>>;
|
||||||
|
|
||||||
class FoodDeliveryController
|
class FoodDeliveryController
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
users m_users;
|
users m_users;
|
||||||
|
restaurants m_restaurants;
|
||||||
std::shared_ptr<User> m_authenticatedUser;
|
std::shared_ptr<User> m_authenticatedUser;
|
||||||
public:
|
public:
|
||||||
void run();
|
void run();
|
||||||
void login();
|
void login();
|
||||||
void registerUser();
|
void registerUser();
|
||||||
void listRestaurants();
|
void listRestaurants();
|
||||||
|
void addNewRestaurant();
|
||||||
void updateRestaurantStatus();
|
void updateRestaurantStatus();
|
||||||
void listRestaurantOrders();
|
void listRestaurantOrders();
|
||||||
void markOrderReady();
|
void markOrderReady();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ Date: 18-02-2026
|
|||||||
|
|
||||||
#include "Restaurant.h"
|
#include "Restaurant.h"
|
||||||
|
|
||||||
|
int Restaurant::m_uid = 0;
|
||||||
|
|
||||||
int Restaurant::getId() const
|
int Restaurant::getId() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
@@ -15,6 +17,11 @@ menuItems& Restaurant::getMenuItems()
|
|||||||
return m_menuItems;
|
return m_menuItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& Restaurant::getName() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
orders& Restaurant::getOrders()
|
orders& Restaurant::getOrders()
|
||||||
{
|
{
|
||||||
return m_orders;
|
return m_orders;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using orders= std::map<int, std::shared_ptr<Order>>;
|
|||||||
class Restaurant
|
class Restaurant
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
static int m_uid;
|
||||||
int m_id;
|
int m_id;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
menuItems m_menuItems;
|
menuItems m_menuItems;
|
||||||
@@ -23,17 +24,18 @@ private:
|
|||||||
bool m_isOpen;
|
bool m_isOpen;
|
||||||
public:
|
public:
|
||||||
Restaurant() :
|
Restaurant() :
|
||||||
m_id(0),
|
m_id(++m_uid),
|
||||||
m_name(""),
|
m_name(""),
|
||||||
m_isOpen(true)
|
m_isOpen(true)
|
||||||
{}
|
{}
|
||||||
Restaurant(int id, const std::string& name) :
|
Restaurant(const std::string& name) :
|
||||||
m_id(id),
|
m_id(++m_uid),
|
||||||
m_name(name),
|
m_name(name),
|
||||||
m_isOpen(true)
|
m_isOpen(true)
|
||||||
{}
|
{}
|
||||||
int getId() const;
|
int getId() const;
|
||||||
menuItems& getMenuItems();
|
menuItems& getMenuItems();
|
||||||
|
const std::string& getName() const;
|
||||||
orders& getOrders();
|
orders& getOrders();
|
||||||
bool getStatus() const;
|
bool getStatus() const;
|
||||||
void setStatus(bool);
|
void setStatus(bool);
|
||||||
|
|||||||
@@ -19,14 +19,15 @@ void RestaurantOwnerMenu::showMenu()
|
|||||||
std::cout << "Welcome " << m_userFullName << "\n";
|
std::cout << "Welcome " << m_userFullName << "\n";
|
||||||
std::cout << "Restaurant Owner Menu\n"
|
std::cout << "Restaurant Owner Menu\n"
|
||||||
"1. List My Restaurants\n"
|
"1. List My Restaurants\n"
|
||||||
"2. Update Restaurant Status\n"
|
"2. Add New Restaurant\n"
|
||||||
"3. List Orders\n"
|
"3. Update Restaurant Status\n"
|
||||||
"4. Mark Order Ready for Delivery\n"
|
"4. List Orders\n"
|
||||||
"5. List Menu Items\n"
|
"5. Mark Order Ready for Delivery\n"
|
||||||
"6. Add New Item to Menu\n"
|
"6. List Menu Items\n"
|
||||||
"7. Remove Item from Menu\n"
|
"7. Add New Item to Menu\n"
|
||||||
"8. View My Profile\n"
|
"8. Remove Item from Menu\n"
|
||||||
"9. Logout\n"
|
"9. View My Profile\n"
|
||||||
|
"10. Logout\n"
|
||||||
"Choice?: ";
|
"Choice?: ";
|
||||||
util::readValue<int>(choice);
|
util::readValue<int>(choice);
|
||||||
if (!handleOperation(choice))
|
if (!handleOperation(choice))
|
||||||
@@ -46,27 +47,30 @@ bool RestaurantOwnerMenu::handleOperation(int choice)
|
|||||||
m_foodDeliveryController.listRestaurants();
|
m_foodDeliveryController.listRestaurants();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
m_foodDeliveryController.updateRestaurantStatus();
|
m_foodDeliveryController.addNewRestaurant();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
m_foodDeliveryController.listRestaurantOrders();
|
m_foodDeliveryController.updateRestaurantStatus();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
m_foodDeliveryController.markOrderReady();
|
m_foodDeliveryController.listRestaurantOrders();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
m_foodDeliveryController.listMenuItems();
|
m_foodDeliveryController.markOrderReady();
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
m_foodDeliveryController.addMenuItem();
|
m_foodDeliveryController.listMenuItems();
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
m_foodDeliveryController.removeMenuItem();
|
m_foodDeliveryController.addMenuItem();
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
m_foodDeliveryController.viewProfile();
|
m_foodDeliveryController.removeMenuItem();
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
|
m_foodDeliveryController.viewProfile();
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
std::cout << "Invalid Choice!\n";
|
std::cout << "Invalid Choice!\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user