Skip to content

Commit

Permalink
update participate-session (http post handler)
Browse files Browse the repository at this point in the history
  • Loading branch information
humorless committed Jul 23, 2024
1 parent a38b8f5 commit 611608e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
21 changes: 21 additions & 0 deletions repl-sessions/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,24 @@
(db/transact [[:db/retractEntity 17592186045468]]))
(user/conn)

;; Test transact participants

(def req {:identity "ccc"
:path-params {:id "17592186045455"}})
(def session (merge {:session/capacity 14}
(db/entity (parse-long (get-in req [:path-params :id])))))

(let [user-id-str (:identity req)
session-eid (parse-long (get-in req [:path-params :id]))
;; session (db/entity session-eid)
capacity (:session/capacity session)
curr-participants (:session/participants session)]
;;TODO
;; Write some code to handle the case that :db/cas throws exception at race condition
(prn :session-eid session-eid)
(prn :capacity capacity)
(prn :curr-ps curr-participants)
(prn :check (< (count curr-participants) capacity))
(if (< (count curr-participants) capacity)
@(db/transact [[:db/add session-eid :session/participants user-id-str]])
{:html/body "No enough capacity for this session"}))
25 changes: 0 additions & 25 deletions resources/public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -273,29 +273,4 @@ body {
.home-filters button, .home-filters .btn {
font-weight: 400;
flex-grow: 1;
}

.repl-sessions_ornament-poke__my_compo >.title {
color: blue;
}

.repl-sessions_ornament-poke__my_compo >.subtitle {
font-weight: 500;
}

.repl-sessions_ornament-poke__action_button {
color: red;
}

.repl-sessions_ornament-poke__action_button:hover {
color: black;
}

.repl-sessions_ornament-poke__main_button {
color: red;
margin: 1rem;
}

.repl-sessions_ornament-poke__main_button:hover {
color: black;
}
17 changes: 8 additions & 9 deletions src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,17 @@
(if-not (:identity req)
;; FIXME: we should redirect to /sessions/:id/participate after redirect (or
;; similar, depending on what makes sense with htmx)
(util/redirect (oauth/flow-init-url {:redirect-url "/sessions/new"}))
(util/redirect (oauth/flow-init-url {:redirect-url (str "/sessions/" (get-in req [:path-params :id]) "/participate")}))
(do
(let [user-id-str (:identity req)
session (db/entity (parse-long (get-in req [:path-params :id])))
session-eid (:db/id session)
session-eid (parse-long (get-in req [:path-params :id]))
session (db/entity session-eid)
capacity (:session/capacity session)
current-pv (:session/participants session)
next-pv (conj current-pv user-id-str)]
;;TODO
;; Write some code to handle the case that :db/cas throws exception at race condition
(if (< (count current-pv) capacity)
@(db/transact [[:db/cas session-eid :session/participants current-pv next-pv]])
current-participants (:session/participants session)]
(if (< (count current-participants) capacity)
(do
@(db/transact [[:db/add session-eid :session/participants user-id-str]])
{:html/body "success"})
{:html/body "No enough capacity for this session"}))
{:html/body (pr-str (db/entity (parse-long (get-in req [:path-params :id]))))})))

Expand Down

0 comments on commit 611608e

Please sign in to comment.