about summary refs log tree commit diff
path: root/users/grfn/bbbg/src
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/bbbg/src')
-rw-r--r--users/grfn/bbbg/src/bbbg/db/event.clj10
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/events.clj46
-rw-r--r--users/grfn/bbbg/src/bbbg/util/time.clj3
3 files changed, 55 insertions, 4 deletions
diff --git a/users/grfn/bbbg/src/bbbg/db/event.clj b/users/grfn/bbbg/src/bbbg/db/event.clj
index 0fd0e3ec0795..41716499db03 100644
--- a/users/grfn/bbbg/src/bbbg/db/event.clj
+++ b/users/grfn/bbbg/src/bbbg/db/event.clj
@@ -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)))
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)
+  )
diff --git a/users/grfn/bbbg/src/bbbg/util/time.clj b/users/grfn/bbbg/src/bbbg/util/time.clj
index 46506fe32b51..0278f89f5edd 100644
--- a/users/grfn/bbbg/src/bbbg/util/time.clj
+++ b/users/grfn/bbbg/src/bbbg/util/time.clj
@@ -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")))))