Class UserService

java.lang.Object
com.ntu.fdae.group1.bto.services.user.UserService
All Implemented Interfaces:
IUserService

public class UserService extends Object implements IUserService
Implementation of the IUserService interface that provides user management functionality for the BTO Management System.

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 Details

    • UserService

      public UserService(IUserRepository userRepository)
      Constructs a new UserService with the specified user repository.
      Parameters:
      userRepository - Repository for accessing user data
  • Method Details

    • findUserById

      public User findUserById(String nric)
      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 interface IUserService
      Parameters:
      nric - The NRIC of the user to find
      Returns:
      The user with the specified NRIC, or null if not found
    • findUserNames

      public Map<String,String> findUserNames(Collection<String> nrics)
      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 interface IUserService
      Parameters:
      nrics - A collection of NRICs for which to retrieve names
      Returns:
      A map of NRICs to user names