Class EnquiryController

java.lang.Object
com.ntu.fdae.group1.bto.controllers.enquiry.EnquiryController

public class EnquiryController extends Object
Controller responsible for managing enquiry-related operations in the BTO Management System.

This controller serves as an intermediary between the UI layer and the enquiry service, handling operations such as creating, editing, and deleting enquiries, as well as managing replies to enquiries. It also enforces business rules regarding who can perform certain operations on enquiries.

The controller implements role-based authorization checks to ensure that: - Only the creator of an enquiry can edit or delete it - Enquiries that have been replied to cannot be edited or deleted - HDB Officers can only reply to enquiries for projects they are approved for - HDB Managers can access and reply to all enquiries

  • Constructor Details

    • EnquiryController

      public EnquiryController(IEnquiryService enquiryService, IOfficerRegistrationService registrationService)
      Constructs a new EnquiryController with the specified services.

      Uses dependency injection to receive the required services and performs null checks to ensure valid dependencies.

      Parameters:
      enquiryService - The service handling enquiry-related business logic
      registrationService - The service handling officer registration status checks
      Throws:
      NullPointerException - if either service is null
  • Method Details

    • createEnquiry

      public Enquiry createEnquiry(User user, String projectId, String content)
      Creates a new enquiry in the system.

      Allows users to submit enquiries either related to a specific project or as general enquiries when projectId is null. The enquiry is associated with the user who created it.

      Parameters:
      user - The user creating the enquiry
      projectId - ID of the related project, or null for general enquiries
      content - The enquiry content
      Returns:
      The created enquiry with its assigned ID and metadata
    • editEnquiry

      public boolean editEnquiry(String enquiryId, String newContent, User user)
      Edits an existing enquiry's content.

      This operation is restricted by the following business rules: 1. Only the original creator of the enquiry can edit it 2. Enquiries that have already received a reply cannot be edited 3. The new content must not be empty or null

      Parameters:
      enquiryId - ID of the enquiry to edit
      newContent - New content for the enquiry
      user - The user editing the enquiry
      Returns:
      true if edit was successful, false otherwise
    • deleteEnquiry

      public boolean deleteEnquiry(String enquiryId, User user)
      Deletes an existing enquiry from the system.

      This operation is restricted by the following business rules: 1. Only the original creator of the enquiry can delete it 2. Enquiries that have already received a reply cannot be deleted

      Parameters:
      enquiryId - ID of the enquiry to delete
      user - The user deleting the enquiry
      Returns:
      true if deletion was successful, false otherwise
    • replyToEnquiry

      public boolean replyToEnquiry(HDBStaff staff, String enquiryId, String replyContent)
      Adds an official reply to an existing enquiry.

      This operation is restricted by role-based authorization: - HDB Managers can reply to any enquiry - HDB Officers can only reply to enquiries for projects they are approved for

      Once an enquiry has been replied to, it can no longer be edited or deleted by the original submitter.

      Parameters:
      staff - The HDB staff member (Officer or Manager) providing the reply
      enquiryId - ID of the enquiry to reply to
      replyContent - The content of the reply
      Returns:
      true if reply was successfully added, false otherwise
    • viewMyEnquiries

      public List<Enquiry> viewMyEnquiries(User user)
      Retrieves all enquiries submitted by a specific user.

      This method allows users to view their own enquiry history, including both replied and non-replied enquiries.

      Parameters:
      user - The user whose enquiries to retrieve
      Returns:
      List of enquiries submitted by the user, or an empty list if none exist
    • viewAllEnquiries

      public List<Enquiry> viewAllEnquiries()
      Retrieves all enquiries in the system.

      This method provides access to all enquiries regardless of their status or the project they are associated with. It is typically used by administrators or for reporting purposes.

      Returns:
      List of all enquiries in the system
    • viewProjectEnquiries

      public List<Enquiry> viewProjectEnquiries(HDBStaff staff, String projectId) throws InvalidInputException, AuthenticationException, DataAccessException
      Retrieves enquiries associated with a specific project, performing authorization checks.

      This method implements role-based access control: - Managers can view enquiries for any project - Officers can only view enquiries for projects they are approved to handle

      The method performs thorough validation and exception handling to provide clear feedback about authorization issues or data access problems.

      Parameters:
      staff - The HDB staff member (Officer or Manager) making the request
      projectId - The ID of the project whose enquiries are requested
      Returns:
      A List of Enquiry objects for the specified project
      Throws:
      InvalidInputException - if projectId is null or empty
      AuthenticationException - if the staff member is not authorized to view these enquiries
      DataAccessException - if an error occurs during data retrieval or authorization check
    • findEnquiryById

      public Enquiry findEnquiryById(String enquiryId)
      Finds an enquiry by its unique identifier.

      This method retrieves a specific enquiry based on its ID. It is commonly used before performing operations like editing, deleting, or replying to an enquiry to verify the enquiry exists and check its current state.

      Parameters:
      enquiryId - ID of the enquiry to find
      Returns:
      The enquiry if found, or null if no enquiry exists with the given ID