Merge branch 'feature-admin-management' into feature
This commit is contained in:
+53
-14
@@ -1,12 +1,19 @@
|
||||
#include <stdexcept>
|
||||
#include "User.h"
|
||||
#include "Enums.h"
|
||||
/*
|
||||
File: UserManagementService.cpp
|
||||
Description: Implementation file containing the method definitions of the
|
||||
UserManagementService class, including user retrieval and removal logic.
|
||||
Author: Trenser
|
||||
Date:19-May-2026
|
||||
*/
|
||||
#include "Config.h"
|
||||
#include "UserManagementService.h"
|
||||
#include "ServiceManagementService.h"
|
||||
#include "PaymentManagementService.h"
|
||||
#include "InventoryManagementService.h"
|
||||
#include "Enums.h"
|
||||
#include "Factory.h"
|
||||
#include "InventoryManagementService.h"
|
||||
#include "PaymentManagementService.h"
|
||||
#include "ServiceManagementService.h"
|
||||
#include "User.h"
|
||||
#include "UserManagementService.h"
|
||||
#include <stdexcept>
|
||||
|
||||
void UserManagementService::ensureAdminExists()
|
||||
{
|
||||
@@ -73,6 +80,17 @@ void UserManagementService::updateUserDetails(const std::string& userID, const s
|
||||
user->setPhone(phone);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getUsers
|
||||
Description: Retrieves all users stored in the DataStore.
|
||||
Parameter: None
|
||||
Return type: util::Map<std::string, User*>
|
||||
*/
|
||||
util::Map<std::string, User*> UserManagementService::getUsers()
|
||||
{
|
||||
return m_dataStore.getUsers();
|
||||
}
|
||||
|
||||
util::Map<std::string, User*> UserManagementService::getUsers(util::UserType type)
|
||||
{
|
||||
util::Map<std::string, User*>& currentUsers = m_dataStore.getUsers();
|
||||
@@ -88,16 +106,37 @@ util::Map<std::string, User*> UserManagementService::getUsers(util::UserType typ
|
||||
return filteredUsersMap;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getUser
|
||||
Description: Retrieves a specific user by ID from the DataStore.
|
||||
Parameter: const std::string& userID - ID of the user
|
||||
Return type: User*
|
||||
*/
|
||||
User* UserManagementService::getUser(const std::string& userID)
|
||||
{
|
||||
util::Map<std::string, User*>& currentUsers = m_dataStore.getUsers();
|
||||
for (int iterator = 0; iterator < currentUsers.getSize(); iterator++)
|
||||
int index = m_dataStore.getUsers().find(userID);
|
||||
if (index != -1)
|
||||
{
|
||||
User* currentUser = currentUsers.getValueAt(iterator);
|
||||
if (currentUser->getId() == userID)
|
||||
{
|
||||
return currentUser;
|
||||
}
|
||||
return m_dataStore.getUsers().getValueAt(index);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: removeUser
|
||||
Description: Marks a user as inactive in the DataStore instead of deleting them.
|
||||
Parameter: const std::string& userID - ID of the user to remove
|
||||
Return type: void
|
||||
*/
|
||||
void UserManagementService::removeUser(const std::string& userID)
|
||||
{
|
||||
int index = m_dataStore.getUsers().find(userID);
|
||||
if (index != -1)
|
||||
{
|
||||
User* user = m_dataStore.getUsers().getValueAt(index);
|
||||
if (user != nullptr)
|
||||
{
|
||||
user->setState(util::State::INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user