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>

@Repository public interface UserRepository extends org.springframework.data.jpa.repository.JpaRepository<User,Long>
Spring Data JPA repository for the 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 Type
    Method
    Description
    void
    Deletes a user by their login.
    Finds a user (Customer or Admin) by their unique login.
    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, 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

    • findByName

      Optional<User> findByName(String name)
      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 Optional containing the user if found
    • findByLogin

      Optional<User> findByLogin(String login)
      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 Optional containing the User if found, or Optional.empty() if no user has this login
    • deleteByLogin

      void deleteByLogin(String login)
      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