diff options
-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 |