From 9533a74d87f40b56d74950afbd75f112742ce3ba Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Tue, 19 May 2026 20:11:19 +0530 Subject: [PATCH] Implement Create Customer functionality CUS004: Register Customer Account 1. Added customer registration flow in UserInterface to collect username, name, email, password, and phone inputs. 2. Added validation for email, password, and phone number before proceeding with registration. 3. Updated Controller::createCustomer() and UserManagementService::createUser() to support customer registration with full user details including name. 4. Added duplicate username validation in UserManagementService using map predicate search. 5. Added user creation and insertion logic in UserManagementService to store newly registered customer records in DataStore. 6. Added observer attachment for newly registered users to inventory(only for admins), payment, and service notification services. 7. Added registration confirmation message display after successful customer creation. Precondition: 1. Application is running and user is on the main login/register menu. 2. DataStore is initialized and available for storing user records. 3. Existing customer records may already be present in the system. Steps: 1. Select the Register Customer option. 2. Enter valid username, name, email, password, and phone number. 3. Submit the registration request. - Verify that the system accepts valid inputs and creates the customer account. 4. Attempt registration using an already existing username. - Verify that the duplicate registration is rejected. 5. Register again with valid unique details. - Verify that the registration confirmation message is displayed. 6. Re-access application data after registration. - Verify that the customer data is stored persistently. Sreeja Reghukumar, please review --- .../controllers/Controller.cpp | 4 ++- .../controllers/Controller.h | 5 ++- .../services/UserManagementService.cpp | 33 +++++++++++++++++ .../services/UserManagementService.h | 2 +- .../views/UserInterface.cpp | 35 ++++++++++++++++++- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..48e9fc7 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -1,4 +1,5 @@ #include "Controller.h" +#include "Enums.h" bool Controller::login(const std::string& username, const std::string& password) { @@ -13,8 +14,9 @@ void Controller::changePassword(const std::string& newPassword) { } -void Controller::createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone) +void Controller::createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone) { + m_userManagementService.createUser(username, name, password, email, phone, util::UserType::CUSTOMER); } const User* Controller::getAuthenticatedUser() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..f7e2826 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,7 @@ #include "Map.h" #include #include "Enums.h" +#include "UserManagementService.h" class Service; class ComboPackage; @@ -14,11 +15,13 @@ class Notification; class Controller { +private: + UserManagementService m_userManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); void changePassword(const std::string& newPassword); - void createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone); + void createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone); const User* getAuthenticatedUser(); void createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone); void updateUserDetails(const std::string& email, const std::string& phone); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp index 2a5bd9e..55a068d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp @@ -1 +1,34 @@ +#include #include "UserManagementService.h" +#include "ServiceManagementService.h" +#include "PaymentManagementService.h" +#include "InventoryManagementService.h" +#include "User.h" +#include "Factory.h" +#include "Enums.h" + +void UserManagementService::createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type) +{ + InventoryManagementService inventoryManagementService; + PaymentManagementService paymentManagementService; + ServiceManagementService serviceManagementService; + auto& usersMap = m_dataStore.getUsers(); + int index = usersMap.findIf( + [&](const std::string&, User* user) + { + return user->getUserName() == username; + } + ); + if (index != -1) + { + throw std::runtime_error("Username already exists"); + } + User* newUser = Factory::getObject(username, password, name, phone, email, type); + usersMap.insert(newUser->getId(), newUser); + paymentManagementService.attach(newUser); + serviceManagementService.attach(newUser); + if (newUser->getUserType() == util::UserType::ADMIN) + { + inventoryManagementService.attach(newUser); + } +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h index bb7a85a..cab8484 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h @@ -13,7 +13,7 @@ private: DataStore& m_dataStore; public: UserManagementService() : m_dataStore(DataStore::getInstance()) {} - void createUser(const std::string& username, const std::string& password, const std::string& email, const std::string& phone, util::UserType type); + void createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type); void updateUserDetails(const std::string& userID, const std::string& email, const std::string& phone); util::Map getUsers(); util::Map getUsers(util::UserType type); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp index 122f9a8..6d71a97 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp @@ -1,6 +1,7 @@ #include "UserInterface.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void UserInterface::run() { @@ -53,5 +54,37 @@ void UserInterface::login() void UserInterface::registerCustomer() { - + std::string username, name, email, phone, password; + util::clear(); + std::cout << "Enter username: "; + util::read(username); + std::cout << "Enter name: "; + util::read(name); + std::cout << "Enter email: "; + util::read(email); + if (!util::isEmailValid(email)) + { + std::cout << "Error: Email is invalid!"; + util::pressEnter(); + return; + } + std::cout << "Enter password: "; + util::read(password); + if (!util::isPasswordValid(password)) + { + std::cout << "Error: Password is invalid!"; + util::pressEnter(); + return; + } + std::cout << "Enter phone: "; + util::read(phone); + if (!util::isPhoneNumberValid(phone)) + { + std::cout << "Error: Phone number is invalid!"; + util::pressEnter(); + return; + } + m_controller.createCustomer(username, name, password, email, phone); + std::cout << "Registration is successful"; + util::pressEnter(); }