Created
April 10, 2012 13:34
-
-
Save dmozzy/2351409 to your computer and use it in GitHub Desktop.
Blog #3 Task persistence changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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