ubicloud/routes/web/project/vm.rb
Burak Yucesoy 2807697f49 Add helper class for Vm routes
The business logic in both web and api endpoints are combined in the helper
class. Currently the combination is made simply adding a branch for each option
and copying the business logic from each endpoint to their respective branches.
Rubocop also moved some common lines out of the branches, but other than that
the logic is exactly same. There is no change in any functionality. We did not
try to converge to single logic and eliminate the branches in this commit. This
is intentional as I wanted to keep this commit as boring and add a separate
commit with the more interesting convergence stuff.

In its current form, this commit does not provide much benefit and in fact it
increases the total line count. However it paves the way for making complex
improvements.
2024-08-21 18:19:54 +02:00

22 lines
581 B
Ruby

# frozen_string_literal: true
class CloverWeb
hash_branch(:project_prefix, "vm") do |r|
vm_endpoint_helper = Routes::Common::VmHelper.new(app: self, request: r, user: @current_user, location: nil, resource: nil)
r.get true do
vm_endpoint_helper.list
end
r.post true do
vm_endpoint_helper.instance_variable_set(:@location, LocationNameConverter.to_internal_name(r.params["location"]))
vm_endpoint_helper.post(r.params["name"])
end
r.on "create" do
r.get true do
vm_endpoint_helper.get_create
end
end
end
end