2016-07-27 21:32:36 -04:00
|
|
|
module Boards
|
|
|
|
module Lists
|
2016-10-07 15:46:32 -04:00
|
|
|
class DestroyService < BaseService
|
2016-08-16 00:07:25 -04:00
|
|
|
def execute(list)
|
2016-08-16 10:31:21 -04:00
|
|
|
return false unless list.destroyable?
|
2016-07-28 00:54:13 -04:00
|
|
|
|
2016-10-05 18:24:42 -04:00
|
|
|
@board = list.board
|
|
|
|
|
2016-07-27 21:32:36 -04:00
|
|
|
list.with_lock do
|
2016-08-16 00:07:25 -04:00
|
|
|
decrement_higher_lists(list)
|
|
|
|
remove_list(list)
|
2016-07-27 21:32:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-10-05 18:24:42 -04:00
|
|
|
attr_reader :board
|
|
|
|
|
2016-08-16 00:07:25 -04:00
|
|
|
def decrement_higher_lists(list)
|
2016-08-16 13:38:43 -04:00
|
|
|
board.lists.movable.where('position > ?', list.position)
|
2016-07-28 18:26:16 -04:00
|
|
|
.update_all('position = position - 1')
|
2016-07-27 21:32:36 -04:00
|
|
|
end
|
|
|
|
|
2016-08-16 00:07:25 -04:00
|
|
|
def remove_list(list)
|
2016-07-27 21:32:36 -04:00
|
|
|
list.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|