mirror of
https://github.com/penpot/penpot.git
synced 2025-03-15 17:21:17 -05:00
Send page data and options already serialized.
This commit is contained in:
parent
15f6672b0e
commit
5f86df81ec
1 changed files with 50 additions and 22 deletions
|
@ -8,56 +8,84 @@
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
[uxbox.repo.core :refer (request url send!)]
|
[uxbox.repo.core :refer (request url send!)]
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]
|
||||||
|
[uxbox.util.transit :as t]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
(defn- decode-page
|
||||||
;; Login
|
[{:keys [data options] :as page}]
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
(merge page
|
||||||
|
(when data {:data (t/decode data)})
|
||||||
|
(when options {:options (t/decode options)})))
|
||||||
|
|
||||||
|
(defn- decode-payload
|
||||||
|
[{:keys [payload] :as rsp}]
|
||||||
|
(if (sequential? payload)
|
||||||
|
(assoc rsp :payload (mapv decode-page payload))
|
||||||
|
(assoc rsp :payload (decode-page payload))))
|
||||||
|
|
||||||
(defmethod request :fetch/pages
|
(defmethod request :fetch/pages
|
||||||
[type data]
|
[type data]
|
||||||
(send! {:url (str url "/pages") :method :get}))
|
(let [params {:url (str url "/pages")
|
||||||
|
:method :get}]
|
||||||
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :fetch/pages-by-project
|
(defmethod request :fetch/pages-by-project
|
||||||
[type {:keys [project] :as params}]
|
[type {:keys [project] :as params}]
|
||||||
(let [url (str url "/projects/" project "/pages")]
|
(let [url (str url "/projects/" project "/pages")]
|
||||||
(send! {:method :get :url url})))
|
(->> (send! {:method :get :url url})
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :fetch/page-history
|
(defmethod request :fetch/page-history
|
||||||
[type {:keys [page] :as params}]
|
[type {:keys [page] :as params}]
|
||||||
(let [url (str url "/pages/" page "/history")
|
(let [url (str url "/pages/" page "/history")
|
||||||
query (select-keys params [:max :since :pinned])]
|
query (select-keys params [:max :since :pinned])
|
||||||
(send! {:method :get :url url :query query })))
|
params {:method :get :url url :query query}]
|
||||||
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :delete/page
|
(defmethod request :delete/page
|
||||||
[_ id]
|
[_ id]
|
||||||
(let [url (str url "/pages/" id)]
|
(let [url (str url "/pages/" id)]
|
||||||
(send! {:url url :method :delete})))
|
(send! {:url url
|
||||||
|
:method :delete})))
|
||||||
|
|
||||||
(defmethod request :create/page
|
(defmethod request :create/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [data options] :as body}]
|
||||||
(let [params {:url (str url "/pages")
|
(let [body (assoc body
|
||||||
|
:data (t/encode data)
|
||||||
|
:options (t/encode options))
|
||||||
|
params {:url (str url "/pages")
|
||||||
:method :post
|
:method :post
|
||||||
:body data}]
|
:body body}]
|
||||||
(send! params)))
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :update/page
|
(defmethod request :update/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id data options] :as body}]
|
||||||
(let [params {:url (str url "/pages/" id)
|
(let [body (assoc body
|
||||||
|
:data (t/encode data)
|
||||||
|
:options (t/encode options))
|
||||||
|
params {:url (str url "/pages/" id)
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body body}]
|
||||||
(send! params)))
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :update/page-history
|
(defmethod request :update/page-history
|
||||||
[type {:keys [id page] :as data}]
|
[type {:keys [id page] :as data}]
|
||||||
(let [params {:url (str url "/pages/" page "/history/" id)
|
(let [params {:url (str url "/pages/" page "/history/" id)
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
||||||
(defmethod request :update/page-metadata
|
(defmethod request :update/page-metadata
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id options] :as body}]
|
||||||
(let [params {:url (str url "/pages/" id "/metadata")
|
(let [body (dissoc body :data)
|
||||||
|
body (assoc body :options (t/encode options))
|
||||||
|
params {:url (str url "/pages/" id "/metadata")
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body body}]
|
||||||
(send! params)))
|
(->> (send! params)
|
||||||
|
(rx/map decode-payload))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue