Class EnquiryController
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 Summary
ConstructorsConstructorDescriptionEnquiryController
(IEnquiryService enquiryService, IOfficerRegistrationService registrationService) Constructs a new EnquiryController with the specified services. -
Method Summary
Modifier and TypeMethodDescriptioncreateEnquiry
(User user, String projectId, String content) Creates a new enquiry in the system.boolean
deleteEnquiry
(String enquiryId, User user) Deletes an existing enquiry from the system.boolean
editEnquiry
(String enquiryId, String newContent, User user) Edits an existing enquiry's content.findEnquiryById
(String enquiryId) Finds an enquiry by its unique identifier.boolean
replyToEnquiry
(HDBStaff staff, String enquiryId, String replyContent) Adds an official reply to an existing enquiry.Retrieves all enquiries in the system.viewMyEnquiries
(User user) Retrieves all enquiries submitted by a specific user.viewProjectEnquiries
(HDBStaff staff, String projectId) Retrieves enquiries associated with a specific project, performing authorization checks.
-
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 logicregistrationService
- The service handling officer registration status checks- Throws:
NullPointerException
- if either service is null
-
-
Method Details
-
createEnquiry
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 enquiryprojectId
- ID of the related project, or null for general enquiriescontent
- The enquiry content- Returns:
- The created enquiry with its assigned ID and metadata
-
editEnquiry
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 editnewContent
- New content for the enquiryuser
- The user editing the enquiry- Returns:
- true if edit was successful, false otherwise
-
deleteEnquiry
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 deleteuser
- The user deleting the enquiry- Returns:
- true if deletion was successful, false otherwise
-
replyToEnquiry
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 replyenquiryId
- ID of the enquiry to reply toreplyContent
- The content of the reply- Returns:
- true if reply was successfully added, false otherwise
-
viewMyEnquiries
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
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 requestprojectId
- 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 emptyAuthenticationException
- if the staff member is not authorized to view these enquiriesDataAccessException
- if an error occurs during data retrieval or authorization check
-
findEnquiryById
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
-