Skip to content

Commit

Permalink
Add tito sync, fix db/transact call, fix default filter behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Aug 20, 2024
1 parent c485f37 commit 11925e2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
4 changes: 3 additions & 1 deletion resources/co/gaiwan/compass/config.edn
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 4 additions & 3 deletions resources/co/gaiwan/compass/system.edn
Original file line number Diff line number Diff line change
@@ -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}}
26 changes: 17 additions & 9 deletions src/co/gaiwan/compass/db/queries.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
13 changes: 7 additions & 6 deletions src/co/gaiwan/compass/model/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))

Expand Down Expand Up @@ -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)))
8 changes: 3 additions & 5 deletions src/co/gaiwan/compass/routes/filters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +16,7 @@
:location "/"
:session (assoc session
:session-filters
(merge defaults
(merge session/default-filters
(update-vals params keyword)))}))

(defn routes []
Expand Down
5 changes: 4 additions & 1 deletion src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/co/gaiwan/compass/routes/ticket.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion src/co/gaiwan/compass/services/tito.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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) "/"))

Expand Down Expand Up @@ -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!)

Expand Down

0 comments on commit 11925e2

Please sign in to comment.