Line data Source code
1 4 : (ns matchscore.domain.club.query
2 : (:require
3 : [matchscore.domain.club.repository.postgres :as club-postgres-repo]
4 : [matchscore.domain.club.repository.redis :as redis-repo]
5 : [taoensso.telemere :as t]))
6 :
7 :
8 4 : (defn get-club
9 : "Retrieves a club by ID. Returns Club map or nil."
10 : [repo id]
11 8 : (club-postgres-repo/find-by-id repo id))
12 :
13 :
14 4 : (defn get-clubs
15 : "Retrieves all active clubs. Tries Redis cache first, falls back to Postgres."
16 : [repo redis]
17 40 : (if-some [cached (when redis (redis-repo/get-all-cached redis))]
18 2 : cached
19 12 : (let [clubs (club-postgres-repo/get-all repo)]
20 28 : (when (and redis (seq clubs))
21 12 : (redis-repo/cache-all! redis clubs)
22 66 : (t/log! :debug "Cached clubs to Redis"))
23 3 : clubs)))
24 :
25 :
26 4 : (defn get-clubs-admin
27 : "Retrieves all clubs including inactive (soft-deleted) ones. Admin use only;
28 : bypasses the Redis cache (which only holds active clubs)."
29 : [repo]
30 3 : (club-postgres-repo/get-all-admin repo))
31 :
32 :
33 4 : (defn search-clubs
34 : "Search clubs by filters and pagination. Returns paginated result."
35 : [repo filters pagination]
36 15 : (club-postgres-repo/search repo filters pagination))
|