Skip to content

Commit

Permalink
Merge pull request #6711 from vpereira/service_for_architectures_Cont…
Browse files Browse the repository at this point in the history
…roller

Move code to service
  • Loading branch information
vpereira committed Jan 7, 2019
2 parents a6239d2 + 82893df commit 788af86
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/api/app/controllers/webui/architectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ def index
end

def bulk_update_availability
all_valid = true
params[:archs].each do |name, value|
arch = Architecture.find_by(name: name)
arch.available = value
all_valid &&= arch.save
end
result = ::ArchitecturesControllerService::ArchitectureUpdater.new(params[:archs]).call

::Configuration.write_to_backend

respond_to do |format|
if all_valid
if result.valid?
format.html { redirect_to architectures_path, notice: 'Architectures successfully updated.' }
else
format.html { redirect_back(fallback_location: root_path, error: 'Not all architectures could be saved') }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ArchitecturesControllerService
class ArchitectureUpdater
def initialize(archs)
@archs = archs
@all_valid = true
end

def call
@archs.each do |name, value|
arch = Architecture.find_by(name: name)
arch.available = value
@all_valid &&= arch.save
end
self
end

def valid?
@all_valid
end
end
end

0 comments on commit 788af86

Please sign in to comment.