summaryrefslogtreecommitdiff
path: root/lib/api/todos.rb
blob: f45c0ae634ab462d15436f9aabe7043bf20eee58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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