summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard/todos_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/dashboard/todos_controller.rb')
-rw-r--r--app/controllers/dashboard/todos_controller.rb25
1 files changed, 10 insertions, 15 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index f9a1929c117..3a2db3e6eeb 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -1,44 +1,39 @@
class Dashboard::TodosController < Dashboard::ApplicationController
- before_action :find_todos, only: [:index, :destroy, :destroy_all]
+ include TodosHelper
+
+ before_action :find_todos, only: [:index, :destroy_all]
def index
@todos = @todos.page(params[:page])
end
def destroy
- todo.done
-
- todo_notice = 'Todo was successfully marked as done.'
+ TodoService.new.mark_todos_as_done([todo], current_user)
respond_to do |format|
- format.html { redirect_to dashboard_todos_path, notice: todo_notice }
+ format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
format.js { head :ok }
- format.json do
- render json: { count: @todos.size, done_count: current_user.todos.done.count }
- end
+ format.json { render json: { count: todos_pending_count, done_count: todos_done_count } }
end
end
def destroy_all
- @todos.each(&:done)
+ TodoService.new.mark_todos_as_done(@todos, current_user)
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
format.js { head :ok }
- format.json do
- find_todos
- render json: { count: @todos.size, done_count: current_user.todos.done.count }
- end
+ format.json { render json: { count: todos_pending_count, done_count: todos_done_count } }
end
end
private
def todo
- @todo ||= current_user.todos.find(params[:id])
+ @todo ||= find_todos.find(params[:id])
end
def find_todos
- @todos = TodosFinder.new(current_user, params).execute
+ @todos ||= TodosFinder.new(current_user, params).execute
end
end