Skip to content

Instantly share code, notes, and snippets.

@dmozzy
Created April 10, 2012 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmozzy/2351409 to your computer and use it in GitHub Desktop.
Save dmozzy/2351409 to your computer and use it in GitHub Desktop.
Blog #3 Task persistence changes
;Gets a map of locations keyed by the locationId value
(defn get-all-locations-map []
(let [loaded-locations
(get-all-locations)]
(zipmap (map (fn [k] (:locationId k)) loaded-locations) loaded-locations)))
(defn save-task [task-map]
(let [input-id (Integer/parseInt (:taskId task-map))
id (if (= input-id -1) nil input-id)
locationId (:locationId task-map)
]
(ds/save! (Task. id locationId task-map))))
(defn get-all-tasks []
(let [locations
(get-all-locations-map)]
(map
(fn [k]
(let [task-map (:task k)
taskLocationId (:taskLocationId task-map)
location (if (= nil taskLocationId) nil (get locations (Integer/parseInt taskLocationId)))]
(if (= location nil)
task-map
(assoc
task-map
:taskId (ds/key-id k)
:taskLat (:locationLat location)
:taskLng (:locationLng location)))))
(ds/query :kind Task))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment