Implement Update Customer Profile Details

<UserStory> CUS005: Update Customer Profile Details </UserStory>

<Changes>
    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.
</Changes>

<Test>

 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.

</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
2026-05-19 20:51:34 +05:30
parent 56c5c2dc70
commit 9c2663db74
4 changed files with 50 additions and 0 deletions
@@ -1,4 +1,6 @@
#include <stdexcept>
#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<std::string, const Service*> Controller::getServices()
@@ -2,6 +2,8 @@
#include "Map.h"
#include <string>
#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();
@@ -1 +1,16 @@
#include <stdexcept>
#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);
}
@@ -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()