Line data Source code
1 4 : (ns matchscore.application.group-participants.helpers
2 : (:require
3 : [cats.monad.either :as either]
4 : [matchscore.domain.draw.repository.postgres :as draw-postgres-repo]
5 : [matchscore.domain.group.repository.postgres :as group-postgres-repo]
6 : [matchscore.domain.stage.repository.postgres :as stage-postgres-repo]
7 : [matchscore.utils.errors :as utils.errors]))
8 :
9 :
10 4 : (defn find-group-or-fail
11 : [repos group-uuid draw-uuid]
12 7 : (let [group (group-postgres-repo/find-by-id (:group-postgres-repo repos) group-uuid)]
13 7 : (cond (nil? group)
14 2 : (either/left
15 3 : (utils.errors/build-error
16 : :check
17 5 : {:code :error.group/not-found
18 : :message "Group not found."}))
19 :
20 6 : (not= draw-uuid (:draw-id group))
21 2 : (either/left
22 3 : (utils.errors/build-error
23 : :check
24 5 : {:code :error.group/not-found
25 : :message "Group not found."}))
26 :
27 3 : :else (either/right group))))
28 :
29 :
30 4 : (defn find-draw-or-fail
31 : [repos draw-uuid]
32 14 : (let [draw (draw-postgres-repo/find-by-id (:draw-postgres-repo repos) draw-uuid)]
33 4 : (if draw
34 6 : (either/right draw)
35 2 : (either/left
36 3 : (utils.errors/build-error
37 : :check
38 5 : {:code :error.draw/not-found
39 : :message "Draw not found."})))))
40 :
41 :
42 4 : (defn find-stage-or-fail
43 : [repos stage-uuid]
44 14 : (let [stage (stage-postgres-repo/find-by-id (:stage-postgres-repo repos) stage-uuid)]
45 4 : (if stage
46 6 : (either/right stage)
47 2 : (either/left
48 3 : (utils.errors/build-error
49 : :check
50 5 : {:code :error.stage/not-found
51 : :message "Stage not found."})))))
|