|
| 1 | +(ns source.routes.post |
| 2 | + (:require [source.services.interface :as services] |
| 3 | + [ring.util.response :as res])) |
| 4 | + |
| 5 | +(defn get |
| 6 | + {:summary "get post by id" |
| 7 | + :parameters {:path [:map [:post-id {:title "post-id" |
| 8 | + :description "post id"} :int]]} |
| 9 | + :responses {200 {:body [:map |
| 10 | + [:id :int] |
| 11 | + [:post-id :string] |
| 12 | + [:feed-id :int] |
| 13 | + [:creator-id :int] |
| 14 | + [:content-type-id :int] |
| 15 | + [:title :string] |
| 16 | + [:thumbnail [:maybe :string]] |
| 17 | + [:info [:maybe :string]] |
| 18 | + [:url [:maybe :string]] |
| 19 | + [:stream-url [:maybe :string]] |
| 20 | + [:season [:maybe :int]] |
| 21 | + [:episode [:maybe :int]] |
| 22 | + [:redacted {:optional true} [:maybe :int]] |
| 23 | + [:posted-at [:maybe :string]]]}}} |
| 24 | + |
| 25 | + [{:keys [ds user path-params] :as _request}] |
| 26 | + (-> (services/incoming-post ds {:where [:and |
| 27 | + [:= :id (:post-id path-params)] |
| 28 | + [:= :creator-id (:id user)]]}) |
| 29 | + (res/response))) |
| 30 | + |
| 31 | +(defn post |
| 32 | + {:summary "Update redacted status of post with the given id" |
| 33 | + :parameters {:path [:map [:post-id {:title "post-id" |
| 34 | + :description "post id"} :int]] |
| 35 | + :body [:map |
| 36 | + [:redacted :boolean]]} |
| 37 | + :responses {200 {:body [:map [:message :string]]} |
| 38 | + 401 {:body [:map [:message :string]]} |
| 39 | + 403 {:body [:map [:message :string]]}}} |
| 40 | + |
| 41 | + [{:keys [ds path-params user body] :as _request}] |
| 42 | + (services/update-incoming-post! ds {:where [:and |
| 43 | + [:= :id (:post-id path-params)] |
| 44 | + [:= :creator-id (:id user)]] |
| 45 | + :data {:redacted (if (:redacted body) 1 0)}}) |
| 46 | + (res/response {:message "successfully updated post"})) |
0 commit comments