File tree Expand file tree Collapse file tree 4 files changed +21
-5
lines changed Expand file tree Collapse file tree 4 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 3333 :url url})
3434 extracted-posts (get-in extracted [:feed :posts ])
3535 extracted-display (get-in extracted [:feed :display-picture ])
36- extended-posts (mapv (fn [{:keys [thumbnail] :as post}]
36+ extended-posts (mapv (fn [{:keys [posted-at thumbnail] :as post}]
3737 (merge post
3838 {:feed-id feed-id
3939 :creator-id creator-id
4040 :content-type-id content-type-id
41+ :posted-at (util/format-rfc-1123-date posted-at)
4142 :thumbnail (if (and thumbnail
4243 (seq thumbnail)
4344 (not (string/includes? thumbnail " .mp3" )))
Original file line number Diff line number Diff line change 3232 [{:keys [ds bundle-id query-params body] :as _request}]
3333 (let [bundle-ds (db.util/conn :bundle bundle-id)
3434 {:keys [category-ids]} body
35- {:keys [type]} (walk/keywordize-keys query-params)
35+ {:keys [type latest ]} (walk/keywordize-keys query-params)
3636 feed-ids (mapv :feed-id (services/outgoing-posts bundle-ds))
3737 category-filtered-feed-ids (if (empty? category-ids)
3838 feed-ids
3939 (->> (hsql/where
4040 [:in :feed-id feed-ids]
4141 [:in :category-id category-ids])
42+ (hsql/order-by (when latest [:created-at :desc ]))
4243 (services/feed-categories ds)
4344 (mapv :feed-id )))
4445 type-filtered (->> (when type [:= :content-type-id type])
Original file line number Diff line number Diff line change 1212 [:uuid :string ]
1313 [:limit {:optional true } :int ]
1414 [:start {:optional true } :int ]
15- [:type {:optional true } :int ]]}
15+ [:type {:optional true } :int ]
16+ [:latest {:optional true } [:enum " true" " false" ]]]}
1617 :responses {200 {:body [:vector
1718 [:map
1819 [:id :int ]
3334
3435 [{:keys [ds bundle-id query-params body] :as _request}]
3536 (let [bundle-ds (db.util/conn :bundle bundle-id)
36- {:keys [limit start type]} (walk/keywordize-keys query-params)
37+ {:keys [limit start type latest ]} (walk/keywordize-keys query-params)
3738 {:keys [category-ids]} body
3839
3940 content-type-comp (when type [:= :content-type-id type])
4041 start (when start (try (Integer/parseInt start) (catch Exception _)))
4142 limit (when limit (try (Integer/parseInt limit) (catch Exception _)))
4243
43- filtered-posts (shuffle (services/outgoing-posts bundle-ds {:where content-type-comp}))
44+ filtered-posts (services/outgoing-posts bundle-ds {:where content-type-comp
45+ :order-by (when (= latest " true" ) [[:posted-at :desc ]])})
4446
4547 categorised-posts (vec (if (seq category-ids)
4648 (->> filtered-posts
Original file line number Diff line number Diff line change 6262 (m/explain schema)
6363 (me/humanize )))}))
6464
65+ (defn format-rss-date
66+ " Takes a date as a string in RFC 1123 format and returns it in a format that meets ISO 8601 standards for SQLite.
67+ This is necessary because some RSS feeds use a different date than what is accepted by SQLite.
68+ Returns the original string if it is not in this format."
69+ [s]
70+ (try
71+ (let [zdt (java.time.ZonedDateTime/parse s java.time.format.DateTimeFormatter/RFC_1123_DATE_TIME)
72+ zdt-utc (.withZoneSameInstant zdt (java.time.ZoneId/of " UTC" ))
73+ out (.format zdt-utc (java.time.format.DateTimeFormatter/ofPattern " yyyy-MM-dd HH:mm:ss" ))]
74+ out)
75+ (catch Exception _ s)))
76+
6577(comment
6678 (require '[source.routes.business :as business])
6779 (validate business/post {:cheese " modulr" })
You can’t perform that action at this time.
0 commit comments