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

destroy_service.rb « lists « boards « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e12d4f46e19dcf2448b8b500c9c41fac95ea819f (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
# frozen_string_literal: true

module Boards
  module Lists
    class DestroyService < Boards::BaseService
      def execute(list)
        return false unless list.destroyable?

        @board = list.board

        list.with_lock do
          decrement_higher_lists(list)
          remove_list(list)
        end
      end

      private

      attr_reader :board

      def decrement_higher_lists(list)
        board.lists.movable.where('position > ?',  list.position)
                   .update_all('position = position - 1')
      end

      def remove_list(list)
        list.destroy
      end
    end
  end
end