feat(grfn/bbbg): Add a skeleton event page

Change-Id: Id056a7d5bf21c34317957a75e7a91ed42f55a939
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4510
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-19 20:40:33 -05:00 committed by clbot
parent 9ea538beea
commit b05a1d1e05
3 changed files with 55 additions and 4 deletions

View file

@ -3,6 +3,7 @@
[bbbg.attendee :as attendee]
[bbbg.db :as db]
[bbbg.event :as event]
[bbbg.util.sql :refer [count-where]]
[honeysql.helpers :refer [merge-group-by merge-left-join merge-select]]
[java-time :refer [local-date]]))
@ -38,6 +39,15 @@
(merge-select :%count.event_attendee.attendee_id)
(merge-group-by :event.id :event_attendee.event-id)))
(defn with-stats
[query]
(-> query
(merge-left-join :event_attendee [:= :event.id :event_attendee.event-id])
(merge-select
[(count-where :event-attendee.rsvpd_attending) :num-rsvps]
[(count-where :event-attendee.attended) :num-attendees])
(merge-group-by :event.id)))
(comment
(def db (:db bbbg.core/system))
(db/list db (-> (today) (with-attendee-counts)))

View file

@ -3,10 +3,14 @@
[bbbg.db :as db]
[bbbg.db.event :as db.event]
[bbbg.event :as event]
[bbbg.handlers.core :refer [page-response authenticated? wrap-auth-required]]
[bbbg.handlers.core :refer [authenticated? page-response]]
[bbbg.util.display :refer [format-date]]
[bbbg.views.flash :as flash]
[compojure.coercions :refer [as-uuid]]
[compojure.core :refer [context GET POST]]
[ring.util.response :refer [redirect]]
[bbbg.views.flash :as flash]))
[java-time :refer [local-date]]
[ring.util.response :refer [not-found redirect]]
[bbbg.util.time :as t]))
(defn events-index [{:keys [events authenticated?]}]
[:div
@ -15,7 +19,22 @@
"Create New Event"])
[:ul.events-list
(for [event events]
[:li (::event/date event)])]])
[:li
[:a {:href (str "/events/" (::event/id event))}
(format-date (::event/date event))]])]])
(defn event-page [{:keys [event]}]
[:div.event-page
[:h1 (format-date (::event/date event))]
[:div.stats
[:p (:num-rsvps event) " RSVP"
(when-not (= 1 (:num-rsvps event)) "s")]
[:p (:num-attendees event)
(if (= (t/->LocalDate (::event/date event))
(local-date))
" Signed In"
(str " Attendee" (when-not (= 1 (:num-attendees event)) "s")))]
]])
(defn event-form
([] (event-form {}))
@ -39,6 +58,16 @@
(events-index {:events events
:authenticated? (authenticated? request)}))))
(GET "/:id" [id :<< as-uuid]
(if-let [event (db/fetch db
(-> {:select [:event.*]
:from [:event]
:where [:= :event.id id]}
(db.event/with-stats)))]
(page-response
(event-page {:event event}))
(not-found "Event Not Found")))
(GET "/new" [date]
(page-response
{:title "New Event"}
@ -50,3 +79,12 @@
redirect
(flash/add-flash {:flash/type :success
:flash/message "Event Created"}))))))
(comment
(def db (:db bbbg.core/system))
(-> (db/list db :event)
first
::event/date
format-date)
)

View file

@ -58,6 +58,9 @@
LocalDate
(->LocalDate [ld] ld)
java.sql.Date
(->LocalDate [sd] (.toLocalDate sd))
java.util.Date
(->LocalDate [d]
(-> d .toInstant (LocalDate/ofInstant (ZoneId/of "UTC")))))