Class EnquiryService

java.lang.Object
com.ntu.fdae.group1.bto.services.enquiry.EnquiryService
All Implemented Interfaces:
IEnquiryService

public class EnquiryService extends Object implements IEnquiryService
Service for managing enquiries in the BTO Management System.

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 Details

    • EnquiryService

      public EnquiryService(IEnquiryRepository enquiryRepo)
      Constructs an EnquiryService with the specified enquiry repository.
      Parameters:
      enquiryRepo - The repository for enquiry data access operations
  • Method Details

    • createEnquiry

      public Enquiry createEnquiry(User user, String projectId, String content)
      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 interface IEnquiryService
      Parameters:
      user - The user creating the enquiry
      projectId - The ID of the project the enquiry is about
      content - The content/text of the enquiry
      Returns:
      The newly created Enquiry object
    • editEnquiry

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

      Updates the enquiry's content and saves the changes to the repository.

      Specified by:
      editEnquiry in interface IEnquiryService
      Parameters:
      enquiryId - The ID of the enquiry to edit
      newContent - The new content for the enquiry
      user - The user attempting to edit the enquiry
      Returns:
      true if the edit was successful
    • deleteEnquiry

      public boolean deleteEnquiry(String enquiryId, User user)
      Deletes an enquiry with the specified ID.

      Attempts to delete the enquiry from the repository and returns a success indicator.

      Specified by:
      deleteEnquiry in interface IEnquiryService
      Parameters:
      enquiryId - The ID of the enquiry to delete
      user - The user attempting to delete the enquiry
      Returns:
      true if the deletion was successful, false if an error occurred
    • replyToEnquiry

      public boolean replyToEnquiry(String enquiryId, String replyContent, HDBStaff staff)
      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 interface IEnquiryService
      Parameters:
      enquiryId - The ID of the enquiry to reply to
      replyContent - The content of the reply
      staff - 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

      public List<Enquiry> viewMyEnquiries(User user)
      Retrieves all enquiries made by a specific user.
      Specified by:
      viewMyEnquiries in interface IEnquiryService
      Parameters:
      user - The user whose enquiries to retrieve
      Returns:
      A list of enquiries made by the specified user
    • viewAllEnquiries

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

      This method is typically used by HDB staff to view all enquiries.

      Specified by:
      viewAllEnquiries in interface IEnquiryService
      Returns:
      A list of all enquiries in the system
    • viewProjectEnquiries

      public List<Enquiry> viewProjectEnquiries(String projectId)
      Retrieves all enquiries related to a specific project.
      Specified by:
      viewProjectEnquiries in interface IEnquiryService
      Parameters:
      projectId - The ID of the project
      Returns:
      A list of enquiries for the specified project
    • findEnquiryById

      public Enquiry findEnquiryById(String enquiryId)
      Finds an enquiry by its unique identifier.
      Specified by:
      findEnquiryById in interface IEnquiryService
      Parameters:
      enquiryId - The ID of the enquiry to find
      Returns:
      The enquiry with the specified ID, or null if not found