|
91 | 91 | (defn get-articles-handler [{:keys [model]}]
|
92 | 92 | {:body (reitit-db-fun.model/get-articles model)})
|
93 | 93 |
|
94 |
| -(defn update-article-handler [{:keys [model body-params]}] |
95 |
| - {:body (reitit-db-fun.model/update-article model body-params)}) |
| 94 | +(defn update-article-handler [{:keys [model body-params sente-functions]}] |
| 95 | + (let [datoms (reitit-db-fun.model/update-article model body-params)] |
| 96 | + (sente-fn/send-datoms-to-all-clients sente-functions datoms) |
| 97 | + {:body "Updated"})) |
96 | 98 |
|
97 | 99 | (defn get-app-handler [{:keys [keys-to-wrap sente sente-functions]}]
|
98 | 100 | (ring/ring-handler
|
|
211 | 213 | (jdbc/execute! datasource)
|
212 | 214 | (mapv :user/id))
|
213 | 215 | app (:app/handler @main-system)]
|
214 |
| - (doseq [idx (range 100)] |
| 216 | + (doseq [idx (range 2)] |
215 | 217 | (app {:request-method :post
|
216 | 218 | :uri "/api/article"
|
217 | 219 | :body-params {:article/title (str "Test-" (inc idx))
|
218 | 220 | :article/body (str "Treść artykułu " (inc idx))
|
219 | 221 | :article/author (rand-nth authors)}})))
|
| 222 | + |
220 | 223 | ;; sprawdzam pojedynczy artykuł
|
221 | 224 | (-> ((:app/handler @main-system)
|
222 | 225 | {:request-method :get
|
|
227 | 230 | (-> ((:app/handler @main-system)
|
228 | 231 | {:request-method :post
|
229 | 232 | :uri "/api/article"
|
230 |
| - :body-params {:article/id "3000001" |
231 |
| - :article/title "Title zmieniony ponownie" |
| 233 | + :body-params {:article/id "3000002" |
| 234 | + :article/title "Title zmieniony 2" |
232 | 235 | :article/body "Treść po zmiania"
|
| 236 | + :article/address "2000001" |
233 | 237 | :article/author "pkoza"}})
|
234 | 238 | (update :body slurp))
|
235 | 239 |
|
236 | 240 | ;; wszystkie arty
|
237 | 241 | (-> ((:app/handler @main-system)
|
238 | 242 | {:request-method :get
|
239 |
| - :uri "/api/articles"}) |
240 |
| - :body |
| 243 | + :uri "/api/articles"} |
| 244 | + :body) |
241 | 245 | slurp)
|
242 | 246 |
|
243 | 247 | ;; Baza SQL na Datomy!
|
|
248 | 252 | :from [:article :address :user]
|
249 | 253 | :where [:and
|
250 | 254 | [:= :article/author :user/id]
|
251 |
| - [:= :user/address :address/id]] |
| 255 | + [:= :user/address :address/id] |
| 256 | + ] |
252 | 257 | :limit 20})]
|
253 | 258 | (->> (jdbc/execute! datasource query)
|
254 | 259 | datom/resultset-into-datoms)))
|
| 260 | + |
| 261 | + (let [datasource (:storage/sql @main-system) |
| 262 | + query (sql/format {:select [:article/*] |
| 263 | + :from [:article] |
| 264 | + :where [:= :article/id 3000015] |
| 265 | + :limit 20})] |
| 266 | + (->> (jdbc/execute! datasource query) |
| 267 | + datom/resultset-into-datoms)) |
| 268 | + |
| 269 | + |
| 270 | + |
255 | 271 | ;; Datascript test db
|
256 | 272 | (def test-db (db/init-db (mapv #(apply d/datom %) initial-datoms)))
|
257 | 273 |
|
258 | 274 | (d/q '[:find (pull ?e [* {:article/author [:user/name {:user/address [*]}]}])
|
259 | 275 | :where [?e :article/id _]]
|
260 | 276 | test-db)
|
261 |
| - |
| 277 | + ;; test pojedynczego arta |
262 | 278 |
|
263 | 279 | (do
|
264 | 280 | (stop-system main-system)
|
265 | 281 | (start-system main-system config))
|
266 | 282 |
|
267 | 283 | (-main)
|
268 |
| - |
269 | 284 | )
|
0 commit comments