Skip to content

Commit

Permalink
consider the case that user may sign up the same event multiple times.
Browse files Browse the repository at this point in the history
  • Loading branch information
humorless committed Jul 23, 2024
1 parent bdbde0e commit de8c5ef
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,22 @@
(let [user-id-str (:user/email (:identity req))
session-eid (parse-long (get-in req [:path-params :id]))
session (db/entity session-eid)
participants (:session/participants session)
capacity (:session/capacity session)
signup (:session/signup session)
new-signup (inc signup)]
(if (< signup capacity)
(cond
(contains? participants user-id-str)
{:html/body (str "you have signed up the session: " (:session/title session))}
(< signup capacity)
(do
;;TODO: add try/catch to handle :db/cas
@(db/transact [[:db/cas session-eid :session/signup signup new-signup]
[:db/add session-eid :session/participants user-id-str]])
{:html/body "success"})
{:html/body "successfully signup"})
:else
{:html/body "No enough capacity for this session"}))
{:html/body (pr-str (db/entity (parse-long (get-in req [:path-params :id]))))})))
#_{:html/body (pr-str (db/entity (parse-long (get-in req [:path-params :id]))))})))

(defn routes []
["/sessions"
Expand Down

0 comments on commit de8c5ef

Please sign in to comment.