Class EnquiryService
- All Implemented Interfaces:
IEnquiryService
This service is responsible for handling the business logic related to enquiries, including: - Creating new enquiries - Editing and deleting existing enquiries - Replying to enquiries (for HDB staff) - Retrieving enquiries by various criteria (user, project, ID)
The service follows the Service Layer pattern, encapsulating business logic related to enquiry management and providing a clean API for controllers.
-
Constructor Summary
ConstructorsConstructorDescriptionEnquiryService
(IEnquiryRepository enquiryRepo) Constructs an EnquiryService with the specified enquiry repository. -
Method Summary
Modifier and TypeMethodDescriptioncreateEnquiry
(User user, String projectId, String content) Creates a new enquiry with the specified details.boolean
deleteEnquiry
(String enquiryId, User user) Deletes an enquiry with the specified ID.boolean
editEnquiry
(String enquiryId, String newContent, User user) Edits the content of an existing enquiry.findEnquiryById
(String enquiryId) Finds an enquiry by its unique identifier.boolean
replyToEnquiry
(String enquiryId, String replyContent, HDBStaff staff) Adds a reply to an enquiry.Retrieves all enquiries in the system.viewMyEnquiries
(User user) Retrieves all enquiries made by a specific user.viewProjectEnquiries
(String projectId) Retrieves all enquiries related to a specific project.
-
Constructor Details
-
EnquiryService
Constructs an EnquiryService with the specified enquiry repository.- Parameters:
enquiryRepo
- The repository for enquiry data access operations
-
-
Method Details
-
createEnquiry
Creates a new enquiry with the specified details.Generates a unique ID for the enquiry, sets the creation date to the current date, and saves it to the repository.
- Specified by:
createEnquiry
in interfaceIEnquiryService
- Parameters:
user
- The user creating the enquiryprojectId
- The ID of the project the enquiry is aboutcontent
- The content/text of the enquiry- Returns:
- The newly created Enquiry object
-
editEnquiry
Edits the content of an existing enquiry.Updates the enquiry's content and saves the changes to the repository.
- Specified by:
editEnquiry
in interfaceIEnquiryService
- Parameters:
enquiryId
- The ID of the enquiry to editnewContent
- The new content for the enquiryuser
- The user attempting to edit the enquiry- Returns:
- true if the edit was successful
-
deleteEnquiry
Deletes an enquiry with the specified ID.Attempts to delete the enquiry from the repository and returns a success indicator.
- Specified by:
deleteEnquiry
in interfaceIEnquiryService
- Parameters:
enquiryId
- The ID of the enquiry to deleteuser
- The user attempting to delete the enquiry- Returns:
- true if the deletion was successful, false if an error occurred
-
replyToEnquiry
Adds a reply to an enquiry.Verifies that the enquiry exists and has not been previously replied to, then adds the reply with the current date and saves the updated enquiry.
- Specified by:
replyToEnquiry
in interfaceIEnquiryService
- Parameters:
enquiryId
- The ID of the enquiry to reply toreplyContent
- The content of the replystaff
- The HDB staff member providing the reply- Returns:
- true if the reply was successfully added, false if the enquiry doesn't exist or already has a reply
-
viewMyEnquiries
Retrieves all enquiries made by a specific user.- Specified by:
viewMyEnquiries
in interfaceIEnquiryService
- Parameters:
user
- The user whose enquiries to retrieve- Returns:
- A list of enquiries made by the specified user
-
viewAllEnquiries
Retrieves all enquiries in the system.This method is typically used by HDB staff to view all enquiries.
- Specified by:
viewAllEnquiries
in interfaceIEnquiryService
- Returns:
- A list of all enquiries in the system
-
viewProjectEnquiries
Retrieves all enquiries related to a specific project.- Specified by:
viewProjectEnquiries
in interfaceIEnquiryService
- Parameters:
projectId
- The ID of the project- Returns:
- A list of enquiries for the specified project
-
findEnquiryById
Finds an enquiry by its unique identifier.- Specified by:
findEnquiryById
in interfaceIEnquiryService
- Parameters:
enquiryId
- The ID of the enquiry to find- Returns:
- The enquiry with the specified ID, or null if not found
-