|
1 | | -;; [[file:~/github/intermediate-clojure-workshop/content/web/core.org::*The%20Preamble][The Preamble:1]] |
2 | 1 | (ns icw.web.core
|
3 | 2 | (:require [compojure.core :as c]
|
4 | 3 | [aleph.http :as http]
|
5 | 4 | [ring.middleware
|
6 | 5 | [keyword-params :refer [wrap-keyword-params]]
|
7 | 6 | [params :refer [wrap-params]]
|
8 | 7 | [json :refer [wrap-json-response]]]
|
| 8 | + [icw.web.handlers.albums :as albums] |
9 | 9 | [icw.search.core :as search]))
|
10 | 10 |
|
11 | 11 | (defn wrap-body [response-body]
|
12 | 12 | {:status 200
|
13 | 13 | :body response-body})
|
14 | | -;; The Preamble:1 ends here |
15 | 14 |
|
16 | | -;; [[file:~/github/intermediate-clojure-workshop/content/web/core.org::*The%20Albums%20Context][The Albums Context:1]] |
17 | 15 | (def albums-context
|
18 | 16 | (c/context "/albums" [:as request]
|
19 | 17 | (c/GET "/" []
|
20 | 18 | (wrap-body
|
21 | | - {:message"Here be your JSON-ful of albums"})) |
| 19 | + (albums/list-albums))) |
22 | 20 | (c/GET "/:id" [id]
|
23 | 21 | (wrap-body {:message (str "Here be your JSON of an album with id " id)}))))
|
24 | | -;; The Albums Context:1 ends here |
25 | 22 |
|
26 | | -;; [[file:~/github/intermediate-clojure-workshop/content/web/core.org::*The%20Search%20Context][The Search Context:1]] |
27 | 23 | (def search-context
|
28 | 24 | (c/context "/search" [:as request]
|
29 | 25 | (c/GET "/:term" [term]
|
|
32 | 28 | (or
|
33 | 29 | (search/search (keyword field) term)
|
34 | 30 | (wrap-body {:message (str "Looking for " term " in field " field ", eh?")}))))))
|
35 | | -;; The Search Context:1 ends here |
36 | 31 |
|
37 | | -;; [[file:~/github/intermediate-clojure-workshop/content/web/core.org::*Tying%20Together][Tying Together:1]] |
38 | 32 | (c/defroutes app*
|
39 | | - albums-context |
40 | | - search-context) |
| 33 | + albums-context |
| 34 | + search-context) |
41 | 35 |
|
42 | 36 | (def app
|
43 | 37 | (c/routes
|
|
0 commit comments