Skip to content

Commit

Permalink
Add route for retrieving comments for a particular namespace and method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Aug 24, 2010
1 parent 236801e commit fe9ca7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Expand Up @@ -20,6 +20,12 @@ Searching for a function
curl "http://localhost:8080/search/map"
curl "http://localhost:8080/search/clojure.core/map"

Searching for comments on a function
------------------------------------

curl "http://localhost:8080/comments/clojure.contrib.json/read-json"


License
-------

Expand Down
29 changes: 29 additions & 0 deletions src/cd_wsapi/core.clj
Expand Up @@ -84,6 +84,32 @@
(perform-search qv))))


(defn format-comment
"Given a comment, format it for json output."
[c]
(dissoc (into {} c) :subject :parent_id :lft :rgt :id :commentable_id :commentable_type :title))


(defn get-comments
"Return the comments for a given namespace and method."
[ns name]
(fn [n]
{:status 200
:headers {"Content-Type" "application/json"}
:body (encode-to-str
(with-connection db
(transaction
(when-let [id (with-query-results
rs
["select id from functions where ns = ? and name = ?" ns name]
(:id (first (doall rs))))]
(when-let [comments (with-query-results
rs
["select * from comments where comments.commentable_id = ? " id]
(doall rs))]
(map format-comment comments))))))}))


(defn app-handler [channel request]
(enqueue-and-close
channel
Expand All @@ -92,12 +118,15 @@
["examples" ns name] (examples ns name)
["search" ns name] (search ns name)
["search" name] (search name)
["comments" ns name] (get-comments ns name)
[&] default)
request)))


(defn app-wrapper [channel request]
(app-handler channel request))


(comment (def server (start-http-server app-wrapper {:port *server-port*}))


Expand Down

0 comments on commit fe9ca7e

Please sign in to comment.