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:
Joel Thomas
2026-02-19 15:39:37 +05:30
parent e959c32bd3
commit c5e4ecbe02
10 changed files with 159 additions and 61 deletions
@@ -14,7 +14,7 @@ void CustomerMenu::showMenu()
bool isMenuActive = true; bool isMenuActive = true;
while (isMenuActive) while (isMenuActive)
{ {
char choice; int choice;
util::clear(); util::clear();
std::cout << "Welcome " << m_userFullName << "\n"; std::cout << "Welcome " << m_userFullName << "\n";
std::cout << "Customer Menu\n" std::cout << "Customer Menu\n"
@@ -24,7 +24,7 @@ void CustomerMenu::showMenu()
"4. View My Profile\n" "4. View My Profile\n"
"5. Logout\n" "5. Logout\n"
"Choice?: "; "Choice?: ";
util::readValue<char>(choice); util::readValue<int>(choice);
if (!handleOperation(choice)) if (!handleOperation(choice))
{ {
isMenuActive = false; isMenuActive = false;
@@ -32,33 +32,29 @@ void CustomerMenu::showMenu()
} }
} }
bool CustomerMenu::handleOperation(char choice) bool CustomerMenu::handleOperation(int choice)
{ {
bool isMenuActive = true; bool isMenuActive = true;
util::clear(); util::clear();
switch (choice) switch (choice)
{ {
case '1': case 1:
m_foodDeliveryController.listCustomerOrders(); m_foodDeliveryController.listCustomerOrders();
break; break;
case '2': case 2:
m_foodDeliveryController.placeOrder(); m_foodDeliveryController.placeOrder();
break; break;
case '3': case 3:
m_foodDeliveryController.cancelOrder(); m_foodDeliveryController.cancelOrder();
break; break;
case '4': case 4:
m_foodDeliveryController.viewProfile(); m_foodDeliveryController.viewProfile();
break; break;
case '5': case 5:
isMenuActive = false; return false;
break; default:
} std::cout << "Invalid Choice!\n";
std::cout << "\nDo you want to continue (Y/N)?: ";
util::readValue<char>(choice);
if (choice != 'Y' && choice != 'y')
{
isMenuActive = false;
} }
util::pressEnter();
return isMenuActive; return isMenuActive;
} }
@@ -13,5 +13,5 @@ class CustomerMenu : public Menu
public: public:
CustomerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {} CustomerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
void showMenu() override; void showMenu() override;
bool handleOperation(char) override; bool handleOperation(int) override;
}; };
@@ -14,7 +14,7 @@ void DeliveryPartnerMenu::showMenu()
bool isMenuActive = true; bool isMenuActive = true;
while (isMenuActive) while (isMenuActive)
{ {
char choice; int choice;
util::clear(); util::clear();
std::cout << "Welcome " << m_userFullName << "\n"; std::cout << "Welcome " << m_userFullName << "\n";
std::cout << "Delivery Partner Menu\n" std::cout << "Delivery Partner Menu\n"
@@ -24,7 +24,7 @@ void DeliveryPartnerMenu::showMenu()
"4. View My Profile\n" "4. View My Profile\n"
"5. Logout\n" "5. Logout\n"
"Choice?: "; "Choice?: ";
util::readValue<char>(choice); util::readValue<int>(choice);
if (!handleOperation(choice)) if (!handleOperation(choice))
{ {
isMenuActive = false; isMenuActive = false;
@@ -32,33 +32,29 @@ void DeliveryPartnerMenu::showMenu()
} }
} }
bool DeliveryPartnerMenu::handleOperation(char choice) bool DeliveryPartnerMenu::handleOperation(int choice)
{ {
bool isMenuActive = true; bool isMenuActive = true;
util::clear(); util::clear();
switch (choice) switch (choice)
{ {
case '1': case 1:
m_foodDeliveryController.listDeliveryAssignments(); m_foodDeliveryController.listDeliveryAssignments();
break; break;
case '2': case 2:
m_foodDeliveryController.acceptDeliveryAssignment(); m_foodDeliveryController.acceptDeliveryAssignment();
break; break;
case '3': case 3:
m_foodDeliveryController.confirmDeliveryAssignment(); m_foodDeliveryController.confirmDeliveryAssignment();
break; break;
case '4': case 4:
m_foodDeliveryController.viewProfile(); m_foodDeliveryController.viewProfile();
break; break;
case '5': case 5:
isMenuActive = false; return false;
break; default:
} std::cout << "Invalid Choice!\n";
std::cout << "\nDo you want to continue (Y/N)?: ";
util::readValue<char>(choice);
if (choice != 'Y' && choice != 'y')
{
isMenuActive = false;
} }
util::pressEnter();
return isMenuActive; return isMenuActive;
} }
@@ -13,5 +13,5 @@ class DeliveryPartnerMenu : public Menu
public: public:
DeliveryPartnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {} DeliveryPartnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
void showMenu() override; void showMenu() override;
bool handleOperation(char) override; bool handleOperation(int) override;
}; };
@@ -16,6 +16,39 @@ Date: 19-02-2026
#include "inputHelper.h" #include "inputHelper.h"
#include "outputHelper.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() void FoodDeliveryController::login()
{ {
util::clear(); util::clear();
@@ -51,6 +84,10 @@ void FoodDeliveryController::login()
menu->showMenu(); menu->showMenu();
m_authenticatedUser.reset(); m_authenticatedUser.reset();
} }
else
{
std::cout << "Invalid Password! Try Again\n";
}
} }
else else
{ {
@@ -109,3 +146,73 @@ void FoodDeliveryController::registerUser()
} }
std::cout << "User Registration Successful\n"; 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; users m_users;
std::shared_ptr<User> m_authenticatedUser; std::shared_ptr<User> m_authenticatedUser;
public: public:
void run();
void login(); void login();
void registerUser(); void registerUser();
void listRestaurants(); void listRestaurants();
@@ -18,6 +18,6 @@ public:
Menu(FoodDeliveryController& foodDeliveryController, const std::string& userFullName) : m_foodDeliveryController(foodDeliveryController), m_userFullName(userFullName) {} Menu(FoodDeliveryController& foodDeliveryController, const std::string& userFullName) : m_foodDeliveryController(foodDeliveryController), m_userFullName(userFullName) {}
virtual ~Menu() = default; virtual ~Menu() = default;
virtual void showMenu() = 0; virtual void showMenu() = 0;
virtual bool handleOperation(char) = 0; virtual bool handleOperation(int) = 0;
}; };
@@ -14,7 +14,7 @@ void RestaurantOwnerMenu::showMenu()
bool isMenuActive = true; bool isMenuActive = true;
while (isMenuActive) while (isMenuActive)
{ {
char choice; int choice;
util::clear(); util::clear();
std::cout << "Welcome " << m_userFullName << "\n"; std::cout << "Welcome " << m_userFullName << "\n";
std::cout << "Restaurant Owner Menu\n" std::cout << "Restaurant Owner Menu\n"
@@ -28,7 +28,7 @@ void RestaurantOwnerMenu::showMenu()
"8. View My Profile\n" "8. View My Profile\n"
"9. Logout\n" "9. Logout\n"
"Choice?: "; "Choice?: ";
util::readValue<char>(choice); util::readValue<int>(choice);
if (!handleOperation(choice)) if (!handleOperation(choice))
{ {
isMenuActive = false; isMenuActive = false;
@@ -36,45 +36,41 @@ void RestaurantOwnerMenu::showMenu()
} }
} }
bool RestaurantOwnerMenu::handleOperation(char choice) bool RestaurantOwnerMenu::handleOperation(int choice)
{ {
bool isMenuActive = true; bool isMenuActive = true;
util::clear(); util::clear();
switch (choice) switch (choice)
{ {
case '1': case 1:
m_foodDeliveryController.listRestaurants(); m_foodDeliveryController.listRestaurants();
break; break;
case '2': case 2:
m_foodDeliveryController.updateRestaurantStatus(); m_foodDeliveryController.updateRestaurantStatus();
break; break;
case '3': case 3:
m_foodDeliveryController.listRestaurantOrders(); m_foodDeliveryController.listRestaurantOrders();
break; break;
case '4': case 4:
m_foodDeliveryController.markOrderReady(); m_foodDeliveryController.markOrderReady();
break; break;
case '5': case 5:
m_foodDeliveryController.listMenuItems(); m_foodDeliveryController.listMenuItems();
break; break;
case '6': case 6:
m_foodDeliveryController.addMenuItem(); m_foodDeliveryController.addMenuItem();
break; break;
case '7': case 7:
m_foodDeliveryController.removeMenuItem(); m_foodDeliveryController.removeMenuItem();
break; break;
case '8': case 8:
m_foodDeliveryController.viewProfile(); m_foodDeliveryController.viewProfile();
break; break;
case '9': case 9:
isMenuActive = false; return false;
break; default:
} std::cout << "Invalid Choice!\n";
std::cout << "\nDo you want to continue (Y/N)?: ";
util::readValue<char>(choice);
if (choice != 'Y' && choice != 'y')
{
isMenuActive = false;
} }
util::pressEnter();
return isMenuActive; return isMenuActive;
} }
@@ -13,6 +13,6 @@ class RestaurantOwnerMenu : public Menu
public: public:
RestaurantOwnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {} RestaurantOwnerMenu(FoodDeliveryController& foodDeliveryController, const std::string userFullName): Menu(foodDeliveryController, userFullName) {}
void showMenu() override; void showMenu() override;
bool handleOperation(char) override; bool handleOperation(int) override;
}; };
@@ -4,16 +4,18 @@ Date: 17-02-2026
*/ */
#include <iostream> #include <iostream>
using namespace std; #include <stdexcept>
#include "FoodDeliveryController.h"
int main() int main()
{ {
try 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;
} }
} }