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 {
|
||||
{
|
||||
"title": "Updated from Bruno",
|
||||
"tags": ["code", "mock"]
|
||||
"title": "quick way to push last jj commit to git",
|
||||
"tags": ["jj", "git"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ meta {
|
|||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/api/snippets?limit=100&skip=0
|
||||
url: {{host}}/api/snippets?limit=25&skip=0
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
limit: 100
|
||||
limit: 25
|
||||
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
|
||||
: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]
|
||||
(fn [request]
|
||||
(update (handler request) :wrap (fnil conj '()) id)))
|
||||
|
|
@ -58,6 +63,7 @@
|
|||
mm/wrap-format
|
||||
[wrap :api]]}
|
||||
["/ping" {:get handle-ping}]
|
||||
["/tags" {:get handle-view-tags}]
|
||||
["/snippets" {:get handle-view-snippets}]
|
||||
["/snippet" {:post handle-create-snippet
|
||||
:get handle-view-snippet
|
||||
|
|
|
|||
|
|
@ -39,3 +39,6 @@
|
|||
(defn patch-snippet [id patch]
|
||||
(t/log! {:level :info, :data {:patch patch :id id}} "Patching snippet")
|
||||
(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]
|
||||
(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