backend/buisnesslogic/src/main/java/com/plannaplan/repositories/UserRepository.java

74 lines
2.4 KiB
Java
Raw Normal View History

2020-07-25 10:38:19 +02:00
package com.plannaplan.repositories;
2020-10-19 12:13:02 +02:00
import java.util.List;
import java.util.Optional;
2020-07-25 10:38:19 +02:00
import com.plannaplan.entities.User;
2020-10-19 12:13:02 +02:00
import com.plannaplan.types.UserRoles;
2020-07-25 10:38:19 +02:00
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
2020-07-25 10:38:19 +02:00
import org.springframework.stereotype.Repository;
/**
2020-12-18 15:24:01 +01:00
* UserRepository.getByAuthority: Return list of: SELECT * FROM User WHERE email
* = i.
*
2020-12-18 15:24:01 +01:00
* Where i, ?1 are equale to variables.
*
2020-12-18 15:24:01 +01:00
* UserRepository.getByToken: Return list of: SELECT * FROM User WHERE token =
* i.
*
2020-12-18 15:24:01 +01:00
* Where i, ?1 are equale to variables.
*
2020-12-18 15:24:01 +01:00
* UserRepository.searchForUsers: Return list of: SELECT * FROM User WHERE (name
* LIKE %?1% OR surname LIKE %?1%).
*
2020-12-18 15:24:01 +01:00
* Where i, ?1 are equale to variables.
*
2020-12-18 15:24:01 +01:00
* UserRepository.searchForUsers with role: Return list of: SELECT * FROM User
* WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
*
2020-12-18 15:24:01 +01:00
* Where i, ?1 are equale to variables.
*/
2020-07-25 10:38:19 +02:00
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
@Query("FROM User WHERE email = ?1 OR usosId = ?1")
/**
* return user by given authority
*
* @param authority user usosId or email
* @return optional with user if found
*/
Optional<User> getByAuthority(@Param("authority") String authority);
2020-09-14 14:02:05 +02:00
@Query("FROM User WHERE email = ?1")
Optional<User> getByEmail(@Param("authority") String authority);
2020-12-23 11:51:17 +01:00
@Query("FROM User WHERE refreshToken = ?1")
Optional<User> getByRefreshToken(@Param("refreshToken") String refreshToken);
2020-09-14 14:02:05 +02:00
@Query("FROM User WHERE token = ?1")
2020-09-25 17:01:38 +02:00
Optional<User> getByToken(@Param("token") String token);
2020-10-19 12:13:02 +02:00
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%)")
List<User> searchForUsers(@Param("query") String query);
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2")
/**
* search for user with given query
*
* @param query string that will be matched to users name and surname
* @param role limits results by role
* @return list opf results
*/
2020-10-19 12:13:02 +02:00
List<User> searchForUsers(@Param("query") String query, @Param("role") UserRoles role);
2020-12-18 15:24:01 +01:00
@Query("FROM User WHERE role=?1")
List<User> getAllByRole(@Param("role") UserRoles role);
@Query("FROM User WHERE usosId = ?1")
Optional<User> getByUsosId(@Param("usosId") String usosId);
2020-07-25 10:38:19 +02:00
}