Interface UserRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<User,,Long> org.springframework.data.jpa.repository.JpaRepository<User,,Long> org.springframework.data.repository.ListCrudRepository<User,,Long> org.springframework.data.repository.ListPagingAndSortingRepository<User,,Long> org.springframework.data.repository.PagingAndSortingRepository<User,,Long> org.springframework.data.repository.query.QueryByExampleExecutor<User>,org.springframework.data.repository.Repository<User,Long>
User entity hierarchy.
Serves as a common access point for both Customer
and Admin entities, since they both extend User.
Provides generic CRUD operations and utility methods that work across all user types.
Specific queries (e.g., by mobile, secret word, etc.) are defined in dedicated repositories
(CustomerRepository, AdminRepository).
This repository is particularly useful for:
- Authentication invalid input: '&' authorization (finding user by login)
- Global search by name across all users
- Admin tools managing any type of user account
- Account deletion by login identifier
Automatically implemented by Spring at runtime — no implementation class needed.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByLogin(String login) Deletes a user by their login.findByLogin(String login) Finds a user (Customer or Admin) by their unique login.findByName(String name) Finds a user (Customer or Admin) by their full name.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByName
Finds a user (Customer or Admin) by their full name.Useful for global search functionality in admin panels or support tools. Note: Names are not guaranteed to be unique, so at most one result is returned (first match by ID order).
- Parameters:
name- the full name to search for (case-sensitive)- Returns:
- an
Optionalcontaining the user if found
-
findByLogin
Finds a user (Customer or Admin) by their unique login.This is the primary method used during authentication. Login is unique across the entire system.
- Parameters:
login- the unique login/username- Returns:
- an
Optionalcontaining theUserif found, orOptional.empty()if no user has this login
-
deleteByLogin
Deletes a user by their login.Convenience method for account removal without loading the full entity first. Used in:
- Admin-initiated user deletion
- GDPR "right to be forgotten" requests
- Automated cleanup scripts
Warning: This is a destructive operation. Ensure proper authorization, auditing, and cascading/soft-delete logic.
- Parameters:
login- the login of the user to delete
-