Implement Controller registerUser()
- Implement Controller registerUser()
- Add Parent Constructor Initialization for User Sub Classes
This commit is contained in:
@@ -6,6 +6,7 @@ Date: 17-02-2026
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "Order.h"
|
#include "Order.h"
|
||||||
|
|
||||||
@@ -13,8 +14,16 @@ using orders = std::map<int, std::shared_ptr<Order>>;
|
|||||||
|
|
||||||
class Customer : public User
|
class Customer : public User
|
||||||
{
|
{
|
||||||
orders m_orders;
|
|
||||||
private:
|
private:
|
||||||
|
orders m_orders;
|
||||||
|
public:
|
||||||
|
Customer(const std::string& username,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& phone,
|
||||||
|
const std::string& password,
|
||||||
|
const std::string& email) :
|
||||||
|
User(username, name, phone, password, email)
|
||||||
|
{}
|
||||||
void addOrder(std::shared_ptr<Order>);
|
void addOrder(std::shared_ptr<Order>);
|
||||||
orders& getOrders();
|
orders& getOrders();
|
||||||
std::string getType() const override;
|
std::string getType() const override;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Date: 17-02-2026
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "DeliveryAssignment.h"
|
#include "DeliveryAssignment.h"
|
||||||
|
|
||||||
@@ -16,6 +17,13 @@ class DeliveryPartner : public User
|
|||||||
private:
|
private:
|
||||||
deliveryAssignments m_deliveryAssignments;
|
deliveryAssignments m_deliveryAssignments;
|
||||||
public:
|
public:
|
||||||
|
DeliveryPartner(const std::string& username,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& phone,
|
||||||
|
const std::string& password,
|
||||||
|
const std::string& email) :
|
||||||
|
User(username, name, phone, password, email)
|
||||||
|
{}
|
||||||
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
|
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
|
||||||
deliveryAssignments& getAssignedDeliveries();
|
deliveryAssignments& getAssignedDeliveries();
|
||||||
std::string getType() const override;
|
std::string getType() const override;
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ Date: 19-02-2026
|
|||||||
#include "CustomerMenu.h"
|
#include "CustomerMenu.h"
|
||||||
#include "DeliveryPartnerMenu.h"
|
#include "DeliveryPartnerMenu.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
|
#include "RestaurantOwner.h"
|
||||||
|
#include "Customer.h"
|
||||||
|
#include "DeliveryPartner.h"
|
||||||
#include "inputHelper.h"
|
#include "inputHelper.h"
|
||||||
#include "outputHelper.h"
|
#include "outputHelper.h"
|
||||||
|
|
||||||
@@ -54,3 +57,55 @@ void FoodDeliveryController::login()
|
|||||||
std::cout << "User Not Found!\n";
|
std::cout << "User Not Found!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoodDeliveryController::registerUser()
|
||||||
|
{
|
||||||
|
std::string username, password, phone, name, email;
|
||||||
|
util::clear();
|
||||||
|
std::cout << "Enter Username: ";
|
||||||
|
util::readString(username);
|
||||||
|
if (m_users.find(username) != m_users.end())
|
||||||
|
{
|
||||||
|
std::cout << "User Already Exists!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::cout << "Enter Password: ";
|
||||||
|
util::readString(password);
|
||||||
|
std::cout << "Enter Full Name: ";
|
||||||
|
util::readString(name);
|
||||||
|
std::cout << "Enter Phone: ";
|
||||||
|
util::readString(phone);
|
||||||
|
std::cout << "Enter Email: ";
|
||||||
|
util::readString(email);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int choice;
|
||||||
|
std::cout << "Select User Type\n"
|
||||||
|
"1. Restaurant Owner\n"
|
||||||
|
"2. Customer\n"
|
||||||
|
"3. Delivery Partner\n"
|
||||||
|
"4. Cancel\n"
|
||||||
|
"Choice?: ";
|
||||||
|
util::readValue<int>(choice);
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
m_users[username] = std::make_shared<RestaurantOwner>(username, name, phone, password, email);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_users[username] = std::make_shared<Customer>(username, name, phone, password, email);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
m_users[username] = std::make_shared<DeliveryPartner>(username, name, phone, password, email);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
util::clear();
|
||||||
|
std::cout << "Invalid Choice! Try Again\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cout << "User Registration Successful\n";
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ private:
|
|||||||
std::shared_ptr<User> m_authenticatedUser;
|
std::shared_ptr<User> m_authenticatedUser;
|
||||||
public:
|
public:
|
||||||
void login();
|
void login();
|
||||||
|
void registerUser();
|
||||||
void listRestaurants();
|
void listRestaurants();
|
||||||
void updateRestaurantStatus();
|
void updateRestaurantStatus();
|
||||||
void listRestaurantOrders();
|
void listRestaurantOrders();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Date: 17-02-2026
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "Restaurant.h"
|
#include "Restaurant.h"
|
||||||
#include "MenuItem.h"
|
#include "MenuItem.h"
|
||||||
@@ -17,6 +18,13 @@ class RestaurantOwner : public User
|
|||||||
private:
|
private:
|
||||||
restaurants m_restaurants;
|
restaurants m_restaurants;
|
||||||
public:
|
public:
|
||||||
|
RestaurantOwner(const std::string& username,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& phone,
|
||||||
|
const std::string& password,
|
||||||
|
const std::string& email) :
|
||||||
|
User(username, name, phone, password, email)
|
||||||
|
{}
|
||||||
void addRestaurant(std::shared_ptr<Restaurant>);
|
void addRestaurant(std::shared_ptr<Restaurant>);
|
||||||
restaurants& getRestaurants();
|
restaurants& getRestaurants();
|
||||||
std::string getType() const override;
|
std::string getType() const override;
|
||||||
|
|||||||
Reference in New Issue
Block a user