Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add API as well to enable / disable #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-player-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-player-sql
[active? user-id]
(-> (h/update :user)
(h/sset [[:active active?]])
(h/where [:= :id user-id])))

(def disable-player-sql (partial toggle-player-sql false))
(def enable-player-sql (partial toggle-player-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