init view / list tags
This commit is contained in:
parent
a2352d19c2
commit
bbeb1b6ba0
6 changed files with 36 additions and 4 deletions
|
|
@ -16,7 +16,7 @@ params:query {
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"title": "Updated from Bruno",
|
"title": "quick way to push last jj commit to git",
|
||||||
"tags": ["code", "mock"]
|
"tags": ["jj", "git"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{host}}/api/snippets?limit=100&skip=0
|
url: {{host}}/api/snippets?limit=25&skip=0
|
||||||
body: none
|
body: none
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
||||||
params:query {
|
params:query {
|
||||||
limit: 100
|
limit: 25
|
||||||
skip: 0
|
skip: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
19
bruno/CodeSnippets/get_tags.bru
Normal file
19
bruno/CodeSnippets/get_tags.bru
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
meta {
|
||||||
|
name: get_tags
|
||||||
|
type: http
|
||||||
|
seq: 8
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/api/tags
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"title": "Test Snippet",
|
||||||
|
"markdown": "## Cool Snippet\ndoes a cool thing",
|
||||||
|
"tags": ["git", "jj"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -47,6 +47,11 @@
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (format "Deleted snippet with id: %s if it existed" id)}))
|
:body (format "Deleted snippet with id: %s if it existed" id)}))
|
||||||
|
|
||||||
|
(defn handle-view-tags [_args]
|
||||||
|
(let [tags (snippets.use-cases.view/view-tags)]
|
||||||
|
{:status 200
|
||||||
|
:body tags}))
|
||||||
|
|
||||||
(defn wrap [handler id]
|
(defn wrap [handler id]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(update (handler request) :wrap (fnil conj '()) id)))
|
(update (handler request) :wrap (fnil conj '()) id)))
|
||||||
|
|
@ -58,6 +63,7 @@
|
||||||
mm/wrap-format
|
mm/wrap-format
|
||||||
[wrap :api]]}
|
[wrap :api]]}
|
||||||
["/ping" {:get handle-ping}]
|
["/ping" {:get handle-ping}]
|
||||||
|
["/tags" {:get handle-view-tags}]
|
||||||
["/snippets" {:get handle-view-snippets}]
|
["/snippets" {:get handle-view-snippets}]
|
||||||
["/snippet" {:post handle-create-snippet
|
["/snippet" {:post handle-create-snippet
|
||||||
:get handle-view-snippet
|
:get handle-view-snippet
|
||||||
|
|
|
||||||
|
|
@ -39,3 +39,6 @@
|
||||||
(defn patch-snippet [id patch]
|
(defn patch-snippet [id patch]
|
||||||
(t/log! {:level :info, :data {:patch patch :id id}} "Patching snippet")
|
(t/log! {:level :info, :data {:patch patch :id id}} "Patching snippet")
|
||||||
(xt/execute-tx client [[:patch-docs :snippets (merge {:xt/id id} patch)]]))
|
(xt/execute-tx client [[:patch-docs :snippets (merge {:xt/id id} patch)]]))
|
||||||
|
|
||||||
|
(defn list-tags []
|
||||||
|
(xt/q client '(-> (from :snippets [{:xt/id id} tags]) (unnest {:tag tags}) (without :tags) (aggregate tag {:ids (array-agg id)}))))
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,7 @@
|
||||||
|
|
||||||
(defn view-snippets [& args]
|
(defn view-snippets [& args]
|
||||||
(db/list-snippets args))
|
(db/list-snippets args))
|
||||||
|
|
||||||
|
(defn view-tags []
|
||||||
|
(t/log! {:level :info} "Viewing tags")
|
||||||
|
(map #(assoc % :count (count (:ids %))) (db/list-tags)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue