Skip to content

Commit

Permalink
backend: defscalar int_string
Browse files Browse the repository at this point in the history
Using `defscalar` fixes introspection errors.

Be aware, that UNION types are not implemented till now:
ajk/specialist-server#3

Also `->Int` was moved from an explicit mapping postprocessing function
into the conformer.
  • Loading branch information
johannesloetzsch committed Mar 12, 2022
1 parent b851df5 commit c7fc8b2
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions backend/src/beherbergung/resolver/root/ngo/get_offers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@
(defn JaNein->bool [JaNein]
({"Ja" true "Nein" false} JaNein))

(defn ->Int
"If unable to parse, we return the original string (requires union datatype)"
[s]
(try
(Integer/parseInt s)
(catch NumberFormatException _e s)))

(def mapping_lifeline_wpforms {:id #(or (get % "E-Mail") (get % "Telefonnummer")) ;; TODO: uuid will be generated when record is written to db

:time_from_str "frühestes Einzugsdatum"
:time_duration_str "Möglicher Aufenthalt (Dauer)" ;; TODO: the duration is not parsed till now

:beds ["Verfügbare Betten" ->Int]
:beds "Verfügbare Betten"
:languages ["Sprachen (sprechen / verstehen)" #(split % #"\n")]

:place_country "Land"
Expand Down Expand Up @@ -60,10 +53,23 @@
(into {}))))]
(map (mapping->fn mapping) offers)))

(t/defscalar int_string
{:name "Int" :description "Integer or String"}
;; TODO: Here we should be able to use s/with-gen
(fn [v]
(cond
(number? v)
(int v)
(string? v)
(try
(Integer/parseInt v)
(catch NumberFormatException _e v))
:else
::s/invalid)))

(s/def ::t_boolean t/boolean #_ (s/with-gen t/boolean #(s/gen boolean?)))
(s/def ::t_string t/string #_ (s/with-gen t/string #(s/gen string?)))
(s/def ::t_int_string (s/or :int t/int
:string t/string) #_ (s/with-gen t/int #(s/gen int?)))
(s/def ::t_int_string int_string #_ (s/with-gen t/int #(s/gen int?)))

(s/def :xtdb.api/id (s/nilable ::t_string)) ;; TODO: in future not nilable
(s/def ::time_from_str (s/nilable ::t_string))
Expand Down

0 comments on commit c7fc8b2

Please sign in to comment.