This repository was archived by the owner on Apr 17, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-5
lines changed
functions/src/app/augment Expand file tree Collapse file tree 4 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 1+ (ns app.augment.implementation
2+ (:require [shared.protocols.loggable :as log]))
3+
4+ ; ; move this logic to course model
5+
6+ (defn augment-checkpoint [{:keys [resource-url] :as checkpoint} tags url]
7+ (if (= resource-url url)
8+ (assoc checkpoint :tags tags)
9+ checkpoint))
10+
11+ (defn augment-checkpoints [course tags-data]
12+ (update-in course [:checkpoints ]
13+ #(map (fn [checkpoint] (apply augment-checkpoint checkpoint tags-data)) %1 )))
14+
15+ (defn augment-course [course tags-data]
16+ (reduce augment-checkpoints course tags-data))
Original file line number Diff line number Diff line change 44 [backend-shared.service.index :as service]
55 [shared.protocols.convertible :as cv]
66 [shared.protocols.queryable :as qa]
7- [cljs.core.async :as async])
7+ [cljs.core.async :as async]
8+ [shared.protocols.actionable :as ac])
89 (:require-macros [cljs.core.async.macros :refer [go]]))
910
1011(def adapters {:db {:table-names {:bookmarks (.. js/process -env -bookmarksTable)
1415 (go
1516 (let [{:keys [event] :as service} (apply service/create specs mappings adapters args)
1617 {:keys [added] :as payload} (cv/to-db-events event)
17- res (async/<! (qa/fetch service added))]
18+ {:keys [found errors]} (async/<! (qa/fetch service added))
19+ res (async/<! (ac/perform service [:transform found]))]
1820 (service/done service res))))
Original file line number Diff line number Diff line change 11(ns app.augment.mappings
22 (:require [backend-shared.service.index :refer [perform fetch]]
3+ [app.augment.implementation :as impl]
34 [shared.protocols.actionable :as ac]
45 [shared.protocols.queryable :as qa]
56 [shared.protocols.loggable :as log]
2223 courses-res (async/<! (qa/fetch db courses-query))
2324 courses (:found courses-res)
2425 errors (mapcat :errors [courses-res bookmarks-res])]
25- {:resources resources
26- :courses courses
27- :bookmarks bookmarks
26+ {:found {:resources resources
27+ :courses courses}
2828 :errors (when-not (empty? errors) errors)})))
2929
30+ (defmethod perform [:transform :motherload ] [_ [_ payload]]
31+ (let [{:keys [resources courses]} payload
32+ tags-data (map #(identity [(:tags %1 ) (:resource-url %1 )]) resources)
33+ ; ; move impl logic to course model
34+ courses (map #(impl/augment-course %1 tags-data) courses)]
35+ (go courses)))
3036
3137 (defmethod perform [:put :nothing ] [_ _]
3238 (go {:error :no-payload }))
Original file line number Diff line number Diff line change 44
55(spec/def :query/course-by-id (spec/keys :req-un [:course/course-id :course/revision ]))
66
7+ (spec/def ::courses (spec/coll-of :offcourse/course ))
8+ (spec/def ::resources (spec/coll-of :offcourse/resource ))
9+ (spec/def ::motherload (spec/keys :req-un [::courses ::resources ]))
10+
711(defn specs []
12+
13+ (defmethod action-spec :transform [_]
14+ (spec/tuple :offcourse/actions (spec/or :motherload ::motherload )))
15+
816 (spec/def :offcourse/query (spec/or :bookmarks (spec/coll-of :query/resource )
917 :courses (spec/coll-of :query/course-by-id )
1018 :errors (spec/coll-of :offcourse/error ))))
You can’t perform that action at this time.
0 commit comments