Skip to content

Commit

Permalink
add API as well to enable / disable
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCrotti committed Jul 15, 2019
1 parent 770c561 commit 3723a79
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/clj/byf/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/clj/byf/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 :*)
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 3723a79

Please sign in to comment.