Class CustomerService

java.lang.Object
org.bookstore.customer.service.CustomerService

public class CustomerService extends Object
The class CustomerService defines a service to manage the customers of a bookstore.
  • Constructor Details

    • CustomerService

      public CustomerService()
  • Method Details

    • registerCustomer

      public Customer registerCustomer(Customer customer) throws EmailAlreadyExistsException
      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

      public Customer findCustomer(long id) throws CustomerNotFoundException
      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

      public List<CustomerInfo> searchCustomers(String name)
      Searches for customers by name.
      A customer is included in the result if the specified name is contained in the first or last 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 exists
      EmailAlreadyExistsException - if the new email address is already used by another customer