Skip to content

Instantly share code, notes, and snippets.

@laser
Last active August 29, 2015 14:11
Show Gist options
  • Save laser/678f1c8497a4a3fc1da4 to your computer and use it in GitHub Desktop.
Save laser/678f1c8497a4a3fc1da4 to your computer and use it in GitHub Desktop.
Adding validation
(defn ensure-text-presence
[params]
"Ensure (body :text) is present"
(if (empty? (params :text))
[nil, "Please provide text for your note"]
[params]))
(defn ensure-text-length
"Ensure that the length of the text is between 1 and 140 characters"
[params]
(let [c (count (:text params))]
(if (or (> 1 c) (< 140 c))
[nil, "Please provide text between 1 and 140 characters in length"]
[params])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment