Implement Controller run()
- Implement Controller run() - Remove Do you want to continue prompts for util::pressEnter - change type of choice from char -> int - Display Invalid Password on bad login - Create empty controller method definitions
This commit is contained in:
@@ -14,7 +14,7 @@ void CustomerMenu::showMenu()
|
||||
bool isMenuActive = true;
|
||||
while (isMenuActive)
|
||||
{
|
||||
char choice;
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Welcome " << m_userFullName << "\n";
|
||||
std::cout << "Customer Menu\n"
|
||||
@@ -24,7 +24,7 @@ void CustomerMenu::showMenu()
|
||||
"4. View My Profile\n"
|
||||
"5. Logout\n"
|
||||
"Choice?: ";
|
||||
util::readValue<char>(choice);
|
||||
util::readValue<int>(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
isMenuActive = false;
|
||||
@@ -32,33 +32,29 @@ void CustomerMenu::showMenu()
|
||||
}
|
||||
}
|
||||
|
||||
bool CustomerMenu::handleOperation(char choice)
|
||||
bool CustomerMenu::handleOperation(int choice)
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
util::clear();
|
||||
switch (choice)
|
||||
{
|
||||
case '1':
|
||||
case 1:
|
||||
m_foodDeliveryController.listCustomerOrders();
|
||||
break;
|
||||
case '2':
|
||||
case 2:
|
||||
m_foodDeliveryController.placeOrder();
|
||||
break;
|
||||
case '3':
|
||||
case 3:
|
||||
m_foodDeliveryController.cancelOrder();
|
||||
break;
|
||||
case '4':
|
||||
case 4:
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '5':
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
std::cout << "\nDo you want to continue (Y/N)?: ";
|
||||
util::readValue<char>(choice);
|
||||
if (choice != 'Y' && choice != 'y')
|
||||
{
|
||||
isMenuActive = false;
|
||||
case 5:
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Invalid Choice!\n";
|
||||
}
|
||||
util::pressEnter();
|
||||
return isMenuActive;
|
||||
}
|
||||
|
||||
@@ -13,5 +13,5 @@ class CustomerMenu : public Menu
|
||||
public:
|
||||
CustomerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
|
||||
void showMenu() override;
|
||||
bool handleOperation(char) override;
|
||||
bool handleOperation(int) override;
|
||||
};
|
||||
|
||||
@@ -14,17 +14,17 @@ void DeliveryPartnerMenu::showMenu()
|
||||
bool isMenuActive = true;
|
||||
while (isMenuActive)
|
||||
{
|
||||
char choice;
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Welcome " << m_userFullName << "\n";
|
||||
std::cout << "DeliveryPartner Menu\n"
|
||||
std::cout << "Delivery Partner Menu\n"
|
||||
"1. View My Delivery Jobs\n"
|
||||
"2. Accept Delivery Job\n"
|
||||
"3. Confirm Delivery\n"
|
||||
"4. View My Profile\n"
|
||||
"5. Logout\n"
|
||||
"Choice?: ";
|
||||
util::readValue<char>(choice);
|
||||
util::readValue<int>(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
isMenuActive = false;
|
||||
@@ -32,33 +32,29 @@ void DeliveryPartnerMenu::showMenu()
|
||||
}
|
||||
}
|
||||
|
||||
bool DeliveryPartnerMenu::handleOperation(char choice)
|
||||
bool DeliveryPartnerMenu::handleOperation(int choice)
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
util::clear();
|
||||
switch (choice)
|
||||
{
|
||||
case '1':
|
||||
case 1:
|
||||
m_foodDeliveryController.listDeliveryAssignments();
|
||||
break;
|
||||
case '2':
|
||||
case 2:
|
||||
m_foodDeliveryController.acceptDeliveryAssignment();
|
||||
break;
|
||||
case '3':
|
||||
case 3:
|
||||
m_foodDeliveryController.confirmDeliveryAssignment();
|
||||
break;
|
||||
case '4':
|
||||
case 4:
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '5':
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
std::cout << "\nDo you want to continue (Y/N)?: ";
|
||||
util::readValue<char>(choice);
|
||||
if (choice != 'Y' && choice != 'y')
|
||||
{
|
||||
isMenuActive = false;
|
||||
case 5:
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Invalid Choice!\n";
|
||||
}
|
||||
util::pressEnter();
|
||||
return isMenuActive;
|
||||
}
|
||||
@@ -13,5 +13,5 @@ class DeliveryPartnerMenu : public Menu
|
||||
public:
|
||||
DeliveryPartnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
|
||||
void showMenu() override;
|
||||
bool handleOperation(char) override;
|
||||
bool handleOperation(int) override;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,39 @@ Date: 19-02-2026
|
||||
#include "inputHelper.h"
|
||||
#include "outputHelper.h"
|
||||
|
||||
void FoodDeliveryController::run()
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
while (isMenuActive)
|
||||
{
|
||||
char choice;
|
||||
util::clear();
|
||||
std::cout << "Food Delivery App\n"
|
||||
"1. Login\n"
|
||||
"2. Register\n"
|
||||
"3. Exit\n"
|
||||
"Choice?: ";
|
||||
util::readValue<char>(choice);
|
||||
if (choice == '1')
|
||||
{
|
||||
login();
|
||||
}
|
||||
else if (choice == '2')
|
||||
{
|
||||
registerUser();
|
||||
}
|
||||
else if (choice == '3')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid Choice!\n";
|
||||
}
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
|
||||
void FoodDeliveryController::login()
|
||||
{
|
||||
util::clear();
|
||||
@@ -51,6 +84,10 @@ void FoodDeliveryController::login()
|
||||
menu->showMenu();
|
||||
m_authenticatedUser.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid Password! Try Again\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,3 +146,73 @@ void FoodDeliveryController::registerUser()
|
||||
}
|
||||
std::cout << "User Registration Successful\n";
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listRestaurants()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::updateRestaurantStatus()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listRestaurantOrders()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::markOrderReady()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listMenuItems()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::addMenuItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::removeMenuItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listCustomerOrders()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::placeOrder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::cancelOrder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listDeliveryAssignments()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::acceptDeliveryAssignment()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::confirmDeliveryAssignment()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FoodDeliveryController::viewProfile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ private:
|
||||
users m_users;
|
||||
std::shared_ptr<User> m_authenticatedUser;
|
||||
public:
|
||||
void run();
|
||||
void login();
|
||||
void registerUser();
|
||||
void listRestaurants();
|
||||
|
||||
@@ -18,6 +18,6 @@ public:
|
||||
Menu(FoodDeliveryController& foodDeliveryController, const std::string& userFullName) : m_foodDeliveryController(foodDeliveryController), m_userFullName(userFullName) {}
|
||||
virtual ~Menu() = default;
|
||||
virtual void showMenu() = 0;
|
||||
virtual bool handleOperation(char) = 0;
|
||||
virtual bool handleOperation(int) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ void RestaurantOwnerMenu::showMenu()
|
||||
bool isMenuActive = true;
|
||||
while (isMenuActive)
|
||||
{
|
||||
char choice;
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Welcome " << m_userFullName << "\n";
|
||||
std::cout << "Restaurant Owner Menu\n"
|
||||
@@ -28,7 +28,7 @@ void RestaurantOwnerMenu::showMenu()
|
||||
"8. View My Profile\n"
|
||||
"9. Logout\n"
|
||||
"Choice?: ";
|
||||
util::readValue<char>(choice);
|
||||
util::readValue<int>(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
isMenuActive = false;
|
||||
@@ -36,45 +36,41 @@ void RestaurantOwnerMenu::showMenu()
|
||||
}
|
||||
}
|
||||
|
||||
bool RestaurantOwnerMenu::handleOperation(char choice)
|
||||
bool RestaurantOwnerMenu::handleOperation(int choice)
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
util::clear();
|
||||
switch (choice)
|
||||
{
|
||||
case '1':
|
||||
case 1:
|
||||
m_foodDeliveryController.listRestaurants();
|
||||
break;
|
||||
case '2':
|
||||
case 2:
|
||||
m_foodDeliveryController.updateRestaurantStatus();
|
||||
break;
|
||||
case '3':
|
||||
case 3:
|
||||
m_foodDeliveryController.listRestaurantOrders();
|
||||
break;
|
||||
case '4':
|
||||
case 4:
|
||||
m_foodDeliveryController.markOrderReady();
|
||||
break;
|
||||
case '5':
|
||||
case 5:
|
||||
m_foodDeliveryController.listMenuItems();
|
||||
break;
|
||||
case '6':
|
||||
case 6:
|
||||
m_foodDeliveryController.addMenuItem();
|
||||
break;
|
||||
case '7':
|
||||
case 7:
|
||||
m_foodDeliveryController.removeMenuItem();
|
||||
break;
|
||||
case '8':
|
||||
case 8:
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '9':
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
std::cout << "\nDo you want to continue (Y/N)?: ";
|
||||
util::readValue<char>(choice);
|
||||
if (choice != 'Y' && choice != 'y')
|
||||
{
|
||||
isMenuActive = false;
|
||||
case 9:
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Invalid Choice!\n";
|
||||
}
|
||||
util::pressEnter();
|
||||
return isMenuActive;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ class RestaurantOwnerMenu : public Menu
|
||||
public:
|
||||
RestaurantOwnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
|
||||
void showMenu() override;
|
||||
bool handleOperation(char) override;
|
||||
bool handleOperation(int) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,16 +4,18 @@ Date: 17-02-2026
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include <stdexcept>
|
||||
#include "FoodDeliveryController.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
FoodDeliveryController controller;
|
||||
controller.run();
|
||||
}
|
||||
catch (const exception& e)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
cout << "Exception : " << e.what() << endl;
|
||||
std::cout << "Exception : " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user