get snippets and get snippet
This commit is contained in:
parent
70aea77dcc
commit
7bbee5b0fb
6 changed files with 42 additions and 6 deletions
|
|
@ -5,13 +5,13 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete {
|
delete {
|
||||||
url: {{host}}/api/snippet?id=952cdf1a-a2a8-4fe2-9354-953b240136ae
|
url: {{host}}/api/snippet?id=90d00a80-78c4-4bc9-a066-01c988599d05
|
||||||
body: none
|
body: none
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
||||||
params:query {
|
params:query {
|
||||||
id: 952cdf1a-a2a8-4fe2-9354-953b240136ae
|
id: 90d00a80-78c4-4bc9-a066-01c988599d05
|
||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
|
|
|
||||||
23
bruno/CodeSnippets/get_snippet.bru
Normal file
23
bruno/CodeSnippets/get_snippet.bru
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
meta {
|
||||||
|
name: get_snippet
|
||||||
|
type: http
|
||||||
|
seq: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/api/snippet?id=aea69336-5116-49ac-ab52-bc221bdb7830
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
params:query {
|
||||||
|
id: aea69336-5116-49ac-ab52-bc221bdb7830
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"title": "Test Snippet",
|
||||||
|
"markdown": "## Cool Snippet\ndoes a cool thing",
|
||||||
|
"tags": ["git", "jj"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{host}}/api/snippet?limit=100&skip=0
|
url: {{host}}/api/snippets?limit=100&skip=0
|
||||||
body: none
|
body: none
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,16 @@
|
||||||
(core/create-snippet body)
|
(core/create-snippet body)
|
||||||
{:status 200, :body "snippet created"})
|
{:status 200, :body "snippet created"})
|
||||||
|
|
||||||
(defn handle-view-snippet [{params :query-params}]
|
(defn handle-view-snippets [{params :query-params}]
|
||||||
(let [limit (Integer/parseInt (get params "limit" "10"))
|
(let [limit (Integer/parseInt (get params "limit" "10"))
|
||||||
skip (Integer/parseInt (get params "skip" "0"))]
|
skip (Integer/parseInt (get params "skip" "0"))]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (core/list-snippets {:limit limit :skip skip})}))
|
:body (core/view-snippets {:limit limit :skip skip})}))
|
||||||
|
|
||||||
|
(defn handle-view-snippet [{params :query-params}]
|
||||||
|
(let [id (get params "id")]
|
||||||
|
{:status 200
|
||||||
|
:body (core/view-snippet id)}))
|
||||||
|
|
||||||
(defn handle-delete-snippet [{params :query-params}]
|
(defn handle-delete-snippet [{params :query-params}]
|
||||||
(let [id (get params "id")]
|
(let [id (get params "id")]
|
||||||
|
|
@ -41,6 +46,7 @@
|
||||||
mm/wrap-format
|
mm/wrap-format
|
||||||
[wrap :api]]}
|
[wrap :api]]}
|
||||||
["/ping" {:get handle-ping}]
|
["/ping" {:get handle-ping}]
|
||||||
|
["/snippets" {:get handle-view-snippets}]
|
||||||
["/snippet" {:post handle-create-snippet
|
["/snippet" {:post handle-create-snippet
|
||||||
:get handle-view-snippet
|
:get handle-view-snippet
|
||||||
:delete handle-delete-snippet}]])
|
:delete handle-delete-snippet}]])
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@
|
||||||
(t/log! {:level :info, :data {:title title :slug slug :id id}} "Creating snippet")
|
(t/log! {:level :info, :data {:title title :slug slug :id id}} "Creating snippet")
|
||||||
(db/put-snippet id {:title title :slug slug :markdown markdown :tags tags :pub-date pub-date})))
|
(db/put-snippet id {:title title :slug slug :markdown markdown :tags tags :pub-date pub-date})))
|
||||||
|
|
||||||
(defn list-snippets [& args]
|
(defn view-snippet [key]
|
||||||
|
(t/log! {:level :info, :data {:key key}} "Viewing snippet by id")
|
||||||
|
(db/get-snippet-by-id key))
|
||||||
|
|
||||||
|
(defn view-snippets [& args]
|
||||||
(db/list-snippets args))
|
(db/list-snippets args))
|
||||||
|
|
||||||
(defn delete-snippet [key]
|
(defn delete-snippet [key]
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@
|
||||||
(read-string
|
(read-string
|
||||||
(format "(quote (-> (from :snippets [title pub-date tags slug markdown {:xt/id id}]) (order-by {:val pub-date, :dir :desc, :nulls :last}) (offset %s) (limit %s)))" skip limit)))))
|
(format "(quote (-> (from :snippets [title pub-date tags slug markdown {:xt/id id}]) (order-by {:val pub-date, :dir :desc, :nulls :last}) (offset %s) (limit %s)))" skip limit)))))
|
||||||
|
|
||||||
|
(defn get-snippet-by-id [snippet-id]
|
||||||
|
(first (xt/q client ['#(from :snippets [{:xt/id %} slug title {:xt/id id} markdown pub-date]) snippet-id])))
|
||||||
|
|
||||||
(defn put-snippet [id snippet]
|
(defn put-snippet [id snippet]
|
||||||
(t/log! {:level :info, :data {:snippet snippet :id id}} "Saving new snippet to db")
|
(t/log! {:level :info, :data {:snippet snippet :id id}} "Saving new snippet to db")
|
||||||
(xt/execute-tx client [[:put-docs :snippets (merge snippet {:xt/id id})]]))
|
(xt/execute-tx client [[:put-docs :snippets (merge snippet {:xt/id id})]]))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue