Remove hardcorded User Types and improve code readability
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "Customer.h"
|
||||
|
||||
const std::string Customer::TYPE = "Customer";
|
||||
|
||||
void Customer::addOrder(std::shared_ptr<Order> orderPointer)
|
||||
{
|
||||
m_orders[orderPointer->getId()] = orderPointer;
|
||||
@@ -12,5 +14,5 @@ orders& Customer::getOrders()
|
||||
|
||||
std::string Customer::getType() const
|
||||
{
|
||||
return "Customer";
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class Customer : public User
|
||||
private:
|
||||
orders m_orders;
|
||||
public:
|
||||
static const std::string TYPE;
|
||||
Customer(const std::string& username,
|
||||
const std::string& name,
|
||||
const std::string& phone,
|
||||
|
||||
@@ -5,6 +5,8 @@ Date: 18-02-2026
|
||||
|
||||
#include "DeliveryPartner.h"
|
||||
|
||||
const std::string DeliveryPartner::TYPE = "DeliveryPartner";
|
||||
|
||||
void DeliveryPartner::acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment> deliveryAssignmentPointer)
|
||||
{
|
||||
m_deliveryAssignments[deliveryAssignmentPointer->getId()] = deliveryAssignmentPointer;
|
||||
@@ -17,5 +19,5 @@ deliveryAssignments& DeliveryPartner::getAssignedDeliveries()
|
||||
|
||||
std::string DeliveryPartner::getType() const
|
||||
{
|
||||
return "DeliveryPartner";
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class DeliveryPartner : public User
|
||||
private:
|
||||
deliveryAssignments m_deliveryAssignments;
|
||||
public:
|
||||
static const std::string TYPE;
|
||||
DeliveryPartner(const std::string& username,
|
||||
const std::string& name,
|
||||
const std::string& phone,
|
||||
|
||||
@@ -10,6 +10,7 @@ Date: 22-12-2026
|
||||
#include<fstream>
|
||||
#include<string>
|
||||
#include<stdexcept>
|
||||
|
||||
template <typename T> using objects = std::map<int, std::shared_ptr<T>>;
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -448,15 +448,15 @@ void FoodDeliveryController::login()
|
||||
std::unique_ptr<Menu> menu;
|
||||
if (user.login(password))
|
||||
{
|
||||
if (user.getType() == "RestaurantOwner")
|
||||
if (user.getType() == RestaurantOwner::TYPE)
|
||||
{
|
||||
menu = std::make_unique<RestaurantOwnerMenu>(*this, user.getName());
|
||||
}
|
||||
else if (user.getType() == "Customer")
|
||||
else if (user.getType() == Customer::TYPE)
|
||||
{
|
||||
menu = std::make_unique<CustomerMenu>(*this, user.getName());
|
||||
}
|
||||
else if (user.getType() == "DeliveryPartner")
|
||||
else if (user.getType() == DeliveryPartner::TYPE)
|
||||
{
|
||||
menu = std::make_unique<DeliveryPartnerMenu>(*this, user.getName());
|
||||
}
|
||||
@@ -557,7 +557,7 @@ void FoodDeliveryController::registerUser()
|
||||
void FoodDeliveryController::listRestaurants() const
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -587,7 +587,7 @@ void FoodDeliveryController::addNewRestaurant()
|
||||
{
|
||||
std::string name;
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -605,7 +605,7 @@ void FoodDeliveryController::updateRestaurantStatus() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -641,7 +641,7 @@ void FoodDeliveryController::listRestaurantOrders() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -704,7 +704,7 @@ void FoodDeliveryController::setOrderReady()
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -757,7 +757,7 @@ void FoodDeliveryController::listMenuItems() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -806,7 +806,7 @@ void FoodDeliveryController::addMenuItem() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -844,7 +844,7 @@ void FoodDeliveryController::removeMenuItem() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
if (!checkAccess(m_authenticatedUser, RestaurantOwner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -881,7 +881,7 @@ void FoodDeliveryController::listCustomerOrders() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "Customer"))
|
||||
if (!checkAccess(m_authenticatedUser, Customer::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -940,7 +940,7 @@ void FoodDeliveryController::placeOrder()
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "Customer"))
|
||||
if (!checkAccess(m_authenticatedUser, Customer::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1030,7 +1030,7 @@ void FoodDeliveryController::cancelOrder() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "Customer"))
|
||||
if (!checkAccess(m_authenticatedUser, Customer::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1076,7 +1076,7 @@ void FoodDeliveryController::listDeliveryAssignments()
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "DeliveryPartner"))
|
||||
if (!checkAccess(m_authenticatedUser, DeliveryPartner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1122,7 +1122,7 @@ void FoodDeliveryController::acceptDeliveryAssignment()
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "DeliveryPartner"))
|
||||
if (!checkAccess(m_authenticatedUser, DeliveryPartner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1169,7 +1169,7 @@ void FoodDeliveryController::confirmDeliveryAssignment() const
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "DeliveryPartner"))
|
||||
if (!checkAccess(m_authenticatedUser, DeliveryPartner::TYPE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ Date: 18-02-2026
|
||||
|
||||
#include "RestaurantOwner.h"
|
||||
|
||||
const std::string RestaurantOwner::TYPE = "RestaurantOwner";
|
||||
|
||||
void RestaurantOwner::addRestaurant(std::shared_ptr<Restaurant> restaurantPointer)
|
||||
{
|
||||
m_restaurants[restaurantPointer->getId()] = restaurantPointer;
|
||||
@@ -17,5 +19,5 @@ restaurants& RestaurantOwner::getRestaurants()
|
||||
|
||||
std::string RestaurantOwner::getType() const
|
||||
{
|
||||
return "RestaurantOwner";
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ using restaurants = std::map<int, std::shared_ptr<Restaurant>>;
|
||||
class RestaurantOwner : public User
|
||||
{
|
||||
private:
|
||||
restaurants m_restaurants;
|
||||
restaurants m_restaurants;
|
||||
public:
|
||||
static const std::string TYPE;
|
||||
RestaurantOwner(const std::string& username,
|
||||
const std::string& name,
|
||||
const std::string& phone,
|
||||
|
||||
Reference in New Issue
Block a user