Permalink
Browse files

Add see-also functionality to get a list of functions to see.

  • Loading branch information...
1 parent fe9ca7e commit 3d4a8b75d2aa934fb6ec7983cd7e25663e03d8e1 @dakrone dakrone committed Aug 25, 2010
Showing with 44 additions and 0 deletions.
  1. +4 −0 README.markdown
  2. +40 −0 src/cd_wsapi/core.clj
View
@@ -25,6 +25,10 @@ Searching for comments on a function
curl "http://localhost:8080/comments/clojure.contrib.json/read-json"
+Getting the 'see-also' functions
+--------------------------------
+
+ curl "http://localhost:8080/see-also/clojure.test/are"
License
-------
View
@@ -110,6 +110,45 @@
(map format-comment comments))))))}))
+(defn format-function
+ "Given a function, format it for json."
+ [function]
+ (dissoc (into {} function) :id :doc :source :shortdoc))
+
+
+(defn format-see-also
+ "Given an id, format the function to see also."
+ [id]
+ (with-connection db
+ (transaction
+ (when-let [functions (with-query-results
+ rs
+ ["select * from functions where id = ?" (:to_id id)]
+ (doall rs))]
+ (map format-function functions)))))
+
+
+(defn see-also
+ "Return the functions to see 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 [see-also-ids (with-query-results
+ rs
+ ["select to_id from see_alsos where from_id = ?" id]
+ (doall rs))]
+ (map format-see-also see-also-ids))))))}))
+
+
+
(defn app-handler [channel request]
(enqueue-and-close
channel
@@ -119,6 +158,7 @@
["search" ns name] (search ns name)
["search" name] (search name)
["comments" ns name] (get-comments ns name)
+ ["see-also" ns name] (see-also ns name)
[&] default)
request)))

0 comments on commit 3d4a8b7

Please sign in to comment.