diff --git a/dev-resources/test-0.0.3-SNAPSHOT/test.pom b/dev-resources/test-0.0.3-SNAPSHOT/test.pom index 807742ec..bfdf3431 100644 --- a/dev-resources/test-0.0.3-SNAPSHOT/test.pom +++ b/dev-resources/test-0.0.3-SNAPSHOT/test.pom @@ -6,14 +6,52 @@ test 0.0.3-SNAPSHOT jar - asdf + asdf TEST http://example.com UTF-8 + + + + + Noelle + some.name@gmail.com + http://noellemarie.com + Noelle Marie + http://noellemarie.com + + tester + + America/Vancouver + + some.name@gmail.com + + + + + + juherr + Julien Herr + julien@herr.fr + + + flgourie + Florian Gourier + florian.gourier@gmail.com + + + + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + scm:git:git://github.com/fake/test.git scm:git:ssh://git@github.com/fake/test.git diff --git a/resources/queries/queryfile.sql b/resources/queries/queryfile.sql index ca01ef0d..a2e286f2 100644 --- a/resources/queries/queryfile.sql +++ b/resources/queries/queryfile.sql @@ -436,8 +436,16 @@ SET token_hash = :token_hash WHERE id = :token_id AND token_hash IS NULL --name: find-groups-jars-information -SELECT j.jar_name, j.group_name, homepage, description, "user", - j.version AS latest_version, r2.version AS latest_release +SELECT j.jar_name, + j.group_name, + j.scm, + j.authors, + licenses, + homepage, + description, + "user", + j.version AS latest_version, + r2.version AS latest_release FROM jars j -- Find the latest version JOIN (SELECT jar_name, group_name, MAX(created) AS created @@ -466,8 +474,16 @@ WHERE j.group_name = :group_id ORDER BY j.group_name ASC, j.jar_name ASC; --name: find-jars-information -SELECT j.jar_name, j.group_name, homepage, description, "user", - j.version AS latest_version, r2.version AS latest_release +SELECT j.jar_name, + j.group_name, + j.scm, + j.authors, + licenses, + homepage, + description, + "user", + j.version AS latest_version, + r2.version AS latest_release FROM jars j -- Find the latest version JOIN (SELECT jar_name, group_name, MAX(created) AS created diff --git a/src/clojars/routes/api.clj b/src/clojars/routes/api.clj index 32d29285..0f296d78 100644 --- a/src/clojars/routes/api.clj +++ b/src/clojars/routes/api.clj @@ -3,48 +3,65 @@ [db :as db] [stats :as stats] [http-utils :refer [wrap-cors-headers]]] + [clojure.edn :as edn] [compojure [core :as compojure :refer [ANY context GET]] [route :refer [not-found]]] [ring.middleware.format-response :refer [wrap-restful-response]] [ring.util.response :refer [response]])) +(defn hyrdate-artifact + [db stats group-id artifact-id artifact] + (-> artifact + (update :scm edn/read-string) + (update :licenses edn/read-string) + (update-in [:recent_versions] + (fn [versions] + (map (fn [version] + (assoc version + :downloads (stats/download-count stats group-id artifact-id (:version version)))) + versions))) + response)) + +(defn hyrdate-artifact-stats + [artifact]) + +(comment + (fn [artifact] + (assoc + artifact + :recent_versions (db/recent-versions db group-id artifact-id) + :downloads (stats/download-count stats group-id artifact-id))) + + (-> artifact + (hyrdate-artifact db stats group-id artifact-id artifact))) + (defn get-artifact [db stats group-id artifact-id] (if-let [artifact (first (db/find-jars-information db group-id artifact-id))] - (-> artifact - (assoc - :recent_versions (db/recent-versions db group-id artifact-id) - :downloads (stats/download-count stats group-id artifact-id)) - (update-in [:recent_versions] - (fn [versions] - (map (fn [version] - (assoc version - :downloads (stats/download-count stats group-id artifact-id (:version version)))) - versions))) - response) + (response artifact) (not-found nil))) (defn handler [db stats] (compojure/routes (context "/api" [] - (GET ["/groups/:group-id", :group-id #"[^/]+"] [group-id] - (if-let [jars (seq (db/find-jars-information db group-id))] - (response - (map (fn [jar] - (assoc jar - :downloads (stats/download-count stats group-id (:jar_name jar)))) - jars)) - (not-found nil))) - (GET ["/artifacts/:artifact-id", :artifact-id #"[^/]+"] [artifact-id] - (get-artifact db stats artifact-id artifact-id)) - (GET ["/artifacts/:group-id/:artifact-id", :group-id #"[^/]+", :artifact-id #"[^/]+"] [group-id artifact-id] - (get-artifact db stats group-id artifact-id)) - (GET "/users/:username" [username] - (if-let [groups (seq (db/find-groupnames db username))] - (response {:groups groups}) - (not-found nil))) - (ANY "*" _ - (not-found nil))))) + (GET ["/groups/:group-id", :group-id #"[^/]+"] [group-id] + (if-let [jars (seq (db/find-jars-information db group-id))] + (response + (map (fn [jar] + (assoc jar + :downloads (stats/download-count stats group-id (:jar_name jar)))) + jars)) + (not-found nil))) + (GET ["/artifacts/:artifact-id", :artifact-id #"[^/]+"] [artifact-id] + (get-artifact db stats artifact-id artifact-id)) + (GET ["/artifacts/:group-id/:artifact-id", :group-id #"[^/]+", :artifact-id #"[^/]+"] [group-id artifact-id] + (get-artifact db stats group-id artifact-id)) + (GET "/users/:username" [username] + (if-let [groups (seq (db/find-groupnames db username))] + (response {:groups groups}) + (not-found nil))) + (ANY "*" _ + (not-found nil))))) (defn routes [db stats] (-> (handler db stats) diff --git a/test/clojars/integration/api_test.clj b/test/clojars/integration/api_test.clj index 64c7a690..99129d98 100644 --- a/test/clojars/integration/api_test.clj +++ b/test/clojars/integration/api_test.clj @@ -51,6 +51,7 @@ (testing "list group artifacts" (let [resp (get-api [:groups "org.clojars.dantheman"] {:accept :json}) body (json/parse-string (:body resp) true)] + (is (= {:latest_version "0.0.3-SNAPSHOT" :latest_release "0.0.2" :jar_name "test" @@ -70,6 +71,8 @@ (is (= {:latest_version "0.0.3-SNAPSHOT" :latest_release "0.0.2" :jar_name "test" + :license "" + :scm_url "" :group_name "org.clojars.dantheman" :user "dantheman" :description "TEST"