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;
|
||||
}
|
||||
|
||||
std::string Customer::getType() const
|
||||
{
|
||||
return "Customer";
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ class Customer : public User
|
||||
private:
|
||||
void addOrder(std::shared_ptr<Order>);
|
||||
orders& getOrders();
|
||||
std::string getType() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ bool CustomerMenu::handleOperation(char choice)
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '5':
|
||||
m_foodDeliveryController.logout();
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,3 +9,8 @@ void DeliveryPartner::acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignmen
|
||||
{
|
||||
m_deliveryAssignments[deliveryAssignmentPointer->getId()] = deliveryAssignmentPointer;
|
||||
}
|
||||
|
||||
std::string DeliveryPartner::getType() const
|
||||
{
|
||||
return "DeliveryPartner";
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ private:
|
||||
public:
|
||||
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
|
||||
deliveryAssignments& getAssignedDeliveries();
|
||||
std::string getType() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ bool DeliveryPartnerMenu::handleOperation(char choice)
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '5':
|
||||
m_foodDeliveryController.logout();
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1 +1,56 @@
|
||||
/*
|
||||
Author: Joel Mathew Thomas
|
||||
Date: 19-02-2026
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#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
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
class User;
|
||||
|
||||
using users = std::map<std::string, std::shared_ptr<User>>;
|
||||
|
||||
class Menu;
|
||||
|
||||
class FoodDeliveryController
|
||||
{
|
||||
private:
|
||||
users m_users;
|
||||
std::shared_ptr<User> m_authenticatedUser;
|
||||
public:
|
||||
void login();
|
||||
void listRestaurants();
|
||||
void updateRestaurantStatus();
|
||||
void listRestaurantOrders();
|
||||
@@ -24,6 +34,5 @@ public:
|
||||
void acceptDeliveryAssignment();
|
||||
void confirmDeliveryAssignment();
|
||||
void viewProfile();
|
||||
void logout();
|
||||
};
|
||||
|
||||
|
||||
@@ -14,3 +14,8 @@ restaurants& RestaurantOwner::getRestaurants()
|
||||
{
|
||||
return m_restaurants;
|
||||
}
|
||||
|
||||
std::string RestaurantOwner::getType() const
|
||||
{
|
||||
return "RestaurantOwner";
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ private:
|
||||
public:
|
||||
void addRestaurant(std::shared_ptr<Restaurant>);
|
||||
restaurants& getRestaurants();
|
||||
std::string getType() const override;
|
||||
};
|
||||
|
||||
@@ -67,7 +67,6 @@ bool RestaurantOwnerMenu::handleOperation(char choice)
|
||||
m_foodDeliveryController.viewProfile();
|
||||
break;
|
||||
case '9':
|
||||
m_foodDeliveryController.logout();
|
||||
isMenuActive = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ private:
|
||||
std::string m_phone;
|
||||
std::string m_password;
|
||||
std::string m_email;
|
||||
|
||||
public:
|
||||
User():
|
||||
m_username(""),
|
||||
@@ -39,6 +38,7 @@ public:
|
||||
std::string getName() const;
|
||||
std::string getPhone() const;
|
||||
std::string getEmail() const;
|
||||
virtual std::string getType() const = 0;
|
||||
bool login(const std::string&) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user