From e44639ae8516382492ae0e61d83794bcc7c2f61f Mon Sep 17 00:00:00 2001 From: Ivan Grishaev Date: Wed, 27 Dec 2017 18:20:24 +0300 Subject: [PATCH] 193 server handler added --- src/clj/commiteth/db/core.clj | 8 ++++++++ src/clj/commiteth/routes/services.clj | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/clj/commiteth/db/core.clj b/src/clj/commiteth/db/core.clj index 162c418..0742d6b 100644 --- a/src/clj/commiteth/db/core.clj +++ b/src/clj/commiteth/db/core.clj @@ -90,3 +90,11 @@ (sql-value [value] (to-pg-json value)) IPersistentVector (sql-value [value] (to-pg-json value))) + +(defmacro with-trx [& body] + "Performs a set of queries in transaction." + `(conman/with-transaction [*db*] + ~@body)) + +(defn update! [& args] + (apply jdbc/update! *db* args)) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 82c5633..fb35a92 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -5,6 +5,7 @@ [compojure.api.meta :refer [restructure-param]] [buddy.auth.accessrules :refer [restrict]] [buddy.auth :refer [authenticated?]] + [commiteth.db.core :as db] [commiteth.db.users :as users] [commiteth.db.usage-metrics :as usage-metrics] [commiteth.db.repositories :as repositories] @@ -234,6 +235,15 @@ (if (= 1 result) (ok) (internal-server-error))))) + + (POST "/hidden" [] + :auth-rules authenticated? + :body-params [user-id :- Long, hidden :- Boolean] + :summary "(Un)mark a user as being hidden (not visible in rating tables)." + (db/with-trx + (db/update! :users {:is_hidden hidden} ["id = ?" user-id])) + (ok)) + (GET "/repositories" {:keys [params]} :auth-rules authenticated? :current-user user