about summary refs log tree commit diff
path: root/users/grfn/bbbg/src
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-12-24T17·29-0500
committerclbot <clbot@tvl.fyi>2021-12-24T17·58+0000
commit6035a8ea9c4fb4b653a04c14f5e98a46eb016d4d (patch)
tree0b7be7a7e1e61957e39d441d1315b0d23b259c9f /users/grfn/bbbg/src
parentb2ded921a42b5ff23603d49e80552f60547360a0 (diff)
feat(grfn/bbbg): Add an import attendees button to event page r/3356
Change-Id: Iab69500f927a3f5a70d294ece3f95891853b63c3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4572
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Diffstat (limited to 'users/grfn/bbbg/src')
-rw-r--r--users/grfn/bbbg/src/bbbg/handlers/events.clj47
-rw-r--r--users/grfn/bbbg/src/bbbg/meetup/import.clj3
-rw-r--r--users/grfn/bbbg/src/bbbg/web.clj2
3 files changed, 38 insertions, 14 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/events.clj b/users/grfn/bbbg/src/bbbg/handlers/events.clj
index dd50a517cceb..6308a975641a 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/events.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/events.clj
@@ -4,13 +4,14 @@
    [bbbg.db.event :as db.event]
    [bbbg.event :as event]
    [bbbg.handlers.core :refer [authenticated? page-response]]
+   [bbbg.meetup.import :refer [import-data!]]
    [bbbg.util.display :refer [format-date]]
+   [bbbg.util.time :as t]
    [bbbg.views.flash :as flash]
    [compojure.coercions :refer [as-uuid]]
    [compojure.core :refer [context GET POST]]
    [java-time :refer [local-date]]
-   [ring.util.response :refer [not-found redirect]]
-   [bbbg.util.time :as t]))
+   [ring.util.response :refer [not-found redirect]]))
 
 (defn events-index [{:keys [events authenticated?]}]
   [:div
@@ -33,8 +34,19 @@
      (if (= (t/->LocalDate (::event/date event))
             (local-date))
        " Signed In"
-       (str " Attendee" (when-not (= 1 (:num-attendees event)) "s")))]
-    ]])
+       (str " Attendee" (when-not (= 1 (:num-attendees event)) "s")))]]
+   [:div
+    [:form {:method :post
+            :action (str "/events/" (::event/id event) "/attendees")
+            :enctype "multipart/form-data"}
+     [:div.form-group
+      [:label "Import Attendee List"
+       [:br]
+       [:input {:type :file
+                :name :attendees}]]]
+     [:div.form-group
+      [:input {:type :submit
+               :value "Import"}]]]]])
 
 (defn event-form
   ([] (event-form {}))
@@ -58,15 +70,24 @@
          (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")))
+    (context "/:id" [id :<< as-uuid]
+      (GET "/" []
+        (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")))
+
+      (POST "/attendees" [attendees]
+        (let [num-imported (import-data! db id (:tempfile attendees))]
+          (-> (redirect (str "/events/" id))
+              (flash/add-flash
+               #:flash{:type :success
+                       :message (format "Successfully imported %d attendees"
+                                        num-imported)})))))
 
     (GET "/new" [date]
       (page-response
diff --git a/users/grfn/bbbg/src/bbbg/meetup/import.clj b/users/grfn/bbbg/src/bbbg/meetup/import.clj
index 29aaf53e50b8..5b5cabaa4e71 100644
--- a/users/grfn/bbbg/src/bbbg/meetup/import.clj
+++ b/users/grfn/bbbg/src/bbbg/meetup/import.clj
@@ -99,7 +99,8 @@
      (map (partial row->event-attendee
                    {::event/id event-id
                     :meetup-id->attendee-id meetup-id->attendee-id})
-          rows))))
+          rows))
+    (count rows)))
 
 ;;; Spreadsheet columns:
 ;;;
diff --git a/users/grfn/bbbg/src/bbbg/web.clj b/users/grfn/bbbg/src/bbbg/web.clj
index e712c89378f7..c9d0fd0d4406 100644
--- a/users/grfn/bbbg/src/bbbg/web.clj
+++ b/users/grfn/bbbg/src/bbbg/web.clj
@@ -18,6 +18,7 @@
    [org.httpkit.server :as http-kit]
    [ring.middleware.flash :refer [wrap-flash]]
    [ring.middleware.keyword-params :refer [wrap-keyword-params]]
+   [ring.middleware.multipart-params :refer [wrap-multipart-params]]
    [ring.middleware.params :refer [wrap-params]]
    [ring.middleware.session :refer [wrap-session]]
    [ring.middleware.session.cookie :refer [cookie-store]]
@@ -88,6 +89,7 @@
       wrap-dynamic-auth
       (wrap-discord-auth env)
       wrap-keyword-params
+      wrap-multipart-params
       wrap-params
       wrap-page-flash
       wrap-flash