ubicloud/routes/web/project/postgres.rb
Burak Yucesoy 26c262ceee Combine business logic for Postgres resource creation endpoints
Most of the code is straightforward changes to merge the logic in two branches
in the postgres_helper. However there is one interesting bit where we set the
location at web/project/postgres.rb. This is because the API request for
resource creation already has location in the URL. However for web endpoints
the location is selected from the UI and cannot be dynamically put to the
form's action. due to csrf checks. So we need to set the location there.
2024-07-08 01:22:43 +02:00

26 lines
876 B
Ruby

# frozen_string_literal: true
class CloverWeb
hash_branch(:project_prefix, "postgres") do |r|
pg_endpoint_helper = Routes::Common::PostgresHelper.new(app: self, request: r, user: @current_user, location: nil, resource: nil)
r.get true do
pg_endpoint_helper.list
end
r.post true do
# API request for resource creation already has location in the URL.
# However for web endpoints the location is selected from the UI and
# cannot be dynamically put to the form's action. due to csrf checks.
# So we need to set the location here.
pg_endpoint_helper.instance_variable_set(:@location, LocationNameConverter.to_internal_name(r.params["location"]))
pg_endpoint_helper.post(name: r.params["name"])
end
r.on "create" do
r.get true do
pg_endpoint_helper.view_create_page
end
end
end
end