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
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "User.h"
|
||||
#include "Order.h"
|
||||
|
||||
@@ -13,8 +14,16 @@ using orders = std::map<int, std::shared_ptr<Order>>;
|
||||
|
||||
class Customer : public User
|
||||
{
|
||||
orders m_orders;
|
||||
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>);
|
||||
orders& getOrders();
|
||||
std::string getType() const override;
|
||||
|
||||
@@ -6,6 +6,7 @@ Date: 17-02-2026
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "User.h"
|
||||
#include "DeliveryAssignment.h"
|
||||
|
||||
@@ -16,6 +17,13 @@ class DeliveryPartner : public User
|
||||
private:
|
||||
deliveryAssignments m_deliveryAssignments;
|
||||
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>);
|
||||
deliveryAssignments& getAssignedDeliveries();
|
||||
std::string getType() const override;
|
||||
|
||||
@@ -10,6 +10,9 @@ Date: 19-02-2026
|
||||
#include "CustomerMenu.h"
|
||||
#include "DeliveryPartnerMenu.h"
|
||||
#include "User.h"
|
||||
#include "RestaurantOwner.h"
|
||||
#include "Customer.h"
|
||||
#include "DeliveryPartner.h"
|
||||
#include "inputHelper.h"
|
||||
#include "outputHelper.h"
|
||||
|
||||
@@ -54,3 +57,55 @@ void FoodDeliveryController::login()
|
||||
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;
|
||||
public:
|
||||
void login();
|
||||
void registerUser();
|
||||
void listRestaurants();
|
||||
void updateRestaurantStatus();
|
||||
void listRestaurantOrders();
|
||||
|
||||
@@ -6,6 +6,7 @@ Date: 17-02-2026
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "User.h"
|
||||
#include "Restaurant.h"
|
||||
#include "MenuItem.h"
|
||||
@@ -17,6 +18,13 @@ class RestaurantOwner : public User
|
||||
private:
|
||||
restaurants m_restaurants;
|
||||
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>);
|
||||
restaurants& getRestaurants();
|
||||
std::string getType() const override;
|
||||
|
||||
Reference in New Issue
Block a user