summaryrefslogtreecommitdiff
path: root/lib/api/todos.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-11 16:04:42 -0300
committerRobert Schilling <rschilling@student.tugraz.at>2016-07-01 10:49:34 +0200
commita1f224d3f7b43bf2f58917e5045dcc2bdb33964d (patch)
treeef8559f8b042a87e377779a51b0badb43b31fe97 /lib/api/todos.rb
parentab81ea1e8177742a0dfed2c7cf922bb03a8b6c51 (diff)
downloadgitlab-ce-a1f224d3f7b43bf2f58917e5045dcc2bdb33964d.tar.gz
Add Todos API
Diffstat (limited to 'lib/api/todos.rb')
-rw-r--r--lib/api/todos.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
new file mode 100644
index 00000000000..f45c0ae634a
--- /dev/null
+++ b/lib/api/todos.rb
@@ -0,0 +1,54 @@
+module API
+ # Todos API
+ class Todos < Grape::API
+ before { authenticate! }
+
+ resource :todos do
+ helpers do
+ def find_todos
+ TodosFinder.new(current_user, params).execute
+ end
+ end
+
+ # Get a todo list
+ #
+ # Example Request:
+ # GET /todos
+ get do
+ @todos = find_todos
+ @todos = paginate @todos
+
+ present @todos, with: Entities::Todo
+ end
+
+ # Mark todo as done
+ #
+ # Parameters:
+ # id: (required) - The ID of the todo being marked as done
+ #
+ # Example Request:
+ #
+ # DELETE /todos/:id
+ #
+ delete ':id' do
+ @todo = current_user.todos.find(params[:id])
+ @todo.done
+
+ present @todo, with: Entities::Todo
+ end
+
+ # Mark all todos as done
+ #
+ # Example Request:
+ #
+ # DELETE /todos
+ #
+ delete do
+ @todos = find_todos
+ @todos.each(&:done)
+
+ present @todos, with: Entities::Todo
+ end
+ end
+ end
+end