diff options
Diffstat (limited to 'users/grfn/bbbg/src/bbbg/handlers/events.clj')
-rw-r--r-- | users/grfn/bbbg/src/bbbg/handlers/events.clj | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/events.clj b/users/grfn/bbbg/src/bbbg/handlers/events.clj index 478cc6b050c4..dd50a517cceb 100644 --- a/users/grfn/bbbg/src/bbbg/handlers/events.clj +++ b/users/grfn/bbbg/src/bbbg/handlers/events.clj @@ -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) + ) |