fixed /list bug, wip docs

This commit is contained in:
Paul Liverman III 2018-04-24 22:20:16 -07:00
parent 40c7fce965
commit 721610e16f
2 changed files with 46 additions and 20 deletions

View File

@ -93,9 +93,9 @@ class API extends Application
local Paginator
if @params.done == nil
Paginator = Tasks\paginated "WHERE user_id = ? ORDER BY created_at ?", @user.id, @params.order, per_page: @params.count
Paginator = Tasks\paginated "WHERE user_id = ? ORDER BY created_at #{@params.order}", @user.id, per_page: @params.count
else
Paginator = Tasks\paginated "WHERE user_id = ? AND done = ? ORDER BY created_at ?", @user.id, @params.done, @params.order, per_page: @params.count
Paginator = Tasks\paginated "WHERE user_id = ? AND done = ? ORDER BY created_at #{@params.order}", @user.id, @params.done, per_page: @params.count
num_pages = Paginator\num_pages!
if num_pages < @params.page
@ -103,7 +103,7 @@ class API extends Application
tasks = Paginator\get_page(@params.page)
-- returns page in case it returned a different page than you asked for! (in the case you ask for a page beyond the end)
return json: { success: true, page: @params.page, :tasks }
return json: { success: true, page: @params.page, pages: num_pages, :tasks }
[random: "/random"]: api_request =>
assert_valid @params, {

View File

@ -5,25 +5,25 @@ class Docs_1 extends Widget
task_list = ->
ul ->
li ->
a href: "#new", "/new"
a href: "#new", "/v1/new"
text " { content: string }"
li ->
a href: "#get", "/get"
a href: "#get", "/v1/get"
text " { id: integer, content: string }"
li ->
a href: "#do", "/do"
a href: "#do", "/v1/do"
text " { id: integer, content: string }"
li ->
a href: "#undo", "/undo"
a href: "#undo", "/v1/undo"
text " { id: integer, content: string }"
li ->
a href: "#delete", "/delete"
a href: "#delete", "/v1/delete"
text " { id: integer, content: string }"
li ->
a href: "#list", "/list"
a href: "#list", "/v1/list"
text " { count: integer, done: boolean, page: integer, order: 'asc'/'desc' }"
li ->
a href: "#random", "/random"
a href: "#random", "/v1/random"
text " { count: integer, done: boolean }"
style -> raw "h3 { font-family: monospace; }"
@ -38,9 +38,9 @@ class Docs_1 extends Widget
a href: "#keys", "API Keys"
ul ->
li ->
a href: "#new-key", "/key/new"
a href: "#new-key", "/v1/key/new"
li ->
a href: "#delete-key", "/key/delete"
a href: "#delete-key", "/v1/key/delete"
text " { id: integer, key: string }"
a name: "auth"
@ -70,15 +70,15 @@ class Docs_1 extends Widget
text "Version 1 of this API is extremely simple. POST "
code '{ "content": "this is a todo item" }'
text " with valid authorization to "
code "/new"
code "/v1/new"
text " to add tasks. The next four endpoints ("
code "/get"
code "/v1/get"
text ","
code "/do"
code "/v1/do"
text ","
code "/undo"
code "/v1/undo"
text ","
code "/delete"
code "/v1/delete"
text ") all use the same input to complete their operations (an "
code "id"
text " integer or "
@ -86,35 +86,61 @@ class Docs_1 extends Widget
text " boolean)."
p ->
code "/list"
code "/v1/list"
text " and "
code "/random"
code "/v1/random"
text " are a little more complex, and explained further below."
task_list!
a name: "new"
h3 "/new"
h3 "/v1/new"
p ->
text "As stated above, just POST a "
code "content"
text " string with valid authorization and a task item will be returned. Here's an example item:"
blockquote ->
code '{ "id": 4, "user_id": 2, "content": "Get a new API key.", "done": false, "created_at": "", "updated_at": "" }'
-- "id", types.serial primary_key: true}
-- {"user_id", types.foreign_key}
-- {"content", types.text}
-- {"done", types.boolean default: false}
--
-- {"created_at", types.time}
-- {"updated_at", types.time}
a name: "get"
h3 "/v1/get"
a name: "do"
h3 "/v1/do"
a name: "undo"
h3 "/v1/undo"
a name: "delete"
h3 "/v1/delete"
a name: "list"
h3 "/v1/list"
a name: "random"
h3 "/v1/random"
a name: "keys"
h2 "API Keys"
a name: "new-key"
h3 "/v1/key/new"
a name: "delete-key"
h3 "/v1/key/delete"
-- /list { count: #, done: bool, page: #, order: asc/desc } (if done not specified, returns all,
-- default count is 50, default page is 1, default order is latest first
-- also returns page: #, pages: #, tasks: []
-- /random { count: #, done: bool } (both args optional, defaults count 1, done false)