fixed /list bug, wip docs
This commit is contained in:
parent
40c7fce965
commit
721610e16f
@ -93,9 +93,9 @@ class API extends Application
|
|||||||
|
|
||||||
local Paginator
|
local Paginator
|
||||||
if @params.done == nil
|
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
|
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!
|
num_pages = Paginator\num_pages!
|
||||||
if num_pages < @params.page
|
if num_pages < @params.page
|
||||||
@ -103,7 +103,7 @@ class API extends Application
|
|||||||
tasks = Paginator\get_page(@params.page)
|
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)
|
-- 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 =>
|
[random: "/random"]: api_request =>
|
||||||
assert_valid @params, {
|
assert_valid @params, {
|
||||||
|
@ -5,25 +5,25 @@ class Docs_1 extends Widget
|
|||||||
task_list = ->
|
task_list = ->
|
||||||
ul ->
|
ul ->
|
||||||
li ->
|
li ->
|
||||||
a href: "#new", "/new"
|
a href: "#new", "/v1/new"
|
||||||
text " { content: string }"
|
text " { content: string }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#get", "/get"
|
a href: "#get", "/v1/get"
|
||||||
text " { id: integer, content: string }"
|
text " { id: integer, content: string }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#do", "/do"
|
a href: "#do", "/v1/do"
|
||||||
text " { id: integer, content: string }"
|
text " { id: integer, content: string }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#undo", "/undo"
|
a href: "#undo", "/v1/undo"
|
||||||
text " { id: integer, content: string }"
|
text " { id: integer, content: string }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#delete", "/delete"
|
a href: "#delete", "/v1/delete"
|
||||||
text " { id: integer, content: string }"
|
text " { id: integer, content: string }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#list", "/list"
|
a href: "#list", "/v1/list"
|
||||||
text " { count: integer, done: boolean, page: integer, order: 'asc'/'desc' }"
|
text " { count: integer, done: boolean, page: integer, order: 'asc'/'desc' }"
|
||||||
li ->
|
li ->
|
||||||
a href: "#random", "/random"
|
a href: "#random", "/v1/random"
|
||||||
text " { count: integer, done: boolean }"
|
text " { count: integer, done: boolean }"
|
||||||
|
|
||||||
style -> raw "h3 { font-family: monospace; }"
|
style -> raw "h3 { font-family: monospace; }"
|
||||||
@ -38,9 +38,9 @@ class Docs_1 extends Widget
|
|||||||
a href: "#keys", "API Keys"
|
a href: "#keys", "API Keys"
|
||||||
ul ->
|
ul ->
|
||||||
li ->
|
li ->
|
||||||
a href: "#new-key", "/key/new"
|
a href: "#new-key", "/v1/key/new"
|
||||||
li ->
|
li ->
|
||||||
a href: "#delete-key", "/key/delete"
|
a href: "#delete-key", "/v1/key/delete"
|
||||||
text " { id: integer, key: string }"
|
text " { id: integer, key: string }"
|
||||||
|
|
||||||
a name: "auth"
|
a name: "auth"
|
||||||
@ -70,15 +70,15 @@ class Docs_1 extends Widget
|
|||||||
text "Version 1 of this API is extremely simple. POST "
|
text "Version 1 of this API is extremely simple. POST "
|
||||||
code '{ "content": "this is a todo item" }'
|
code '{ "content": "this is a todo item" }'
|
||||||
text " with valid authorization to "
|
text " with valid authorization to "
|
||||||
code "/new"
|
code "/v1/new"
|
||||||
text " to add tasks. The next four endpoints ("
|
text " to add tasks. The next four endpoints ("
|
||||||
code "/get"
|
code "/v1/get"
|
||||||
text ","
|
text ","
|
||||||
code "/do"
|
code "/v1/do"
|
||||||
text ","
|
text ","
|
||||||
code "/undo"
|
code "/v1/undo"
|
||||||
text ","
|
text ","
|
||||||
code "/delete"
|
code "/v1/delete"
|
||||||
text ") all use the same input to complete their operations (an "
|
text ") all use the same input to complete their operations (an "
|
||||||
code "id"
|
code "id"
|
||||||
text " integer or "
|
text " integer or "
|
||||||
@ -86,35 +86,61 @@ class Docs_1 extends Widget
|
|||||||
text " boolean)."
|
text " boolean)."
|
||||||
|
|
||||||
p ->
|
p ->
|
||||||
code "/list"
|
code "/v1/list"
|
||||||
text " and "
|
text " and "
|
||||||
code "/random"
|
code "/v1/random"
|
||||||
text " are a little more complex, and explained further below."
|
text " are a little more complex, and explained further below."
|
||||||
|
|
||||||
task_list!
|
task_list!
|
||||||
|
|
||||||
a name: "new"
|
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"
|
a name: "get"
|
||||||
|
h3 "/v1/get"
|
||||||
|
|
||||||
a name: "do"
|
a name: "do"
|
||||||
|
h3 "/v1/do"
|
||||||
|
|
||||||
a name: "undo"
|
a name: "undo"
|
||||||
|
h3 "/v1/undo"
|
||||||
|
|
||||||
a name: "delete"
|
a name: "delete"
|
||||||
|
h3 "/v1/delete"
|
||||||
|
|
||||||
a name: "list"
|
a name: "list"
|
||||||
|
h3 "/v1/list"
|
||||||
|
|
||||||
a name: "random"
|
a name: "random"
|
||||||
|
h3 "/v1/random"
|
||||||
|
|
||||||
a name: "keys"
|
a name: "keys"
|
||||||
h2 "API Keys"
|
h2 "API Keys"
|
||||||
|
|
||||||
a name: "new-key"
|
a name: "new-key"
|
||||||
|
h3 "/v1/key/new"
|
||||||
|
|
||||||
a name: "delete-key"
|
a name: "delete-key"
|
||||||
|
h3 "/v1/key/delete"
|
||||||
|
|
||||||
-- /list { count: #, done: bool, page: #, order: asc/desc } (if done not specified, returns all,
|
-- /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
|
-- 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)
|
-- /random { count: #, done: bool } (both args optional, defaults count 1, done false)
|
||||||
|
Loading…
Reference in New Issue
Block a user