Line data Source code
1 4 : (ns matchscore.domain.match.query
2 : (:require
3 : [cats.monad.either :as either]
4 : [matchscore.domain.match.repository.postgres :as postgres-repo]))
5 :
6 :
7 4 : (defn get-match
8 : "Retrieves a match by ID. Returns Match map or nil."
9 : [repo id]
10 8 : (postgres-repo/find-by-id repo id))
11 :
12 :
13 4 : (defn get-matches-by-series
14 : "Retrieves all games in a series, ordered by game-number. Returns seq."
15 : [repo series-id]
16 4 : (postgres-repo/find-by-series-id repo series-id))
17 :
18 :
19 4 : (defn get-matches-by-series-ids
20 : "Retrieves all matches for multiple series in one batch. Returns seq."
21 : [repo series-ids]
22 8 : (postgres-repo/find-by-series-ids repo series-ids))
23 :
24 :
25 4 : (defn get-matches-by-group-ids
26 : "Retrieves all matches for multiple groups in one batch. Returns seq."
27 : [repo group-ids]
28 8 : (postgres-repo/find-by-group-ids repo group-ids))
29 :
30 :
31 4 : (defn get-matches-by-group
32 : "Retrieves all matches in a group. Returns seq."
33 : [repo group-id]
34 0 : (postgres-repo/find-by-group-id repo group-id))
35 :
36 :
37 4 : (defn get-matches-by-bracket-match
38 : "Retrieves matches for a bracket match slot. Returns seq."
39 : [repo bracket-match-id]
40 0 : (postgres-repo/find-by-bracket-match-id repo bracket-match-id))
41 :
42 :
43 4 : (defn get-matches-by-bracket-match-ids
44 : "Retrieves matches for multiple bracket matches in one batch. Returns seq."
45 : [repo bracket-match-ids]
46 4 : (postgres-repo/find-by-bracket-match-ids repo bracket-match-ids))
47 :
48 :
49 4 : (defn search-matches
50 : "Search matches by filters and pagination. Returns paginated result."
51 : [repo filters pagination]
52 5 : (postgres-repo/search repo filters pagination))
53 :
54 :
55 4 : (defn search-user-matches
56 : "Search matches where the authenticated user participates (home or away).
57 : Forces participation through participants.user_id.
58 : Returns Either<Error, Result>."
59 : [repo user-id filters pagination]
60 4 : (if (seq user-id)
61 2 : (either/right
62 13 : (postgres-repo/search repo (assoc (or filters {}) :participating-user-id user-id) pagination))
63 2 : (either/left
64 5 : {:code :error.match/authentication-required
65 : :message "Authentication required."})))
|