Line data Source code
1 4 : (ns schemas.domain.group-participants
2 : (:require
3 : [malli.core :as m]
4 : [malli.error :as me]))
5 :
6 :
7 4 : (def GroupParticipantRecordSchema
8 28 : [:map {:swagger/title "GroupParticipantRecord"
9 : :swagger/description "Complete group participant record from database"}
10 20 : [:uuid [:ref :types/UuidString]]
11 20 : [:group-id [:ref :types/UuidString]]
12 20 : [:participant-id {:optional true}
13 20 : [:maybe [:ref :types/UuidString]]]
14 24 : [:created-datetime {:optional true}
15 : :any]
16 8 : [:status
17 28 : [:string {:description "Participant status in group"
18 : :example "active"}]]
19 20 : [:slot {:optional true}
20 12 : [:maybe :int]]
21 20 : [:source [:ref :matchscore/source]]])
22 :
23 :
24 4 : (defrecord
25 : GroupParticipantRecord
26 : [uuid group-id participant-id created-datetime status slot source])
27 :
28 :
29 4 : (defn make-group-participant-record
30 : "Creates a GroupParticipant record with validation.
31 : Note: This validation uses the default registry. Ensure schemas.registry/init-registry!
32 : has been called before using this function."
33 : {:malli/schema [:=> [:cat GroupParticipantRecordSchema] GroupParticipantRecordSchema]}
34 : [{:keys [uuid group-id participant-id created-datetime status slot source]
35 : :as group-participant-data}]
36 20 : (if (m/validate GroupParticipantRecordSchema group-participant-data)
37 8 : (map->GroupParticipantRecord
38 36 : {:uuid uuid
39 4 : :group-id group-id
40 4 : :participant-id participant-id
41 4 : :created-datetime created-datetime
42 4 : :status status
43 4 : :slot slot
44 4 : :source source})
45 0 : (throw
46 0 : (ex-info
47 : "Invalid group participant data"
48 0 : {:type :internal-validation-error
49 0 : :schema GroupParticipantRecordSchema
50 0 : :data group-participant-data
51 0 : :humanized-errors (me/humanize
52 0 : (m/explain GroupParticipantRecordSchema group-participant-data))}))))
|