-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscriptionRepository.java
More file actions
31 lines (26 loc) · 1.08 KB
/
SubscriptionRepository.java
File metadata and controls
31 lines (26 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
30
31
package tnews.subscription.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import tnews.subscription.entity.Subscription;
import java.util.List;
@Repository
public interface SubscriptionRepository extends JpaRepository<Subscription, Long>, CustomizedSave<Subscription> {
@Query(value = """
SELECT *
FROM subscription s
WHERE
(s.time_interval = 0 AND
(s.last_send IS NULL OR s.last_send <= now() - INTERVAL '1 minute'))
OR
(s.time_interval = 1 AND
(s.last_send IS NULL OR s.last_send <= now() - INTERVAL '1 day'))
OR
(s.time_interval = 2 AND
(s.last_send IS NULL OR s.last_send <= now() - INTERVAL '1 week'))
OR
(s.time_interval = 3 AND
(s.last_send IS NULL OR s.last_send <= now() - INTERVAL '1 month'))
""", nativeQuery = true)
List<Subscription> findValidSubscriptions();
}