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

Commit fcad308

Browse files
committed
wip: change dynamodb from getItem to query api
1 parent 6f8e2be commit fcad308

File tree

8 files changed

+61
-3
lines changed

8 files changed

+61
-3
lines changed

functions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports.split = db_out.app.core.split;
99
exports.retrieve = db_out.app.core.retrieve;
1010
exports.save = db_out.app.core.save;
1111
exports.index = db_out.app.core.index;
12+
exports.augment = db_out.app.core.augment;
1213
exports.debug = db_out.app.core.debug;
1314
exports.dump = db_out.app.core.dump;
1415
exports.combine = db_out.app.core.combine;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns app.augment.index
2+
(:require [app.augment.mappings :refer [mappings]]
3+
[app.augment.specs :refer [specs]]
4+
[backend-shared.service.index :as service]
5+
[shared.protocols.convertible :as cv]
6+
[shared.protocols.queryable :as qa]
7+
[cljs.core.async :as async])
8+
(:require-macros [cljs.core.async.macros :refer [go]]))
9+
10+
(def adapters {:db {:table-names {:bookmarks (.. js/process -env -bookmarksTable)}}})
11+
12+
(defn augment [& args]
13+
(go
14+
(let [{:keys [event] :as service} (apply service/create specs mappings adapters args)
15+
{:keys [added] :as payload} (cv/to-db-events event)
16+
res (async/<! (qa/fetch service added))]
17+
(service/done service res))))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns app.augment.mappings
2+
(:require [backend-shared.service.index :refer [perform fetch]]
3+
[shared.protocols.actionable :as ac]
4+
[shared.protocols.queryable :as qa]
5+
[shared.protocols.loggable :as log])
6+
(:require-macros [cljs.core.async.macros :refer [go]]))
7+
8+
(defn mappings []
9+
10+
(defmethod fetch :bookmarks [{:keys [db]} payload]
11+
(let [query (map (fn [{:keys [bookmark-url]}] {:resource-url bookmark-url}) payload)]
12+
(qa/fetch db query)))
13+
14+
(defmethod perform [:put :nothing] [_ _]
15+
(go {:error :no-payload}))
16+
17+
(defmethod perform [:put :errors] [_ [_ errors]]
18+
(go errors))
19+
20+
(defmethod perform :default [{:keys [bucket]} action]
21+
(ac/perform bucket action)))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(ns app.augment.specs
2+
(:require [cljs.spec :as spec]
3+
[shared.specs.action :as action :refer [action-spec]]))
4+
5+
(spec/def ::resource-url :base/url)
6+
(spec/def :query/bookmark (spec/keys :req-un [::resource-url]))
7+
8+
(defn specs []
9+
(spec/def :offcourse/query (spec/or :bookmarks (spec/coll-of :query/resource)
10+
:errors (spec/coll-of :offcourse/error))))

functions/src/app/authorize/mappings.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
[shared.protocols.actionable :as ac]
44
[shared.protocols.convertible :as cv]
55
[shared.protocols.queryable :as qa]
6-
[shared.protocols.loggable :as log])
6+
[shared.protocols.loggable :as log]
7+
[cljs.core.async :as async])
78
(:require-macros [cljs.core.async.macros :refer [go]]))
89

910
(defn mappings []
1011

11-
(defmethod fetch :identity [{:keys [db]} query]
12+
(defmethod fetch :identity [{:keys [db table-names]} query]
1213
(qa/fetch db query))
1314

1415
(defmethod fetch :error [{:keys [db]} error]

functions/src/app/core.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[backend-shared.index]
55
[app.query.index :as query]
66
[app.transform.index :as transform]
7+
[app.augment.index :as augment]
78
[app.command.index :as command]
89
[app.retrieve.index :as retrieve]
910
[app.index.index :as index]
@@ -21,6 +22,7 @@
2122
(def ^:export download download/download)
2223
(def ^:export save save/save)
2324
(def ^:export index index/index)
25+
(def ^:export augment augment/augment)
2426
(def ^:export debug debug/debug)
2527
(def ^:export retrieve retrieve/retrieve)
2628

functions/src/app/query/mappings.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
(handle-request index query true))
2424

2525
(defmethod fetch :resource [{:keys [db stage]} query]
26-
(go (async/<! (qa/fetch db query)))))
26+
(qa/fetch db query)))

serverless.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ provider:
1111
- dynamodb:GetItem
1212
- dynamodb:BatchGetItem
1313
- dynamodb:PutItem
14+
- dynamodb:query
1415
- dynamodb:Scan
1516
- s3:PutObject
1617
- s3:GetObject
@@ -43,6 +44,11 @@ functions:
4344
integration: lambda
4445
authorizer: authorize
4546

47+
augment:
48+
handler: functions/index.augment
49+
environment:
50+
bookmarksTable: "bookmarks-${opt:stage}"
51+
4652
query:
4753
handler: functions/index.query
4854
environment:

0 commit comments

Comments
 (0)