Interface CustomerRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<Customer,Long>, org.springframework.data.jpa.repository.JpaRepository<Customer,Long>, org.springframework.data.repository.ListCrudRepository<Customer,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<Customer,Long>, org.springframework.data.repository.PagingAndSortingRepository<Customer,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<Customer>, org.springframework.data.repository.Repository<Customer,Long>

@Repository public interface CustomerRepository extends org.springframework.data.jpa.repository.JpaRepository<Customer,Long>
Spring Data JPA repository for Customer entities.

Provides standard CRUD operations inherited from JpaRepository and additional query methods specific to customer management.

The Customer entity extends

invalid reference
User
and represents registered shoppers in the system. Mobile phone number is used as a secondary unique identifier (alongside login/email) for fast lookup and account recovery.

This repository is automatically implemented by Spring at runtime — no manual implementation required.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes a customer by their mobile phone number.
    Finds a customer by their mobile phone number.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByMobile

      Optional<Customer> findByMobile(String mobile)
      Finds a customer by their mobile phone number.

      Mobile number is often used as an alternative identifier for:

      • Login via phone (SMS OTP)
      • Account recovery / password reset
      • Duplicate check during registration
      • Admin/support lookup by phone

      Assumes mobile numbers are stored in normalized format (e.g., digits only or with country code).

      Parameters:
      mobile - the customer's mobile phone number (not null, not blank)
      Returns:
      an Optional containing the matching Customer if found, or Optional.empty() if no customer has this mobile number
    • deleteByMobile

      void deleteByMobile(String mobile)
      Deletes a customer by their mobile phone number.

      Convenience method that removes a customer without loading the entity first. Useful in scenarios such as:

      • Account deletion request by phone identifier
      • GDPR / right-to-be-forgotten compliance cleanup
      • Admin tools performing bulk deletion by mobile

      Warning: This is a destructive operation. Use with extreme caution and ensure proper authorization, logging, and soft-delete consideration.

      Parameters:
      mobile - the mobile number of the customer to delete