From 83f8dc6540b60df7e17a91e5c011d8c5e8b2d349 Mon Sep 17 00:00:00 2001 From: Ivan Willig Date: Sat, 25 Jun 2022 17:58:50 -0400 Subject: [PATCH] WIP, Broken --- dev-resources/test-0.0.3-SNAPSHOT/test.pom | 40 ++++++++++++++++- resources/queries/queryfile.sql | 24 ++++++++-- src/clojars/routes/api.clj | 52 +++++++++++++++------- test/clojars/integration/api_test.clj | 3 ++ 4 files changed, 97 insertions(+), 22 deletions(-) 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 efa1e963..29b19588 100644 --- a/resources/queries/queryfile.sql +++ b/resources/queries/queryfile.sql @@ -417,8 +417,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 @@ -447,8 +455,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..85f2a346 100644 --- a/src/clojars/routes/api.clj +++ b/src/clojars/routes/api.clj @@ -3,25 +3,42 @@ [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] @@ -29,12 +46,13 @@ (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))) + (do (clojure.pprint/pprint jars) + (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] 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"