get sending edit patch to backend working
This commit is contained in:
parent
e71062bb87
commit
7ab8f97e3e
2 changed files with 23 additions and 13 deletions
|
|
@ -1 +1,2 @@
|
||||||
{:backend-host "http://aemos:5008"}
|
{:backend-host "http://localhost:8080"}
|
||||||
|
;; {:backend-host "http://aemos:5008"}
|
||||||
|
|
|
||||||
|
|
@ -20,19 +20,28 @@
|
||||||
{:value "tags" :item :tags}
|
{:value "tags" :item :tags}
|
||||||
{:value "done" :item :done})))
|
{:value "done" :item :done})))
|
||||||
|
|
||||||
;; (defn send-patch [{:keys [title slug markdown tags]}]
|
(defn send-patch [id patch]
|
||||||
;; (http/post (str (:backend-host config) "/api/snippet")
|
(http/patch (str (:backend-host config) "/api/snippet")
|
||||||
;; {:headers {:content-type "application/json"}
|
{:query-params {:id id}
|
||||||
;; :body (json/encode {:title title :slug slug :markdown markdown :tags tags})}))
|
:headers {:content-type "application/json"}
|
||||||
|
:body (json/encode patch)}))
|
||||||
|
|
||||||
(defn edit [snippet]
|
(defn edit
|
||||||
(case (prompt-for-edit-type)
|
([snippet]
|
||||||
:title (edit (assoc snippet :title (utils/prompt-for "title")))
|
(edit snippet {}))
|
||||||
:slug (edit (assoc snippet :slug (utils/prompt-for "slug")))
|
([snippet changes]
|
||||||
:tags (edit (assoc snippet :tags (utils/prompt-for-many "tags")))
|
(case (prompt-for-edit-type)
|
||||||
:markdown (edit (assoc snippet :markdown (utils/prompt-for-long-form "markdown")))
|
:title (let [new-title (utils/prompt-for "title")]
|
||||||
:done snippet))
|
(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 []
|
(defn run []
|
||||||
(let [snippet-to-edit (utils/select (map #(hash-map :value (:slug %) :item %) (fetch-snippets)))]
|
(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")))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue