get sending edit patch to backend working

This commit is contained in:
Travis Shears 2025-06-10 15:12:58 +02:00
parent e71062bb87
commit 7ab8f97e3e
2 changed files with 23 additions and 13 deletions

View file

@ -1 +1,2 @@
{:backend-host "http://aemos:5008"}
{:backend-host "http://localhost:8080"}
;; {:backend-host "http://aemos:5008"}

View file

@ -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]
(defn edit
([snippet]
(edit snippet {}))
([snippet changes]
(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))
: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")))