Implement Controller login()
- Implement Controller login() - Add getType() method in User to determine User Type to create corresponding menu object - Remove logout() method from Controller, as login() can procedurally logout - Remove unused includes from Controller
This commit is contained in:
@@ -9,3 +9,8 @@ orders& Customer::getOrders()
|
|||||||
{
|
{
|
||||||
return m_orders;
|
return m_orders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Customer::getType() const
|
||||||
|
{
|
||||||
|
return "Customer";
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ class Customer : public User
|
|||||||
private:
|
private:
|
||||||
void addOrder(std::shared_ptr<Order>);
|
void addOrder(std::shared_ptr<Order>);
|
||||||
orders& getOrders();
|
orders& getOrders();
|
||||||
|
std::string getType() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ bool CustomerMenu::handleOperation(char choice)
|
|||||||
m_foodDeliveryController.viewProfile();
|
m_foodDeliveryController.viewProfile();
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
m_foodDeliveryController.logout();
|
|
||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,3 +9,8 @@ void DeliveryPartner::acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignmen
|
|||||||
{
|
{
|
||||||
m_deliveryAssignments[deliveryAssignmentPointer->getId()] = deliveryAssignmentPointer;
|
m_deliveryAssignments[deliveryAssignmentPointer->getId()] = deliveryAssignmentPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DeliveryPartner::getType() const
|
||||||
|
{
|
||||||
|
return "DeliveryPartner";
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
|
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
|
||||||
deliveryAssignments& getAssignedDeliveries();
|
deliveryAssignments& getAssignedDeliveries();
|
||||||
|
std::string getType() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ bool DeliveryPartnerMenu::handleOperation(char choice)
|
|||||||
m_foodDeliveryController.viewProfile();
|
m_foodDeliveryController.viewProfile();
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
m_foodDeliveryController.logout();
|
|
||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,56 @@
|
|||||||
|
/*
|
||||||
|
Author: Joel Mathew Thomas
|
||||||
|
Date: 19-02-2026
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include "FoodDeliveryController.h"
|
#include "FoodDeliveryController.h"
|
||||||
|
#include "Menu.h"
|
||||||
|
#include "RestaurantOwnerMenu.h"
|
||||||
|
#include "CustomerMenu.h"
|
||||||
|
#include "DeliveryPartnerMenu.h"
|
||||||
|
#include "User.h"
|
||||||
|
#include "inputHelper.h"
|
||||||
|
#include "outputHelper.h"
|
||||||
|
|
||||||
|
void FoodDeliveryController::login()
|
||||||
|
{
|
||||||
|
util::clear();
|
||||||
|
std::string username, password;
|
||||||
|
std::cout << "Enter username: ";;
|
||||||
|
util::readString(username);
|
||||||
|
std::cout << "Enter password: ";;
|
||||||
|
util::readString(password);
|
||||||
|
users::iterator userIterator = m_users.find(username);
|
||||||
|
if (userIterator != m_users.end())
|
||||||
|
{
|
||||||
|
User& user = *(userIterator->second);
|
||||||
|
std::unique_ptr<Menu> menu;
|
||||||
|
if (user.login(password))
|
||||||
|
{
|
||||||
|
if (user.getType() == "RestaurantOwner")
|
||||||
|
{
|
||||||
|
menu = std::make_unique<RestaurantOwnerMenu>(*this, user.getUsername());
|
||||||
|
}
|
||||||
|
else if (user.getType() == "Customer")
|
||||||
|
{
|
||||||
|
menu = std::make_unique<CustomerMenu>(*this, user.getUsername());
|
||||||
|
}
|
||||||
|
else if (user.getType() == "DeliveryPartner")
|
||||||
|
{
|
||||||
|
menu = std::make_unique<DeliveryPartnerMenu>(*this, user.getUsername());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid User");
|
||||||
|
}
|
||||||
|
m_authenticatedUser = userIterator->second;
|
||||||
|
menu->showMenu();
|
||||||
|
m_authenticatedUser.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "User Not Found!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,12 +4,22 @@ Date: 18-02-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class User;
|
||||||
|
|
||||||
|
using users = std::map<std::string, std::shared_ptr<User>>;
|
||||||
|
|
||||||
class Menu;
|
|
||||||
|
|
||||||
class FoodDeliveryController
|
class FoodDeliveryController
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
users m_users;
|
||||||
|
std::shared_ptr<User> m_authenticatedUser;
|
||||||
public:
|
public:
|
||||||
|
void login();
|
||||||
void listRestaurants();
|
void listRestaurants();
|
||||||
void updateRestaurantStatus();
|
void updateRestaurantStatus();
|
||||||
void listRestaurantOrders();
|
void listRestaurantOrders();
|
||||||
@@ -24,6 +34,5 @@ public:
|
|||||||
void acceptDeliveryAssignment();
|
void acceptDeliveryAssignment();
|
||||||
void confirmDeliveryAssignment();
|
void confirmDeliveryAssignment();
|
||||||
void viewProfile();
|
void viewProfile();
|
||||||
void logout();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,3 +14,8 @@ restaurants& RestaurantOwner::getRestaurants()
|
|||||||
{
|
{
|
||||||
return m_restaurants;
|
return m_restaurants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RestaurantOwner::getType() const
|
||||||
|
{
|
||||||
|
return "RestaurantOwner";
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ private:
|
|||||||
public:
|
public:
|
||||||
void addRestaurant(std::shared_ptr<Restaurant>);
|
void addRestaurant(std::shared_ptr<Restaurant>);
|
||||||
restaurants& getRestaurants();
|
restaurants& getRestaurants();
|
||||||
|
std::string getType() const override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ bool RestaurantOwnerMenu::handleOperation(char choice)
|
|||||||
m_foodDeliveryController.viewProfile();
|
m_foodDeliveryController.viewProfile();
|
||||||
break;
|
break;
|
||||||
case '9':
|
case '9':
|
||||||
m_foodDeliveryController.logout();
|
|
||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ private:
|
|||||||
std::string m_phone;
|
std::string m_phone;
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
std::string m_email;
|
std::string m_email;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
User():
|
User():
|
||||||
m_username(""),
|
m_username(""),
|
||||||
@@ -39,6 +38,7 @@ public:
|
|||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
std::string getPhone() const;
|
std::string getPhone() const;
|
||||||
std::string getEmail() const;
|
std::string getEmail() const;
|
||||||
|
virtual std::string getType() const = 0;
|
||||||
bool login(const std::string&) const;
|
bool login(const std::string&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user