diff options
author | Griffin Smith <grfn@gws.fyi> | 2021-12-19T17·30-0500 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2021-12-19T17·33+0000 |
commit | 1b0ec2a6d694dca0f22d6e0c102785b229b25f17 (patch) | |
tree | 98e7d58e18910e454b8973293abf47d5aa0820d3 | |
parent | 9af35bd683228f2c039e1dd39cde3f72749bd112 (diff) |
feat(grfn/bbbg): Add an attendee search form r/3309
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
-rw-r--r-- | users/grfn/bbbg/src/bbbg/db.clj | 5 | ||||
-rw-r--r-- | users/grfn/bbbg/src/bbbg/db/attendee.clj | 28 | ||||
-rw-r--r-- | users/grfn/bbbg/src/bbbg/handlers/attendees.clj | 13 |
3 files changed, 30 insertions, 16 deletions
diff --git a/users/grfn/bbbg/src/bbbg/db.clj b/users/grfn/bbbg/src/bbbg/db.clj index 03c86d6fb965..c5820f982bb9 100644 --- a/users/grfn/bbbg/src/bbbg/db.clj +++ b/users/grfn/bbbg/src/bbbg/db.clj @@ -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 ;;; diff --git a/users/grfn/bbbg/src/bbbg/db/attendee.clj b/users/grfn/bbbg/src/bbbg/db/attendee.clj index 8f5a8ffeb898..c8b1df613f94 100644 --- a/users/grfn/bbbg/src/bbbg/db/attendee.clj +++ b/users/grfn/bbbg/src/bbbg/db/attendee.clj @@ -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) ) diff --git a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj index 3db7f04d9085..b6846c1f3c44 100644 --- a/users/grfn/bbbg/src/bbbg/handlers/attendees.clj +++ b/users/grfn/bbbg/src/bbbg/handlers/attendees.clj @@ -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 |