Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit a9e6b70

Browse files
committed
augment course with tags from resources
1 parent a5de6b0 commit a9e6b70

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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))

functions/src/app/augment/index.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
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)
@@ -14,5 +15,6 @@
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))))

functions/src/app/augment/mappings.cljs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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]
@@ -22,11 +23,16 @@
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}))

functions/src/app/augment/specs.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
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))))

0 commit comments

Comments
 (0)