Package service

Class CustomerService

java.lang.Object
service.CustomerService

public class CustomerService extends Object
Service class for managing customer operations. Handles customer creation, updates, retrieval, and deletion.
Author:
TAMIL MUGHILAN
  • Field Details

  • Constructor Details

    • CustomerService

      public CustomerService(DataStorage dataStorage)
      Creates a new CustomerService with the specified data storage.
      Parameters:
      dataStorage - the data storage implementation to use
  • Method Details

    • createCustomer

      public int createCustomer(String name, String phone, String email, int branchId)
      Creates a new customer.
      Parameters:
      name - the customer's name
      phone - the customer's phone number
      email - the customer's email address
      branchId - the branch ID
      Returns:
      the new customer ID
    • createCustomerWithPassword

      public int createCustomerWithPassword(String name, String phone, String email, int branchId, String password, String salt)
      Creates a new customer with password for login.
      Parameters:
      name - the customer's name
      phone - the customer's phone number
      email - the customer's email address
      branchId - the branch ID
      password - the hashed password
      salt - the password salt for security
      Returns:
      the new customer ID
    • updateCustomer

      public void updateCustomer(int customerId, String name, String phone, String email, int branchId) throws SQLException
      Updates an existing customer's information.
      Parameters:
      customerId - the customer ID to update
      name - the new name
      phone - the new phone number
      email - the new email address
      branchId - the new branch ID
      Throws:
      SQLException - if database error occurs
      IllegalArgumentException - if customer data is invalid
    • getCustomer

      public Customer getCustomer(int customerId)
      Retrieves a customer by ID.
      Parameters:
      customerId - the customer ID
      Returns:
      the customer or null if not found
    • deleteCustomer

      public boolean deleteCustomer(int customerId)
      Retrieves a customer by ID.
      Parameters:
      customerId - the customer ID
      Returns:
      the customer or null if not found
    • getCustomerByEmail

      public Customer getCustomerByEmail(String email)
      Retrieves a customer by email address.
      Parameters:
      email - the customer's email address
      Returns:
      the customer or null if not found
    • getCustomersByBranch

      public List<Customer> getCustomersByBranch(int branchId)
      Gets all customers for a specific branch.
      Parameters:
      branchId - the branch ID
      Returns:
      list of customers in the branch
    • getSaltForCustomer

      public String getSaltForCustomer(int customerId)
      Gets the password salt for a customer.
      Parameters:
      customerId - the customer ID
      Returns:
      the password salt or null if not found