about summary refs log tree commit diff
path: root/users/grfn/bbbg
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-12-19T17·21-0500
committerclbot <clbot@tvl.fyi>2021-12-19T17·24+0000
commit9af35bd683228f2c039e1dd39cde3f72749bd112 (patch)
treed6e83b6c0d0faa121a4cdb6d347084a2ae887b13 /users/grfn/bbbg
parenteea2dbadd0d38bc017d1fc3fe7b71ac38b6e4bea (diff)
feat(grfn/bbbg): Add an attendees list r/3308
Add a list of attendees visible only to authenticated users, with stats
about rsvps, events attended, and no-shows.

Change-Id: Ib9a0fe8acf8c616fb725c613494b37121a1ad0e4
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4501
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/grfn/bbbg')
-rw-r--r--users/grfn/bbbg/src/bbbg/attendee.clj8
-rw-r--r--users/grfn/bbbg/src/bbbg/db/attendee.clj26
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/attendees.clj32
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/home.clj3
-rw-r--r--users/grfn/bbbg/src/bbbg/util/sql.clj5
5 files changed, 73 insertions, 1 deletions
diff --git a/users/grfn/bbbg/src/bbbg/attendee.clj b/users/grfn/bbbg/src/bbbg/attendee.clj
index fabedb0a910d..6088e1f0326d 100644
--- a/users/grfn/bbbg/src/bbbg/attendee.clj
+++ b/users/grfn/bbbg/src/bbbg/attendee.clj
@@ -2,3 +2,11 @@
   (:require [clojure.spec.alpha :as s]))
 
 (s/def ::id uuid?)
+
+(s/def ::meetup-name string?)
+
+(s/def ::discord-name (s/nilable string?))
+
+(s/def ::meetup-user-id (s/nilable string?))
+
+(s/def ::organizer-notes string?)
diff --git a/users/grfn/bbbg/src/bbbg/db/attendee.clj b/users/grfn/bbbg/src/bbbg/db/attendee.clj
index 7584b1cceb8e..8f5a8ffeb898 100644
--- a/users/grfn/bbbg/src/bbbg/db/attendee.clj
+++ b/users/grfn/bbbg/src/bbbg/db/attendee.clj
@@ -1,8 +1,12 @@
 (ns bbbg.db.attendee
   (:require
+   [bbbg.attendee :as attendee]
    [bbbg.db :as db]
+   [bbbg.util.sql :refer [count-where]]
    honeysql-postgres.helpers
-   [honeysql.helpers :refer [merge-join merge-where]]))
+   [honeysql.helpers
+    :refer
+    [merge-group-by merge-join merge-left-join merge-select merge-where]]))
 
 (defn search
   ([query]
@@ -23,7 +27,27 @@
        (merge-join :event_attendee [:= :attendee.id :event_attendee.attendee_id])
        (merge-where [:= :event_attendee.event_id event-id]))))
 
+(defn with-stats
+  ([] (with-stats {:select [:attendee.*]
+                   :from [:attendee]}))
+  ([query]
+   (-> query
+       (merge-left-join :event_attendee [:= :attendee.id :event_attendee.attendee_id])
+       (merge-group-by :attendee.id)
+       (merge-select
+        [(count-where :event_attendee.rsvpd_attending) :events-rsvpd]
+        [(count-where :event_attendee.attended) :events-attended]
+        [(count-where [:and
+                       :event_attendee.rsvpd_attending
+                       [:not :event_attendee.attended]])
+         :no-shows]))))
+
 (comment
   (def db (:db bbbg.core/system))
   (search db "gri")
+  (db/insert! db :attendee {::attendee/meetup-name "Griffin Smith"
+                            ::attendee/discord-name "grfn"
+                            })
+
+  (db/list db (with-stats))
   )
diff --git a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
index e2a57c7dac9b..3db7f04d9085 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj
@@ -8,11 +8,42 @@
    [cheshire.core :as json]
    [compojure.core :refer [GET POST routes]]
    [honeysql.helpers :refer [merge-where]]
+   [bbbg.handlers.core :refer [page-response wrap-auth-required]]
    [ring.util.response :refer [content-type redirect response]]
    [bbbg.views.flash :as flash]))
 
+(defn- attendees-page [{:keys [attendees]}]
+  [:div
+   [:form.search-form {:method :get :action "/attendees"}
+    [:input {:type "search"
+             :name "q"}]
+    [:input {:type "submit"
+             :value "Search Attendees"}]]
+   [:table.attendees
+    [:thead
+     [:tr
+      [:th "Meetup Name"]
+      [:th "Discord Name"]
+      [:th "Events RSVPd"]
+      [:th "Events Attended"]
+      [:th "No-Shows"]]]
+    [:tbody
+     (for [attendee attendees]
+       [:tr
+        [:td (::attendee/meetup-name attendee)]
+        [:td (::attendee/discord-name attendee)]
+        [:td (:events-rsvpd attendee)]
+        [:td (:events-attended attendee)]
+        [:td (:no-shows attendee)]])]]])
+
 (defn attendees-routes [{:keys [db]}]
   (routes
+   (wrap-auth-required
+    (routes
+     (GET "/attendees" []
+       (let [attendees (db/list db (db.attendee/with-stats))]
+         (page-response (attendees-page {:attendees attendees}))))))
+
    (GET "/attendees.json" [q event_id attended]
      (let [results
            (db/list
@@ -47,6 +78,7 @@
 
 (comment
   (def db (:db bbbg.core/system))
+  (db/list db :attendee)
   (db/list db
            (->
             (db.attendee/search "gr")
diff --git a/users/grfn/bbbg/src/bbbg/handlers/home.clj b/users/grfn/bbbg/src/bbbg/handlers/home.clj
index 726f45d4905d..81a968739718 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/home.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/home.clj
@@ -12,6 +12,9 @@
 (defn- home-page [{:keys [authenticated?]}]
   [:nav.home-nav
    [:ul
+    (when authenticated?
+      [:li [:a {:href "/attendees"}
+            "Attendees"]])
     [:li [:a {:href "/events"}
           "Events"]]
     [:li [:a {:href "/signup-forms"}
diff --git a/users/grfn/bbbg/src/bbbg/util/sql.clj b/users/grfn/bbbg/src/bbbg/util/sql.clj
new file mode 100644
index 000000000000..988959fd0603
--- /dev/null
+++ b/users/grfn/bbbg/src/bbbg/util/sql.clj
@@ -0,0 +1,5 @@
+(ns bbbg.util.sql
+  (:require [honeysql.core :as hsql]))
+
+(defn count-where [cond]
+  (hsql/call :count (hsql/call :case cond #sql/raw "1" :else nil)))