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