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·38-0500
committerclbot <clbot@tvl.fyi>2021-12-24T18·02+0000
commitea39c6bdfe12771910e3847de8b9393ca91101cb (patch)
tree44259f6d25b9da7dc7e6e017abfa8e88900ab582 /users/grfn/bbbg/src
parent6035a8ea9c4fb4b653a04c14f5e98a46eb016d4d (diff)
feat(grfn/bbbg): Allow creating events with attendees r/3357
Change-Id: I91a6a54921b90098040eb315d8b5385bd42879ac
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4573
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.clj57
-rw-r--r--users/grfn/bbbg/src/bbbg/meetup/import.clj4
2 files changed, 38 insertions, 23 deletions
diff --git a/users/grfn/bbbg/src/bbbg/handlers/events.clj b/users/grfn/bbbg/src/bbbg/handlers/events.clj
index 6308a975641a..f1cd05235423 100644
--- a/users/grfn/bbbg/src/bbbg/handlers/events.clj
+++ b/users/grfn/bbbg/src/bbbg/handlers/events.clj
@@ -4,7 +4,7 @@
    [bbbg.db.event :as db.event]
    [bbbg.event :as event]
    [bbbg.handlers.core :refer [authenticated? page-response]]
-   [bbbg.meetup.import :refer [import-data!]]
+   [bbbg.meetup.import :refer [import-attendees!]]
    [bbbg.util.display :refer [format-date]]
    [bbbg.util.time :as t]
    [bbbg.views.flash :as flash]
@@ -24,6 +24,13 @@
        [:a {:href (str "/events/" (::event/id event))}
         (format-date (::event/date event))]])]])
 
+(defn- import-attendee-list-form-group []
+  [:div.form-group
+   [:label "Import Attendee List"
+    [:br]
+    [:input {:type :file
+             :name :attendees}]]])
+
 (defn event-page [{:keys [event]}]
   [:div.event-page
    [:h1 (format-date (::event/date event))]
@@ -39,11 +46,7 @@
     [: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}]]]
+     (import-attendee-list-form-group)
      [:div.form-group
       [:input {:type :submit
                :value "Import"}]]]]])
@@ -51,13 +54,16 @@
 (defn event-form
   ([] (event-form {}))
   ([event]
-   [:form {:method "POST" :action "/events"}
+   [:form {:method "POST"
+           :action "/events"
+           :enctype "multipart/form-data"}
     [:div.form-group
      [:label "Date"
       [:input {:type "date"
                :id "date"
                :name "date"
                :value (str (::event/date event))}]]]
+    (import-attendee-list-form-group)
     [:div.form-group
      [:input {:type "submit"
               :value "Create Event"}]]]))
@@ -70,6 +76,27 @@
          (events-index {:events events
                         :authenticated? (authenticated? request)}))))
 
+    (GET "/new" [date]
+      (page-response
+       {:title "New Event"}
+       (event-form {::event/date date})))
+
+    (POST "/" [date attendees]
+      (let [event (db.event/create! db {::event/date date})
+            message
+            (if attendees
+              (let [num-attendees
+                    (import-attendees! db
+                                       (::event/id event)
+                                       (:tempfile attendees))]
+                (format "Event created with %d attendees"
+                        num-attendees))
+              "Event created")]
+        (-> (str "/signup-forms/" (::event/id event))
+            redirect
+            (flash/add-flash {:flash/type :success
+                              :flash/message message}))))
+
     (context "/:id" [id :<< as-uuid]
       (GET "/" []
         (if-let [event (db/fetch db
@@ -82,24 +109,12 @@
           (not-found "Event Not Found")))
 
       (POST "/attendees" [attendees]
-        (let [num-imported (import-data! db id (:tempfile attendees))]
+        (let [num-imported (import-attendees! 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
-       {:title "New Event"}
-       (event-form {::event/date date})))
-
-    (POST "/" [date]
-      (let [event (db.event/create! db {::event/date date})]
-        (-> (str "/signup-forms/" (::event/id event))
-            redirect
-            (flash/add-flash {:flash/type :success
-                              :flash/message "Event Created"}))))))
+                                        num-imported)})))))))
 
 (comment
   (def db (:db bbbg.core/system))
diff --git a/users/grfn/bbbg/src/bbbg/meetup/import.clj b/users/grfn/bbbg/src/bbbg/meetup/import.clj
index 5b5cabaa4e71..d13d63e16cc2 100644
--- a/users/grfn/bbbg/src/bbbg/meetup/import.clj
+++ b/users/grfn/bbbg/src/bbbg/meetup/import.clj
@@ -88,7 +88,7 @@
 
 ;;;
 
-(defn import-data! [db event-id f]
+(defn import-attendees! [db event-id f]
   (let [rows (read-attendees f)
         attendees (db.attendee/upsert-all! db (map row->attendee rows))
         meetup-id->attendee-id (into {}
@@ -120,6 +120,6 @@
   (def event-id #uuid "09f8fed6-7480-451b-89a2-bb4edaeae657")
 
   (read-attendees -filename-)
-  (import-data! (:db bbbg.core/system) event-id -filename-)
+  (import-attendees! (:db bbbg.core/system) event-id -filename-)
 
   )