mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
Improve code style and impl of auth and project repo ns.
This commit is contained in:
parent
ca4afe920c
commit
6492faefd4
@ -7,11 +7,8 @@
|
|||||||
(ns uxbox.repo.auth
|
(ns uxbox.repo.auth
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:refer-clojure :exclude [do])
|
(:refer-clojure :exclude [do])
|
||||||
(:require [httpurr.client.xhr :as http]
|
(:require [beicon.core :as rx]
|
||||||
[httpurr.status :as http.status]
|
[uxbox.repo.core :refer (-do url send!)]
|
||||||
[promesa.core :as p :include-macros true]
|
|
||||||
[beicon.core :as rx]
|
|
||||||
[uxbox.repo.core :as urc]
|
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -20,20 +17,24 @@
|
|||||||
|
|
||||||
(defn- request-token
|
(defn- request-token
|
||||||
[params]
|
[params]
|
||||||
(urc/req! {:url (str urc/url "/auth/token")
|
(let [url (str url "/auth/token")]
|
||||||
:method :post
|
(send! {:url url
|
||||||
:auth false
|
:method :post
|
||||||
:body params}))
|
:auth false
|
||||||
|
:body params})))
|
||||||
|
|
||||||
(defn- request-profile
|
(defn- request-profile
|
||||||
[]
|
[]
|
||||||
(p/resolved {:fullname "Cirilla Fiona"
|
(rx/of {:fullname "Cirilla Fiona"
|
||||||
:photo "/images/favicon.png"
|
:photo "/images/favicon.png"
|
||||||
:username "cirilla"
|
:username "cirilla"
|
||||||
:email "cirilla@uxbox.io"}))
|
:email "cirilla@uxbox.io"}))
|
||||||
|
|
||||||
(defmethod urc/-do :login
|
(defmethod -do :login
|
||||||
[type data]
|
[type data]
|
||||||
(p/alet [authdata (p/await (request-token data))
|
(->> (rx/zip (request-token data)
|
||||||
profile (p/await (request-profile))]
|
(request-profile))
|
||||||
(merge profile authdata)))
|
(rx/map (fn [[authdata profile]]
|
||||||
|
(println authdata profile)
|
||||||
|
(println authdata profile)
|
||||||
|
(merge authdata profile)))))
|
||||||
|
|||||||
@ -6,49 +6,55 @@
|
|||||||
|
|
||||||
(ns uxbox.repo.projects
|
(ns uxbox.repo.projects
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:refer-clojure :exclude [do])
|
(:require [beicon.core :as rx]
|
||||||
(:require [httpurr.client.xhr :as http]
|
[uxbox.repo.core :refer (-do url send!)]
|
||||||
[httpurr.status :as http.status]
|
|
||||||
[promesa.core :as p :include-macros true]
|
|
||||||
[beicon.core :as rx]
|
|
||||||
[uxbox.repo.core :as urc]
|
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Login
|
;; Login
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defmethod urc/-do :fetch/projects
|
(defmethod -do :fetch/projects
|
||||||
[type data]
|
[type data]
|
||||||
(urc/req! {:url (str urc/url "/projects") :method :get}))
|
(let [url (str url "/projects")]
|
||||||
|
(send! {:url url :method :get})))
|
||||||
|
|
||||||
(defmethod urc/-do :fetch/pages
|
(defmethod -do :fetch/pages
|
||||||
[type data]
|
[type data]
|
||||||
(urc/req! {:url (str urc/url "/pages") :method :get}))
|
(send! {:url (str url "/pages") :method :get}))
|
||||||
|
|
||||||
(defmethod urc/-do :create/project
|
(defmethod -do :fetch/pages-by-project
|
||||||
|
[type {:keys [project] :as params}]
|
||||||
|
(let [url (str url "/projects/" project "/pages")]
|
||||||
|
(send! {:method :get :url url})))
|
||||||
|
|
||||||
|
(defmethod -do :create/project
|
||||||
[_ data]
|
[_ data]
|
||||||
(let [params {:url (str urc/url "/projects")
|
(let [params {:url (str url "/projects")
|
||||||
:method :post
|
:method :post
|
||||||
:body data}]
|
:body data}]
|
||||||
(urc/req! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod urc/-do :delete/project
|
(defmethod -do :delete/project
|
||||||
[_ {:keys [id]}]
|
[_ id]
|
||||||
(let [params {:url (str urc/url "/projects/" id)
|
(let [url (str url "/projects/" id)]
|
||||||
:method :delete}]
|
(send! {:url url :method :delete})))
|
||||||
(urc/req! params)))
|
|
||||||
|
|
||||||
(defmethod urc/-do :create/page
|
(defmethod -do :delete/page
|
||||||
|
[_ id]
|
||||||
|
(let [url (str url "/pages/" id)]
|
||||||
|
(send! {:url url :method :delete})))
|
||||||
|
|
||||||
|
(defmethod -do :create/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id] :as data}]
|
||||||
(let [params {:url (str urc/url "/pages")
|
(let [params {:url (str url "/pages")
|
||||||
:method :post
|
:method :post
|
||||||
:body data}]
|
:body data}]
|
||||||
(urc/req! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod urc/-do :update/page
|
(defmethod -do :update/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id] :as data}]
|
||||||
(let [params {:url (str urc/url "/pages/" id)
|
(let [params {:url (str url "/pages/" id)
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body data}]
|
||||||
(urc/req! params)))
|
(send! params)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user