-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRepository.java
More file actions
29 lines (20 loc) · 1.08 KB
/
UserRepository.java
File metadata and controls
29 lines (20 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.ecommerce.user.repository;
import com.ecommerce.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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;
import java.util.Optional;
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsername(String username);
Optional<User> findByEmail(String email);
boolean existsByUsername(String username);
boolean existsByEmail(String email);
@Query("SELECT u FROM User u WHERE u.status = :status")
Page<User> findByStatus(@Param("status") User.UserStatus status, Pageable pageable);
@Query("SELECT u FROM User u WHERE u.firstName LIKE %:keyword% OR u.lastName LIKE %:keyword% OR u.email LIKE %:keyword%")
Page<User> searchUsers(@Param("keyword") String keyword, Pageable pageable);
}