package com.plannaplan.repositories; import java.util.List; import java.util.Optional; import com.plannaplan.entities.User; import com.plannaplan.types.UserRoles; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; /** * UserRepository.getByAuthority: * Return list of: * SELECT * FROM User WHERE email = i. * * Where i, ?1 are equale to variables. * * UserRepository.getByToken: * Return list of: * SELECT * FROM User WHERE token = i. * * Where i, ?1 are equale to variables. * * UserRepository.searchForUsers: * Return list of: * SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%). * * Where i, ?1 are equale to variables. * * UserRepository.searchForUsers with role: * Return list of: * SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2"). * * Where i, ?1 are equale to variables. */ @Repository public interface UserRepository extends JpaRepository { @Query("FROM User WHERE email = ?1") Optional getByAuthority(@Param("authority") String authority); @Query("FROM User WHERE token = ?1") Optional getByToken(@Param("token") String token); @Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%)") List searchForUsers(@Param("query") String query); @Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2") List searchForUsers(@Param("query") String query, @Param("role") UserRoles role); }