Skip to content

Commit

Permalink
Merge pull request #1608 from yeti-switch/specify-type-for-service-ap…
Browse files Browse the repository at this point in the history
…i-resource

1592, Customer API: specify service_type attribute for Service API resource
  • Loading branch information
dmitry-sinina authored Nov 11, 2024
2 parents 265fad8 + e7ff6c2 commit d8f75c0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/admin/billing/service_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
filter :name
filter :provisioning_class
filter :force_renew
filter :ui_type

index do
selectable_column
Expand All @@ -25,6 +26,7 @@
column :force_renew
column :provisioning_class
column :variables, :variables_json
column :ui_type
end

show do
Expand All @@ -39,6 +41,7 @@
link_to resource.services.count,
services_path(q: { type_id_eq: resource.id })
end
row :ui_type
end
end

Expand All @@ -58,6 +61,7 @@
f.input :name
f.input :force_renew
f.input :provisioning_class, as: :select, collection: Billing::ServiceType.available_provisioning_classes, input_html: { class: :chosen }
f.input :ui_type
f.input :variables_json, label: 'Variables', as: :text
end
f.actions
Expand Down
1 change: 1 addition & 0 deletions app/models/billing/service_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# force_renew :boolean default(FALSE), not null
# name :string not null
# provisioning_class :string
# ui_type :string
# variables :jsonb
#
# Indexes
Expand Down
5 changes: 5 additions & 0 deletions app/resources/api/rest/customer/v1/service_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Api::Rest::Customer::V1::ServiceResource < Api::Rest::Customer::V1::BaseRe
attribute :renew_at
attribute :renew_period
attribute :service_type
attribute :ui_type

has_one :account, class_name: 'Account', foreign_key_on: :related
has_many :transactions, class_name: 'Transaction', foreign_key_on: :related
Expand All @@ -31,6 +32,10 @@ def service_type
_model.type.name
end

def ui_type
_model.type.ui_type
end

def self.sortable_fields(_ctx = nil)
%i[id name initial_price renew_price created_at renew_at renew_period]
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ en:
lnp_routing_plan_lnp_rule:
drop_call_on_error: "Drop call if LNP resolve failed. When disabled routing will fallback to use destination number"
rewrite_call_destination: "use LRN as new call destination"
billing_service_type:
ui_type: "This field will be used in Service Resource of Customer API"


attributes:
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20241107212537_migration_add_ui_type_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class MigrationAddUiTypeField < ActiveRecord::Migration[7.0]
def change
add_column 'billing.service_types', :ui_type, :string
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31489,7 +31489,8 @@ CREATE TABLE billing.service_types (
name character varying NOT NULL,
provisioning_class character varying,
variables jsonb,
force_renew boolean DEFAULT false NOT NULL
force_renew boolean DEFAULT false NOT NULL,
ui_type character varying
);


Expand Down Expand Up @@ -41244,6 +41245,7 @@ INSERT INTO "public"."schema_migrations" (version) VALUES
('20241012124910'),
('20241015092015'),
('20241016075439'),
('20241017124729');
('20241017124729'),
('20241107212537');


2 changes: 2 additions & 0 deletions spec/factories/billing/service_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# force_renew :boolean default(FALSE), not null
# name :string not null
# provisioning_class :string
# ui_type :string
# variables :jsonb
#
# Indexes
Expand All @@ -19,5 +20,6 @@
sequence(:name) { |n| "Service Type #{n}" }
provisioning_class { 'Billing::Provisioning::Logging' }
variables { { 'foo' => 'bar' } }
ui_type { 'phone_systems' }
end
end
1 change: 1 addition & 0 deletions spec/models/billing/service_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# force_renew :boolean default(FALSE), not null
# name :string not null
# provisioning_class :string
# ui_type :string
# variables :jsonb
#
# Indexes
Expand Down

0 comments on commit d8f75c0

Please sign in to comment.