BigW Consortium Gitlab

todos.rb 816 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
module API
  module V3
    class Todos < Grape::API
      before { authenticate! }

      resource :todos do
        desc 'Mark a todo as done' do
          success ::API::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])
15
          TodoService.new.mark_todos_as_done([todo], current_user)
16

17
          present todo.reload, with: ::API::Entities::Todo, current_user: current_user
18 19 20 21
        end

        desc 'Mark all todos as done'
        delete do
Robert Schilling committed
22
          status(200)
23

24
          todos = TodosFinder.new(current_user, params).execute
25
          TodoService.new.mark_todos_as_done(todos, current_user).size
26 27 28 29 30
        end
      end
    end
  end
end