Browse Source

fixed /list bug, wip docs

Paul Liverman III 6 years ago
parent
commit
721610e16f
2 changed files with 46 additions and 20 deletions
  1. 3
    3
      applications/api.moon
  2. 43
    17
      views/docs/v1.moon

+ 3
- 3
applications/api.moon View File

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

+ 43
- 17
views/docs/v1.moon View File

@@ -5,25 +5,25 @@ class Docs_1 extends Widget
5 5
     task_list = ->
6 6
       ul ->
7 7
         li ->
8
-          a href: "#new", "/new"
8
+          a href: "#new", "/v1/new"
9 9
           text " { content: string }"
10 10
         li ->
11
-          a href: "#get", "/get"
11
+          a href: "#get", "/v1/get"
12 12
           text " { id: integer, content: string }"
13 13
         li ->
14
-          a href: "#do", "/do"
14
+          a href: "#do", "/v1/do"
15 15
           text " { id: integer, content: string }"
16 16
         li ->
17
-          a href: "#undo", "/undo"
17
+          a href: "#undo", "/v1/undo"
18 18
           text " { id: integer, content: string }"
19 19
         li ->
20
-          a href: "#delete", "/delete"
20
+          a href: "#delete", "/v1/delete"
21 21
           text " { id: integer, content: string }"
22 22
         li ->
23
-          a href: "#list", "/list"
23
+          a href: "#list", "/v1/list"
24 24
           text " { count: integer, done: boolean, page: integer, order: 'asc'/'desc' }"
25 25
         li ->
26
-          a href: "#random", "/random"
26
+          a href: "#random", "/v1/random"
27 27
           text " { count: integer, done: boolean }"
28 28
 
29 29
     style -> raw "h3 { font-family: monospace; }"
@@ -38,9 +38,9 @@ class Docs_1 extends Widget
38 38
         a href: "#keys", "API Keys"
39 39
         ul ->
40 40
           li ->
41
-            a href: "#new-key", "/key/new"
41
+            a href: "#new-key", "/v1/key/new"
42 42
           li ->
43
-            a href: "#delete-key", "/key/delete"
43
+            a href: "#delete-key", "/v1/key/delete"
44 44
             text " { id: integer, key: string }"
45 45
 
46 46
     a name: "auth"
@@ -70,15 +70,15 @@ class Docs_1 extends Widget
70 70
       text "Version 1 of this API is extremely simple. POST "
71 71
       code '{ "content": "this is a todo item" }'
72 72
       text " with valid authorization to "
73
-      code "/new"
73
+      code "/v1/new"
74 74
       text " to add tasks. The next four endpoints ("
75
-      code "/get"
75
+      code "/v1/get"
76 76
       text ","
77
-      code "/do"
77
+      code "/v1/do"
78 78
       text ","
79
-      code "/undo"
79
+      code "/v1/undo"
80 80
       text ","
81
-      code "/delete"
81
+      code "/v1/delete"
82 82
       text ") all use the same input to complete their operations (an "
83 83
       code "id"
84 84
       text " integer or "
@@ -86,35 +86,61 @@ class Docs_1 extends Widget
86 86
       text " boolean)."
87 87
 
88 88
     p ->
89
-      code "/list"
89
+      code "/v1/list"
90 90
       text " and "
91
-      code "/random"
91
+      code "/v1/random"
92 92
       text " are a little more complex, and explained further below."
93 93
 
94 94
     task_list!
95 95
 
96 96
     a name: "new"
97
-    h3 "/new"
97
+    h3 "/v1/new"
98
+
99
+    p ->
100
+      text "As stated above, just POST a "
101
+      code "content"
102
+      text " string with valid authorization and a task item will be returned. Here's an example item:"
103
+
104
+    blockquote ->
105
+      code '{ "id": 4, "user_id": 2, "content": "Get a new API key.", "done": false, "created_at": "", "updated_at": "" }'
106
+
107
+
108
+        -- "id", types.serial primary_key: true}
109
+        -- {"user_id", types.foreign_key}
110
+        -- {"content", types.text}
111
+        -- {"done", types.boolean default: false}
112
+        --
113
+        -- {"created_at", types.time}
114
+        -- {"updated_at", types.time}
98 115
 
99 116
     a name: "get"
117
+    h3 "/v1/get"
100 118
 
101 119
     a name: "do"
120
+    h3 "/v1/do"
102 121
 
103 122
     a name: "undo"
123
+    h3 "/v1/undo"
104 124
 
105 125
     a name: "delete"
126
+    h3 "/v1/delete"
106 127
 
107 128
     a name: "list"
129
+    h3 "/v1/list"
108 130
 
109 131
     a name: "random"
132
+    h3 "/v1/random"
110 133
 
111 134
     a name: "keys"
112 135
     h2 "API Keys"
113 136
 
114 137
     a name: "new-key"
138
+    h3 "/v1/key/new"
115 139
 
116 140
     a name: "delete-key"
141
+    h3 "/v1/key/delete"
117 142
 
118 143
 -- /list { count: #, done: bool, page: #, order: asc/desc } (if done not specified, returns all,
119 144
 --                        default count is 50, default page is 1, default order is latest first
145
+-- also returns page: #, pages: #, tasks: []
120 146
 -- /random { count: #, done: bool } (both args optional, defaults count 1, done false)