29 lines
989 B
Clojure
29 lines
989 B
Clojure
(ns auto-ap.entities.companies
|
|
(:require [clojure.spec.alpha :as s]
|
|
[auto-ap.entities.shared :as shared]
|
|
[clojure.string :as str]
|
|
[auto-ap.entities.address :as address]))
|
|
|
|
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
|
|
(s/def ::id int)
|
|
|
|
(s/def ::name ::shared/required-identifier)
|
|
(s/def ::address ::address/address)
|
|
|
|
(s/def ::location string?)
|
|
(s/def ::locations (s/coll-of ::location))
|
|
|
|
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
|
:is-empty #(= % "")))))
|
|
|
|
|
|
(s/def ::company (s/keys :req-un [::name]
|
|
:opt-un [::email
|
|
::address
|
|
::locations
|
|
::id]))
|
|
|
|
|
|
(def company-spec (apply hash-map (drop 1 (s/form ::company))))
|
|
(def all-keys (map #(keyword (name %)) (concat (:req-un company-spec) (:opt-un company-spec))))
|