BigW Consortium Gitlab

todos_controller.rb 694 Bytes
Newer Older
1
class Projects::TodosController < Projects::ApplicationController
2
  before_action :authenticate_user!, only: [:create]
3

Phil Hughes committed
4 5
  def create
    todo = TodoService.new.mark_todo(issuable, current_user)
6

7
    render json: {
8
      count: TodosFinder.new(current_user, state: :pending).execute.count,
Phil Hughes committed
9
      delete_path: dashboard_todo_path(todo)
10
    }
11 12 13
  end

  private
14

15 16 17 18
  def issuable
    @issuable ||= begin
      case params[:issuable_type]
      when "issue"
19
        IssuesFinder.new(current_user, project_id: @project.id).find(params[:issuable_id])
20
      when "merge_request"
21
        MergeRequestsFinder.new(current_user, project_id: @project.id).find(params[:issuable_id])
22 23 24 25
      end
    end
  end
end