From 2bdf0eb7411339a4997b05c24322c1677340b35a Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Wed, 20 May 2026 12:31:54 +0530 Subject: [PATCH] Implement Add Technician Functionality ADM001: Add Technician 1. Added UserManagementService integration in Controller to support technician account creation. 2. Updated Controller::createTechnician method to call createUser with util::UserType::TECHNICIAN. 3. Renamed parameter from 'phone' to 'phoneNumber' for clarity and consistency. 4. Enhanced AdminMenu::addTechnician with input validation for password, email, and phone number. 5. Added success and error handling messages in AdminMenu for technician creation workflow. Precondition: 1. Admin is logged into the system. 2. UserManagementService is available and connected. 3. No existing technician account with the same username/email. Steps: 1. Navigate to Admin Menu and select "Add Technician". 2. Enter technician details (username, password, email, phone number). - Verify that invalid password/email/phone inputs are rejected with error messages. 3. Enter valid technician details. - Verify that uniqueness is checked and duplicate accounts are not created. 4. Submit valid details. - Verify that technician account is created successfully and confirmation message is displayed. Sreeja Reghukumar --- .../controllers/Controller.cpp | 3 +- .../controllers/Controller.h | 5 ++- .../views/AdminMenu.cpp | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..bbab445 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -22,8 +22,9 @@ const User* Controller::getAuthenticatedUser() return nullptr; } -void Controller::createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone) +void Controller::createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phoneNumber) { + m_userManagementService.createUser(username, password, email, phoneNumber, util::UserType::TECHNICIAN); } void Controller::updateUserDetails(const std::string& email, const std::string& phone) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..c618ede 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,13 +15,15 @@ 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); const User* getAuthenticatedUser(); - void createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone); + void createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phoneNumber); void updateUserDetails(const std::string& email, const std::string& phone); util::Map getServices(); util::Map getComboPackages(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index 0432f3c..18de5cf 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -1,6 +1,8 @@ +#include #include "AdminMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void AdminMenu::showMenu() { @@ -70,6 +72,37 @@ void AdminMenu::removeService() void AdminMenu::addTechnician() { + util::clear(); + std::string username, password, email, phoneNumber; + std::cout << std::left << std::setw(25) << "Enter Technician Username:"; + util::read(username); + std::cout << std::setw(25) << "Enter Technician Password:"; + util::read(password); + if(!util::isPasswordValid(password)) + { + std::cout << "Error: Password is invalid!"; + util::pressEnter(); + return; + } + std::cout << std::setw(25) << "Enter Technician Email:"; + util::read(email); + if(!util::isEmailValid(email)) + { + std::cout << "Error: Email is invalid!"; + util::pressEnter(); + return; + } + std::cout << std::setw(25) << "Enter Technician Phone:"; + util::read(phoneNumber); + if(!util::isPhoneNumberValid(phoneNumber)) + { + std::cout << "Error: Phone Number is invalid!"; + util::pressEnter(); + return; + } + m_controller.createTechnician(username, password, email, phoneNumber); + std::cout << "\nTechnician Added Successfully.\n"; + util::pressEnter(); } void AdminMenu::removeUser()