Class UserService
- All Implemented Interfaces:
IUserService
This service is responsible for retrieving user information, including: - Finding users by their NRIC - Retrieving names for a collection of users
The service acts as an intermediary between controllers and the user repository, providing a clean API for user-related operations and handling any necessary business logic or data transformations.
-
Constructor Summary
ConstructorsConstructorDescriptionUserService
(IUserRepository userRepository) Constructs a new UserService with the specified user repository. -
Method Summary
Modifier and TypeMethodDescriptionfindUserById
(String nric) Finds a user by their NRIC (National Registration Identity Card).findUserNames
(Collection<String> nrics) Retrieves names for a collection of users identified by their NRICs.
-
Constructor Details
-
UserService
Constructs a new UserService with the specified user repository.- Parameters:
userRepository
- Repository for accessing user data
-
-
Method Details
-
findUserById
Finds a user by their NRIC (National Registration Identity Card).Delegates to the user repository to find a user by their NRIC. Returns null if no user is found with the specified NRIC.
- Specified by:
findUserById
in interfaceIUserService
- Parameters:
nric
- The NRIC of the user to find- Returns:
- The user with the specified NRIC, or null if not found
-
findUserNames
Retrieves names for a collection of users identified by their NRICs.This method is particularly useful for UI displays that need to show user names alongside references to users by their IDs.
Creates a mapping of NRICs to user names for the specified collection of NRICs. If a user cannot be found for a given NRIC, or if the user's name is null, the value "N/A" is used instead.
Returns an empty map if the input collection is null or empty.
- Specified by:
findUserNames
in interfaceIUserService
- Parameters:
nrics
- A collection of NRICs for which to retrieve names- Returns:
- A map of NRICs to user names
-