From 9c2663db74277a2c47d1b48dbca9222fed459981 Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Tue, 19 May 2026 20:51:34 +0530 Subject: [PATCH] Implement Update Customer Profile Details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CUS005: Update Customer Profile Details 1. Added update profile flow in CustomerMenu to collect new email and phone number inputs. 2. Added validation for updated email and phone number before saving changes. 3. Updated Controller::updateUserDetails() to fetch the authenticated user and delegate profile update to UserManagementService. 4. Added user existence validation in UserManagementService before updating profile details. 5. Added logic in UserManagementService to update stored email and phone details for the selected user. 6. Added profile update confirmation message after successful save. Update Customer Profile Details Precondition: 1. Application is running and a customer is logged into the system. 2. Customer record exists in DataStore. 3. Customer has existing profile details stored in the system. Steps: 1. Select the Update Profile Details option. 2. Verify that the current profile details are displayed. - Verify that the system shows the customer’s existing details. 3. Enter a new valid email address and phone number. 4. Save the updated details. - Verify that the system accepts the changes and displays a success message. 5. Create or view a future booking using the same customer account. - Verify that the updated profile details are reflected in future bookings. Sreeja Reghukumar, please review --- .../controllers/Controller.cpp | 8 +++++++ .../controllers/Controller.h | 5 +++++ .../services/UserManagementService.cpp | 15 +++++++++++++ .../views/CustomerMenu.cpp | 22 +++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..0f0bc65 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -1,4 +1,6 @@ +#include #include "Controller.h" +#include "User.h" bool Controller::login(const std::string& username, const std::string& password) { @@ -28,6 +30,12 @@ void Controller::createTechnician(const std::string& username, const std::string void Controller::updateUserDetails(const std::string& email, const std::string& phone) { + User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); + if (authenticatedUser == nullptr) + { + throw std::runtime_error("No user currently logged in!"); + } + m_userManagementService.updateUserDetails(authenticatedUser->getId(), email, phone); } util::Map Controller::getServices() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..e1ecc49 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,8 @@ #include "Map.h" #include #include "Enums.h" +#include "AuthenticationManagementService.h" +#include "UserManagementService.h" class Service; class ComboPackage; @@ -14,6 +16,9 @@ class Notification; class Controller { +private: + AuthenticationManagementService m_authenticationManagementService; + UserManagementService m_userManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp index 2a5bd9e..4b2cd42 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp @@ -1 +1,16 @@ +#include #include "UserManagementService.h" +#include "User.h" + +void UserManagementService::updateUserDetails(const std::string& userID, const std::string& email, const std::string& phone) +{ + auto& usersMap = m_dataStore.getUsers(); + int index = usersMap.find(userID); + if (index == -1) + { + throw std::runtime_error("User does not exist!"); + } + User* user = usersMap.getValueAt(index); + user->setEmail(email); + user->setPhone(phone); +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 047f471..7233f23 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,7 @@ #include "CustomerMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void CustomerMenu::showMenu() { @@ -41,6 +42,27 @@ void CustomerMenu::changePassword() void CustomerMenu::updateDetails() { + std::string email, phone; + util::clear(); + std::cout << "Enter new email: "; + util::read(email); + if (!util::isEmailValid(email)) + { + std::cout << "Error: Email is invalid!"; + util::pressEnter(); + return; + } + std::cout << "Enter new phone: "; + util::read(phone); + if (!util::isPhoneNumberValid(phone)) + { + std::cout << "Error: Phone number is invalid!"; + util::pressEnter(); + return; + } + m_controller.updateUserDetails(email, phone); + std::cout << "Profile details updated successfully"; + util::pressEnter(); } void CustomerMenu::selectService()