Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-06-08 11:29:19 +0300
committerPhil Hughes <me@iamphill.com>2016-06-14 10:36:07 +0300
commit20d382a891d92197620eb4e72526577a916292d7 (patch)
treebf9dcaddb8c33e9d7c6e15f07a3ecef1d010933f /app/controllers/projects/todos_controller.rb
parentf8a8999a2069dedd9ca21bde2b726a077c057576 (diff)
Moved todo creation over to project todos controller
Diffstat (limited to 'app/controllers/projects/todos_controller.rb')
-rw-r--r--app/controllers/projects/todos_controller.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/projects/todos_controller.rb b/app/controllers/projects/todos_controller.rb
new file mode 100644
index 00000000000..21745977860
--- /dev/null
+++ b/app/controllers/projects/todos_controller.rb
@@ -0,0 +1,28 @@
+class Projects::TodosController < Projects::ApplicationController
+ def create
+ json_data = Hash.new
+
+ if params[:todo_id].nil?
+ TodoService.new.mark_todo(issuable, current_user)
+
+ json_data[:todo] = current_user.todos.find_by(state: :pending, action: Todo::MARKED, target_id: issuable.id)
+ else
+ current_user.todos.find_by_id(params[:todo_id]).update(state: :done)
+ end
+
+ render json: json_data.merge({ 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