BigW Consortium Gitlab

Commit fbeaa751 by Rémy Coutable

Merge branch 'grapify-todos-api' into 'master'

Grapify todos API ## What does this MR do? Add the Grape-DSL to the todos API. ## What are the relevant issue numbers? Related to #22928 See merge request !6875
parents 35cd09d6 b927473c
......@@ -8,18 +8,19 @@ module API
'issues' => ->(id) { find_project_issue(id) }
}
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
ISSUABLE_TYPES.each do |type, finder|
type_id_str = "#{type.singularize}_id".to_sym
# Create a todo on an issuable
#
# Parameters:
# id (required) - The ID of a project
# issuable_id (required) - The ID of an issuable
# Example Request:
# POST /projects/:id/issues/:issuable_id/todo
# POST /projects/:id/merge_requests/:issuable_id/todo
desc 'Create a todo on an issuable' do
success Entities::Todo
end
params do
requires type_id_str, type: Integer, desc: 'The ID of an issuable'
end
post ":id/#{type}/:#{type_id_str}/todo" do
issuable = instance_exec(params[type_id_str], &finder)
todo = TodoService.new.mark_todo(issuable, current_user).first
......@@ -40,25 +41,21 @@ module API
end
end
# Get a todo list
#
# Example Request:
# GET /todos
#
desc 'Get a todo list' do
success Entities::Todo
end
get do
todos = find_todos
present paginate(todos), with: Entities::Todo, current_user: current_user
end
# Mark a todo as done
#
# Parameters:
# id: (required) - The ID of the todo being marked as done
#
# Example Request:
# DELETE /todos/:id
#
desc 'Mark a todo as done' do
success Entities::Todo
end
params do
requires :id, type: Integer, desc: 'The ID of the todo being marked as done'
end
delete ':id' do
todo = current_user.todos.find(params[:id])
TodoService.new.mark_todos_as_done([todo], current_user)
......@@ -66,11 +63,7 @@ module API
present todo.reload, with: Entities::Todo, current_user: current_user
end
# Mark all todos as done
#
# Example Request:
# DELETE /todos
#
desc 'Mark all todos as done'
delete do
todos = find_todos
TodoService.new.mark_todos_as_done(todos, current_user)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment