diff --git a/src/clj/byf/api.clj b/src/clj/byf/api.clj index 61451dc..51f790d 100644 --- a/src/clj/byf/api.clj +++ b/src/clj/byf/api.clj @@ -146,19 +146,31 @@ (some? github-token)) :token github-token}))) +(defn enable-player + [request] + (let [player-id (-> request :params :player-id)] + (db/write! db/enable-user-sql player-id))) + +(defn disable-player + [request] + (let [player-id (-> request :params :player-id)] + (db/write! db/disable-player-sql player-id))) + ;;TODO: add a not found page for everything else? (def routes ["/" {"api/" {"add-player" add-player! - "add-game" add-game! + "add-game" add-game! - "league" get-league - "leagues" get-leagues - "companies" get-companies - "players" get-players - "games" get-games} + "league" get-league + "leagues" get-leagues + "companies" get-companies + "players" get-players + "games" get-games + "enable-player" enable-player + "disable-player" disable-player} "oauth2/github/callback" github-callback - "authenticated" authenticated? + "authenticated" authenticated? ;; quite a crude way to make sure all the other urls actually ;; render to the SPA, letting the routing be handled by diff --git a/src/clj/byf/db.clj b/src/clj/byf/db.clj index f28d9b6..6fb6230 100644 --- a/src/clj/byf/db.clj +++ b/src/clj/byf/db.clj @@ -40,6 +40,15 @@ (h/order-by [:played_at :asc] [:recorded_at :asc]))) +(defn toggle-user-sql + [active? user-id] + (-> (h/update :user) + (h/sset [[:active active?]]) + (h/where [:= :id user-id]))) + +(def disable-user-sql (partial toggle-user-sql false)) +(def enable-user-sql (partial toggle-user-sql true)) + (defn load-players-sql [league-id] (-> (h/select :*) @@ -76,6 +85,11 @@ (jdbc/query (db-spec) (sql/format (apply func args)))) +(defn write! + [func & args] + (jdbc/execute! (db-spec) + (sql/format (apply func args)))) + (defn get-single [func & args] (first (apply query func args)))