Line data Source code
1 4 : (ns matchscore.api.hosts
2 : (:require
3 : [matchscore.db.postgres.host :as host]
4 : [schemas.api.core :as api-schemas]))
5 :
6 :
7 40 : (def HostRequest [:map [:host-user-id [:maybe [:ref :types/UuidString]]]])
8 :
9 :
10 4 : (defn- update-host
11 : [ctx kind id data]
12 11 : (let [result (host/set-host! (:pg ctx) kind id (:host-user-id data))]
13 8 : (if-let [error (:error result)]
14 8 : {:status (if (= error :error.host/not-found) 404 400)
15 4 : :body {:message "The host must be an existing admin."
16 1 : :code error}}
17 4 : {:status 200
18 3 : :body {:data result}})))
19 :
20 :
21 4 : (defn event-host-handler
22 : {:malli/schema [:=> [:cat api-schemas/RingRequest HostRequest] api-schemas/RingResponse]
23 : :malli/parameters {:path api-schemas/EventPathParamsSchema}
24 : :authz {:obj :event
25 : :act :update
26 : :id :route-params/event-uuid}
27 : :summary "Set or clear the event host"}
28 : [{:keys [ctx route-params]} data]
29 8 : (update-host ctx :event (:event-uuid route-params) data))
30 :
31 :
32 4 : (defn template-host-handler
33 : {:malli/schema [:=> [:cat api-schemas/RingRequest HostRequest] api-schemas/RingResponse]
34 : :malli/parameters {:path api-schemas/TemplatePathParamsSchema}
35 : :authz {:obj :template
36 : :act :update
37 : :id :route-params/template-uuid}
38 : :summary "Set or clear the template host"}
39 : [{:keys [ctx route-params]} data]
40 8 : (update-host ctx :template (:template-uuid route-params) data))
|