diff --git a/resources/co/gaiwan/compass/config.edn b/resources/co/gaiwan/compass/config.edn index fdb87c1..7843864 100644 --- a/resources/co/gaiwan/compass/config.edn +++ b/resources/co/gaiwan/compass/config.edn @@ -1,4 +1,6 @@ {:port 8099 :tito/event-slug "heart-of-clojure/2024" :uploads/dir "uploads" - :dynamic-routes? false} + :dynamic-routes? false + :tito/sync-interval-seconds 900 ;; every 15 minutes + } diff --git a/resources/co/gaiwan/compass/system.edn b/resources/co/gaiwan/compass/system.edn index eeaf8dd..3e2a766 100644 --- a/resources/co/gaiwan/compass/system.edn +++ b/resources/co/gaiwan/compass/system.edn @@ -1,5 +1,6 @@ -{:compass/http {:port #config :port - :router #ig/ref :compass/router +{:compass/http {:port #config :port + :router #ig/ref :compass/router :dynamic? #config :dynamic-routes?} :compass/router {:dynamic? #config :dynamic-routes?} - :compass/db {:url #config :datomic/url}} + :compass/db {:url #config :datomic/url} + :tito/sync {:interval-seconds #config :tito/sync-interval-seconds}} diff --git a/src/co/gaiwan/compass/db/queries.clj b/src/co/gaiwan/compass/db/queries.clj index a1a8e6e..a564404 100644 --- a/src/co/gaiwan/compass/db/queries.clj +++ b/src/co/gaiwan/compass/db/queries.clj @@ -5,14 +5,22 @@ (defn all-sessions [] - (sort-by :session/time - (db/q - '[:find - [(pull ?e [* {:session/type [*] - :session/location [*]}]) ...] - :where - [?e :session/title]] - (db/db)))) + (sort-by + :session/time + (db/q + '[:find + [(pull ?e [* {:session/type [*] + :session/location [*]}]) ...] + :where + [?e :session/title]] + (db/db)))) (defn all-users [] - ) + (sort-by + :public-profile/name + (db/q + '[:find + [(pull ?e [*]) ...] + :where + [?e :public-profile/name]] + (db/db)))) diff --git a/src/co/gaiwan/compass/model/session.clj b/src/co/gaiwan/compass/model/session.clj index f43a727..c7ab04d 100644 --- a/src/co/gaiwan/compass/model/session.clj +++ b/src/co/gaiwan/compass/model/session.clj @@ -19,13 +19,13 @@ ;; first make sure that user is already login (some? user) (or - ;; Condition 1: organized property record the user's :db/id + ;; Condition 1: organized property record the user's :db/id (= (:db/id user) (:db/id organized)) - ;; Condition 2: organized property record the user's group :db/id + ;; Condition 2: organized property record the user's group :db/id (some (comp #{(:db/id user)} :db/id) (:user-group/users organized)) - ;; Condition 3: The user belongs to orga group + ;; Condition 3: The user belongs to orga group (some :user-group/orga (:user-group/_users user)))))) @@ -102,11 +102,12 @@ (< (count participants) capacity)) sessions)) +(def default-filters + {:include-past false}) + (defn apply-filters [sessions user filters] - (def sessions sessions) - (def f filters) (reduce (fn [sessions [k v]] (apply-filter sessions user k v)) sessions - filters)) + (merge default-filters filters))) diff --git a/src/co/gaiwan/compass/routes/filters.clj b/src/co/gaiwan/compass/routes/filters.clj index 29a77fb..cc16a38 100644 --- a/src/co/gaiwan/compass/routes/filters.clj +++ b/src/co/gaiwan/compass/routes/filters.clj @@ -2,10 +2,8 @@ "Filtering behavior" (:require [co.gaiwan.compass.html.filters :as filters] - [co.gaiwan.compass.http.response :as redirect])) - -(def defaults - {:include-past false}) + [co.gaiwan.compass.http.response :as redirect] + [co.gaiwan.compass.model.session :as session])) (defn GET-filters [req] {:html/layout false @@ -18,7 +16,7 @@ :location "/" :session (assoc session :session-filters - (merge defaults + (merge session/default-filters (update-vals params keyword)))})) (defn routes [] diff --git a/src/co/gaiwan/compass/routes/profiles.clj b/src/co/gaiwan/compass/routes/profiles.clj index 7587bfb..697eeaf 100644 --- a/src/co/gaiwan/compass/routes/profiles.clj +++ b/src/co/gaiwan/compass/routes/profiles.clj @@ -4,6 +4,7 @@ [clojure.java.io :as io] [co.gaiwan.compass.config :as config] [co.gaiwan.compass.db :as db] + [co.gaiwan.compass.db.queries :as q] [co.gaiwan.compass.html.profiles :as h] [co.gaiwan.compass.http.response :as response] [ring.util.response :as ring-response])) @@ -47,7 +48,9 @@ (ring-response/file-response (.getPath file)) (ring-response/not-found "File not found")))) -(defn GET-attendees [req]) +(defn GET-attendees [req] + (let [attendees (q/all-users)] + {:html/body [:p "TODO"] #_[attendees/user-list attendees]})) (defn routes [] [["/profile" diff --git a/src/co/gaiwan/compass/routes/ticket.clj b/src/co/gaiwan/compass/routes/ticket.clj index bb86f55..2ee13c2 100644 --- a/src/co/gaiwan/compass/routes/ticket.clj +++ b/src/co/gaiwan/compass/routes/ticket.clj @@ -29,7 +29,7 @@ (if-let [ticket (tito/find-unassigned-ticket (str/upper-case ref) email)] (do @(db/transact - [:db/add (:db/id ticket) :tito.ticket/assigned-to [:user/uuid (:user/uuid identity)]]) + [[:db/add (:db/id ticket) :tito.ticket/assigned-to [:user/uuid (:user/uuid identity)]]]) (discord/assign-ticket-role (:discord/id identity) ticket) (response/redirect "/" {:flash [:p "Ticket connection successful! You should now have the appropriate roles in our Discord server."]})) (response/redirect "/connect-ticket" {:status :found diff --git a/src/co/gaiwan/compass/services/tito.clj b/src/co/gaiwan/compass/services/tito.clj index fb69803..5e04001 100644 --- a/src/co/gaiwan/compass/services/tito.clj +++ b/src/co/gaiwan/compass/services/tito.clj @@ -14,7 +14,9 @@ [co.gaiwan.compass.config :as config] [co.gaiwan.compass.db :as db] [co.gaiwan.compass.util :as util] - [hato.client :as hato])) + [hato.client :as hato] + [integrant.core :as ig] + [io.pedestal.log :as log])) (def API_ENDPOINT (str "https://api.tito.io/v3/" (config/value :tito/event-slug) "/")) @@ -128,6 +130,21 @@ (not [?ticket :tito.ticket/assigned-to _])] (db/db) reference email)) +(defmethod ig/init-key :tito/sync [_ {:keys [interval-seconds]}] + (log/info :tito/starting-sync-loop {:interval-seconds interval-seconds}) + (let [stop? (volatile! false)] + (future + (while (not @stop?) + (try + (sync!) + (catch Exception e + (log/error :tito/sync-failed {} :exception e))) + (Thread/sleep (* 1000 interval-seconds)))) + stop?)) + +(defmethod ig/halt-key! :tito/sync [_ stop?] + (vreset! stop? true)) + (comment (sync!)