Package org.bookstore.customer.service
Class CustomerService
java.lang.Object
org.bookstore.customer.service.CustomerService
The class CustomerService defines a service to manage the customers of a bookstore.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfindCustomer
(long id) Finds a customer by identifier.registerCustomer
(Customer customer) Registers a customer.searchCustomers
(String name) Searches for customers by name.
A customer is included in the result if his first or last name matches the specified name.updateCustomer
(Customer customer) Updates the data of a customer.
-
Constructor Details
-
CustomerService
public CustomerService()
-
-
Method Details
-
registerCustomer
Registers a customer.- Parameters:
customer
- the data of the customer (identifier must be null)- Returns:
- the data of the registered customer
- Throws:
EmailAlreadyExistsException
- if the email address is already used by another customer
-
findCustomer
Finds a customer by identifier.- Parameters:
id
- the identifier of the customer- Returns:
- the data of the found customer
- Throws:
CustomerNotFoundException
- if no customer with the specified identifier exists
-
searchCustomers
Searches for customers by name.
A customer is included in the result if his first or last name matches the specified name.- Parameters:
name
- the name to search for- Returns:
- the matching customers
-
updateCustomer
public Customer updateCustomer(Customer customer) throws CustomerNotFoundException, EmailAlreadyExistsException Updates the data of a customer.- Parameters:
customer
- the new data of the customer- Returns:
- the data of the updated customer
- Throws:
CustomerNotFoundException
- if no customer with the corresponding identifier existsEmailAlreadyExistsException
- if the new email address is already used by another customer
-