Skip to content
Snippets Groups Projects
Unverified Commit f80bce03 authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Events BE fixes - Hydrate :collection on timelines and default icon "star" (#21169)

parent 8869361e
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@
archived (s/maybe su/BooleanString)}
(let [archived? (Boolean/parseBoolean archived)
timelines (db/select Timeline [:where [:= :archived archived?]])]
(cond->> (hydrate timelines :creator)
(cond->> (hydrate timelines :creator :collection)
(= include "events")
(map #(timeline-event/include-events-singular % {:events/all? archived?})))))
......@@ -48,7 +48,7 @@
end (s/maybe su/TemporalString)}
(let [archived? (Boolean/parseBoolean archived)
timeline (api/read-check (Timeline id))]
(cond-> (hydrate timeline :creator)
(cond-> (hydrate timeline :creator :collection)
(= include "events")
(timeline-event/include-events-singular {:events/all? archived?
:events/start (when start (u.date/parse start))
......
......@@ -30,12 +30,13 @@
{:status-code 404})))
(collection/check-write-perms-for-collection (:collection_id timeline)))
;; todo: revision system
(let [parsed (if (nil? timestamp)
(throw (ex-info (tru "Timestamp cannot be null") {:status-code 400}))
(u.date/parse timestamp))]
(db/insert! TimelineEvent (assoc body
:creator_id api/*current-user-id*
:timestamp parsed))))
(let [parsed-timestamp (if (nil? timestamp)
(throw (ex-info (tru "Timestamp cannot be null") {:status-code 400}))
(u.date/parse timestamp))
evt (merge body {:creator_id api/*current-user-id*
:timestamp parsed-timestamp})]
(db/insert! TimelineEvent (cond-> evt
(nil? icon) (assoc :icon "star")))))
(api/defendpoint GET "/:id"
"Fetch the [[TimelineEvent]] with `id`."
......
......@@ -34,7 +34,13 @@
(events-of (mt/user-http-request :rasta :get 200 "timeline")))))
(testing "check that we only get archived timelines when `archived=true`"
(is (= #{"Timeline C"}
(events-of (mt/user-http-request :rasta :get 200 "timeline" :archived true))))))))))
(events-of (mt/user-http-request :rasta :get 200 "timeline" :archived true)))))
(testing "check that `:collection` key is hydrated on each timeline"
(is (= #{id}
(->> (mt/user-http-request :rasta :get 200 "timeline")
(filter (comp #{id} :collection_id))
(map #(get-in % [:collection :id]))
set)))))))))
(deftest get-timeline-test
(testing "GET /api/timeline/:id"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment