0
Fork 0
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:
Andrey Antukh 2016-04-24 18:48:04 +03:00
parent 15f6672b0e
commit 5f86df81ec
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -8,56 +8,84 @@
"A main interface for access to remote resources."
(:require [beicon.core :as rx]
[uxbox.repo.core :refer (request url send!)]
[uxbox.state :as ust]))
[uxbox.state :as ust]
[uxbox.util.transit :as t]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Login
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- decode-page
[{: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
[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
[type {:keys [project] :as params}]
(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
[type {:keys [page] :as params}]
(let [url (str url "/pages/" page "/history")
query (select-keys params [:max :since :pinned])]
(send! {:method :get :url url :query query })))
query (select-keys params [:max :since :pinned])
params {:method :get :url url :query query}]
(->> (send! params)
(rx/map decode-payload))))
(defmethod request :delete/page
[_ id]
(let [url (str url "/pages/" id)]
(send! {:url url :method :delete})))
(send! {:url url
:method :delete})))
(defmethod request :create/page
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages")
[type {:keys [data options] :as body}]
(let [body (assoc body
:data (t/encode data)
:options (t/encode options))
params {:url (str url "/pages")
:method :post
:body data}]
(send! params)))
:body body}]
(->> (send! params)
(rx/map decode-payload))))
(defmethod request :update/page
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages/" id)
[type {:keys [id data options] :as body}]
(let [body (assoc body
:data (t/encode data)
:options (t/encode options))
params {:url (str url "/pages/" id)
:method :put
:body data}]
(send! params)))
:body body}]
(->> (send! params)
(rx/map decode-payload))))
(defmethod request :update/page-history
[type {:keys [id page] :as data}]
(let [params {:url (str url "/pages/" page "/history/" id)
:method :put
:body data}]
(send! params)))
(->> (send! params)
(rx/map decode-payload))))
(defmethod request :update/page-metadata
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages/" id "/metadata")
[type {:keys [id options] :as body}]
(let [body (dissoc body :data)
body (assoc body :options (t/encode options))
params {:url (str url "/pages/" id "/metadata")
:method :put
:body data}]
(send! params)))
:body body}]
(->> (send! params)
(rx/map decode-payload))))