feat(grfn/bbbg): Add an attendee search form

Change-Id: I6f4d5102c1d3a36cb706a637196a2053739003bb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4502
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-19 12:30:36 -05:00 committed by clbot
parent 9af35bd683
commit 1b0ec2a6d6
3 changed files with 30 additions and 16 deletions

View file

@ -96,6 +96,11 @@
(defn make-database [config]
(map->Database {:config config}))
(defn database? [x]
(or
(instance? Database x)
(and (map? x) (contains? x :pool))))
;;;
;;; Migrations
;;;

View file

@ -9,17 +9,16 @@
[merge-group-by merge-join merge-left-join merge-select merge-where]]))
(defn search
([query]
(cond->
{:select [:attendee.*]
:from [:attendee]}
query
(assoc
:where [:or
[:ilike :meetup_name (str "%" query "%")]
[:ilike :discord_name (str "%" query "%")]])))
([db query]
(db/list db (search query))))
([q] (search {:select [:attendee.*] :from [:attendee]} q))
([db-or-query q]
(if (db/database? db-or-query)
(db/list db-or-query (search q))
(cond-> db-or-query
q [:or
[:ilike :meetup_name (str "%" q "%")]
[:ilike :discord_name (str "%" q "%")]])))
([db query q]
(db/list db (search query q))))
(defn for-event
([query event-id]
@ -44,10 +43,17 @@
(comment
(def db (:db bbbg.core/system))
(db/database? db)
(search db "gri")
(db/insert! db :attendee {::attendee/meetup-name "Griffin Smith"
::attendee/discord-name "grfn"
})
(search db (with-stats) "gri")
(search (with-stats) "gri")
(db/list db (with-stats))
(map? db)
)

View file

@ -12,11 +12,12 @@
[ring.util.response :refer [content-type redirect response]]
[bbbg.views.flash :as flash]))
(defn- attendees-page [{:keys [attendees]}]
(defn- attendees-page [{:keys [attendees q]}]
[:div
[:form.search-form {:method :get :action "/attendees"}
[:input {:type "search"
:name "q"}]
:name "q"
:value q}]
[:input {:type "submit"
:value "Search Attendees"}]]
[:table.attendees
@ -40,9 +41,11 @@
(routes
(wrap-auth-required
(routes
(GET "/attendees" []
(let [attendees (db/list db (db.attendee/with-stats))]
(page-response (attendees-page {:attendees attendees}))))))
(GET "/attendees" [q]
(let [attendees (db/list db (cond-> (db.attendee/with-stats)
q (db.attendee/search q)))]
(page-response (attendees-page {:attendees attendees
:q q}))))))
(GET "/attendees.json" [q event_id attended]
(let [results