summaryrefslogtreecommitdiff
path: root/app/controllers/projects/todos_controller.rb
blob: a51bd5e2b499ff42a7c5c205a4bd212d7d4a4248 (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
class Projects::TodosController < Projects::ApplicationController
  def create
    todos = TodoService.new.mark_todo(issuable, current_user)

    render json: {
      todo: todos,
      count: current_user.todos.pending.count,
    }
  end

  def update
    current_user.todos.find_by_id(params[:id]).update(state: :done)

    render json: {
      count: current_user.todos.pending.count,
    }
  end

  private

  def issuable
    @issuable ||= begin
      case params[:issuable_type]
      when "issue"
        @project.issues.find(params[:issuable_id])
      when "merge_request"
        @project.merge_requests.find(params[:issuable_id])
      end
    end
  end
end