diff --git a/config.edn b/config.edn index 0afcf59..90e2cc7 100644 --- a/config.edn +++ b/config.edn @@ -1 +1,2 @@ -{:backend-host "http://aemos:5008"} +{:backend-host "http://localhost:8080"} +;; {:backend-host "http://aemos:5008"} diff --git a/src/cli_cms/edit.clj b/src/cli_cms/edit.clj index 0a1f074..9d0d6b0 100644 --- a/src/cli_cms/edit.clj +++ b/src/cli_cms/edit.clj @@ -20,19 +20,28 @@ {:value "tags" :item :tags} {:value "done" :item :done}))) -;; (defn send-patch [{:keys [title slug markdown tags]}] -;; (http/post (str (:backend-host config) "/api/snippet") -;; {:headers {:content-type "application/json"} -;; :body (json/encode {:title title :slug slug :markdown markdown :tags tags})})) +(defn send-patch [id patch] + (http/patch (str (:backend-host config) "/api/snippet") + {:query-params {:id id} + :headers {:content-type "application/json"} + :body (json/encode patch)})) -(defn edit [snippet] - (case (prompt-for-edit-type) - :title (edit (assoc snippet :title (utils/prompt-for "title"))) - :slug (edit (assoc snippet :slug (utils/prompt-for "slug"))) - :tags (edit (assoc snippet :tags (utils/prompt-for-many "tags"))) - :markdown (edit (assoc snippet :markdown (utils/prompt-for-long-form "markdown"))) - :done snippet)) +(defn edit + ([snippet] + (edit snippet {})) + ([snippet changes] + (case (prompt-for-edit-type) + :title (let [new-title (utils/prompt-for "title")] + (edit (assoc snippet :title new-title) (assoc changes :title new-title))) + :slug (let [new-slug (utils/prompt-for "slug")] + (edit (assoc snippet :slug new-slug) (assoc changes :slug new-slug))) + :tags (let [new-tags (utils/prompt-for-many "tags")] + (edit (assoc snippet :tags new-tags) (assoc changes :tags new-tags))) + :markdown (let [new-markdown (utils/prompt-for-long-form "markdown")] + (edit (assoc snippet :markdown new-markdown) (assoc changes :markdown new-markdown))) + :done changes))) (defn run [] (let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))] - (pprint (edit snippet-to-edit)))) + (send-patch (:id snippet-to-edit) (edit snippet-to-edit)) + (println "Snippet updated successfully")))