Package service
Class CustomerService
java.lang.Object
service.CustomerService
Service class for managing customer operations.
Handles customer creation, updates, retrieval, and deletion.
- Author:
- TAMIL MUGHILAN
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCustomerService
(DataStorage dataStorage) Creates a new CustomerService with the specified data storage. -
Method Summary
Modifier and TypeMethodDescriptionint
createCustomer
(String name, String phone, String email, int branchId) Creates a new customer.int
createCustomerWithPassword
(String name, String phone, String email, int branchId, String password, String salt) Creates a new customer with password for login.boolean
deleteCustomer
(int customerId) Retrieves a customer by ID.getCustomer
(int customerId) Retrieves a customer by ID.getCustomerByEmail
(String email) Retrieves a customer by email address.getCustomersByBranch
(int branchId) Gets all customers for a specific branch.getSaltForCustomer
(int customerId) Gets the password salt for a customer.void
updateCustomer
(int customerId, String name, String phone, String email, int branchId) Updates an existing customer's information.
-
Field Details
-
dataStorage
-
-
Constructor Details
-
CustomerService
Creates a new CustomerService with the specified data storage.- Parameters:
dataStorage
- the data storage implementation to use
-
-
Method Details
-
createCustomer
Creates a new customer.- Parameters:
name
- the customer's namephone
- the customer's phone numberemail
- the customer's email addressbranchId
- 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 namephone
- the customer's phone numberemail
- the customer's email addressbranchId
- the branch IDpassword
- the hashed passwordsalt
- 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 updatename
- the new namephone
- the new phone numberemail
- the new email addressbranchId
- the new branch ID- Throws:
SQLException
- if database error occursIllegalArgumentException
- if customer data is invalid
-
getCustomer
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
Retrieves a customer by email address.- Parameters:
email
- the customer's email address- Returns:
- the customer or null if not found
-
getCustomersByBranch
Gets all customers for a specific branch.- Parameters:
branchId
- the branch ID- Returns:
- list of customers in the branch
-
getSaltForCustomer
Gets the password salt for a customer.- Parameters:
customerId
- the customer ID- Returns:
- the password salt or null if not found
-