TT#128605 implement dynamic fields expand

* add API functionality to request additional data
  and expand fields in GET methods
* syntax:
   - /api/resource/?expand=all - expands all expandable fields
     e.g.: customer_id field is expanded and customer internally
     is queried and returned under "customer" => {...}
     (the returned data is identical to what /api/customers/id
      would return)
   - /api/resource/?expand=reseller_id,customer_id - expands
     only reseller_id and customer_id fields, if they are expandable
   - /api/resource/?expand=reseller_id,invalidfield_id -
     returns the data and expands only fields that are expandable
     (reseller_id in this case) but if it finds either unknown
     fields or non-expandable fields, changes HTTP status code
     to "409 Conflict"
* adapt all API endpoints to support dynamic expand fields expanding
  functionality, however the actual expand for them requires modifying
  the form fields in the following format:
  has_field 'contact_id' => (
      element_attr => {
        expand => {
            class    => 'NGCP::Panel::Role::API::CustomerContacts',
            id_field => 'contact_id',
            alias    => 'contact',
            fetch    => 0,
        },
    },
  );
  - class - represents the class that should be used by the logic
    to fetch the relevant data
  - id_field - which field from the resource needs to be expanded,
    it should be the "id" field (subscriber_id, domain_id, etc.)
  - alias - (optional), under which key the fetched data is stored.
    the field name is used as the key if the option is omitted.
  - fetch - (optional), if the returned data is under
    $data->{contract_id} then it will be fetched from there and
    stored under the key (field name or alias), otherwise the whole
    retreived data is stored under the key (field name or alias)
* adapt /api/autoattendants to use the new approach (old one was expand=1)
* currently supported endpoints with expand:
  - admins
  - autoattendants
  - domains
  - customers
  - customercontacts
  - resellers
  - subscribers

Change-Id: Iac53409dad944ed4794039a48dc3a9f6dce25bc1
mr10.0
Kirill Solomko 5 years ago
parent f48ec2dfab
commit 2b144caf2c

@ -8,6 +8,12 @@ has_field 'reseller' => (
type => '+NGCP::Panel::Field::Reseller',
label => 'Reseller',
validate_when_empty => 1,
element_attr => {
expand => {
class => 'NGCP::Panel::Role::API::Resellers',
id_field => 'reseller_id',
},
},
);
has_block 'fields' => (
tag => 'div',

@ -8,7 +8,11 @@ has_field 'reseller' => (
validate_when_empty => 1,
element_attr => {
rel => ['tooltip'],
title => ['The reseller id this contact belongs to.']
title => ['The reseller id this contact belongs to.'],
expand => {
class => 'NGCP::Panel::Role::API::Resellers',
id_field => 'reseller_id',
},
},
);

@ -8,7 +8,12 @@ has_field 'contact_id' => (
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The contact id this contract belongs to.']
title => ['The contact id this contract belongs to.'],
expand => {
class => 'NGCP::Panel::Role::API::CustomerContacts',
id_field => 'contact_id',
alias => 'contact',
},
},
);
@ -17,7 +22,12 @@ has_field 'billing_profile_id' => (
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The billing profile id used to charge this contract, which will become active immediately. This field is required if the profile definition mode is not defined or the \'id\' mode is used.']
title => ['The billing profile id used to charge this contract, which will become active immediately. This field is required if the profile definition mode is not defined or the \'id\' mode is used.'],
expand => {
class => 'NGCP::Panel::Role::API::BillingProfiles',
id_field => 'billing_profile_id',
alias => 'billing_profile',
},
},
);

@ -8,7 +8,11 @@ has_field 'reseller' => (
validate_when_empty => 1,
element_attr => {
rel => ['tooltip'],
title => ['The reseller id to assign this domain to.']
title => ['The reseller id to assign this domain to.'],
expand => {
class => 'NGCP::Panel::Role::API::Resellers',
id_field => 'reseller_id',
},
},
);

@ -16,7 +16,11 @@ has_field 'contract' => (
validate_when_empty => 1,
element_attr => {
rel => ['tooltip'],
title => ['The contract used for this reseller.']
title => ['The contract used for this reseller.'],
expand => {
class => 'NGCP::Panel::Role::API::Contracts',
id_field => 'contract_id',
},
},
);

@ -91,6 +91,10 @@ has_field 'domain' => (
title => ['The domain name this subscriber belongs to.'],
},
},
expand => {
class => 'NGCP::Panel::Role::API::Domains',
id_field => 'domain_id',
},
},
);

@ -61,6 +61,14 @@ has_block 'fields' => (
has_field 'subscriber_id' => (
type => '+NGCP::Panel::Field::PosInteger',
element_attr => {
expand => {
class => 'NGCP::Panel::Role::API::Subscribers',
alias => 'subscriber',
id_field => 'subscriber_id',
remove_fields => [qw(password webpassword)],
},
},
);
sub validate_slots_destination {

@ -12,7 +12,13 @@ has_field 'customer_id' => (
validate_when_empty => 1,
element_attr => {
rel => ['tooltip'],
title => ['The contract used for this subscriber.']
title => ['The contract used for this subscriber.'],
expand => {
class => 'NGCP::Panel::Role::API::Customers',
alias => 'customer',
id_field => 'customer_id',
fetch => 0,
},
},
);

@ -1272,10 +1272,57 @@ sub hal_from_item {
}
$resource->{id} = $self->get_item_id($c, $item);
$resource = $self->post_process_hal_resource($c, $item, $resource, $form);
$self->expand_fields($c, $resource);
$hal->resource({%$resource});
return $hal;
}
sub expand_fields {
my ($self, $c, $resource) = @_;
my $expand_param = $c->req->param('expand') // return 1;
my $all = $expand_param eq 'all' ? 1 : 0;
my @expand_fields = split /,/, $expand_param;
my @found_fields = ();
my $resource_form = $self->get_form($c);
return unless $resource_form;
foreach my $field ($resource_form->fields) {
my $attr = $field->element_attr;
my $expand = $attr->{expand} // next;
my $alias = $expand->{alias} // $field->name;
my $class = $expand->{class} // next;
my $id_field = $expand->{id_field} // next;
my $fetch = $expand->{fetch} // 0;
my $id = $resource->{$id_field} // next;
next unless $all || grep { /^$id_field$/ } @expand_fields;
my $form = $class->get_form($c) // next;
my $item = $class->item_by_id($c, $id) // next;
my $data = $class->resource_from_item($c, $item, $form);
$data = $class->post_process_hal_resource($c, $item, $data, $form);
push @found_fields, $id_field;
if (my $remove_fields = $expand->{remove_fields}) {
delete @{$data}{@{$remove_fields}};
}
if ($fetch && $data->{$id_field}) {
$resource->{$alias} = $data->{$id_field};
} else {
$resource->{$alias} = $data;
}
}
unless ($all || $#expand_fields == $#found_fields) {
$c->log->debug("Provided expand fields are invalid");
$self->error($c, HTTP_CONFLICT, "Provided expand fields are invalid");
return;
}
return 1;
}
sub get_mandatory_params {
my ($self, $c, $href_type, $item, $resource, $params) = @_;
#href type - item or collection

@ -18,12 +18,28 @@ sub get_form {
return NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::AutoAttendantAPI", $c);
}
sub hal_from_item {
my ($self, $c, $item) = @_;
sub resource_from_item {
my ($self, $c, $item, $form) = @_;
my $p_subs = $item->provisioning_voip_subscriber;
my $resource = { subscriber_id => $item->id, slots => $self->_autoattendants_from_subscriber($p_subs) };
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
run => 0,
);
return $resource;
}
sub hal_from_item {
my ($self, $c, $item) = @_;
my $resource = $self->resource_from_item($c, $item);
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
@ -42,22 +58,7 @@ sub hal_from_item {
relation => 'ngcp:'.$self->resource_name,
);
my $form = $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
run => 0,
);
if ($c->req->param('expand') && is_int($c->req->param('expand')) && $c->req->param('expand') == 1) {
my $subscriber_form = NGCP::Panel::Role::API::Subscribers->get_form($c);
$resource->{subscriber} = NGCP::Panel::Role::API::Subscribers->resource_from_item($c, $item, $subscriber_form);
#don't show passwords here
delete $resource->{subscriber}->{webpassword};
delete $resource->{subscriber}->{password};
}
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -135,6 +135,7 @@ sub hal_from_balance {
);
#$resource{id} = int($item->contract->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -71,6 +71,8 @@ sub hal_from_fee {
$resource{id} = int($fee->id);
$resource{billing_profile_id} = int($fee->billing_profile_id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -61,6 +61,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -91,6 +91,7 @@ sub hal_from_item {
relation => 'ngcp:'.$self->resource_name,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -72,6 +72,8 @@ sub hal_from_zone {
$resource{id} = int($zone->id);
$resource{billing_profile_id} = int($zone->billing_profile_id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -61,6 +61,7 @@ sub hal_from_item {
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -73,6 +73,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -96,6 +96,8 @@ sub hal_from_item {
);
$resource->{cft_ringtimeout} = $ringtimeout_preference;
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -65,6 +65,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -342,6 +342,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -79,6 +79,7 @@ sub hal_from_item {
}
}
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -146,6 +146,8 @@ sub hal_from_item {
);
my $resource = $self->resource_from_item($c, $item, $form);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -94,6 +94,8 @@ sub hal_from_item {
);
my $resource = $self->resource_from_item($c, $item, $form);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -67,6 +67,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -37,20 +37,45 @@ sub get_form {
return NGCP::Panel::Form::get("NGCP::Panel::Form::Contract::ContractAPI", $c);
}
sub hal_from_contract {
my ($self, $c, $contract, $form, $now) = @_;
sub resource_from_item {
my ($self, $c, $item, $form, $now) = @_;
my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $contract, );
my %resource = $item->get_inflated_columns;
$now //= NGCP::Panel::Utils::DateTime::current_local;
my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $item, );
my $billing_profile_id = $billing_mapping->billing_profile->id;
my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($contract);
my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($contract);
my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($item);
my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($item);
#contract balances are created with GET api/contracts/4711
NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $contract,
contract => $item,
now => $now);
my %resource = $contract->get_inflated_columns;
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$resource{type} = $item->product->class;
$resource{billing_profiles} = $future_billing_profiles;
$resource{all_billing_profiles} = $billing_profiles;
$resource{id} = int($item->id);
$resource{billing_profile_id} = $billing_profile_id ? int($billing_profile_id) : undef;
$resource{billing_profile_definition} = 'id';
return \%resource;
}
sub hal_from_contract {
my ($self, $c, $contract, $form, $now) = @_;
my $resource = $self->resource_from_item($c, $contract, $form, $now);
my @profile_links = ();
my @network_links = ();
@ -81,22 +106,8 @@ sub hal_from_contract {
relation => 'ngcp:'.$self->resource_name,
);
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$resource{type} = $contract->product->class;
$resource{billing_profiles} = $future_billing_profiles;
$resource{all_billing_profiles} = $billing_profiles;
$resource{id} = int($contract->id);
$resource{billing_profile_id} = $billing_profile_id ? int($billing_profile_id) : undef;
$resource{billing_profile_definition} = 'id';
$hal->resource({%resource});
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -74,6 +74,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->contract->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -40,9 +40,33 @@ sub get_form {
}
}
sub resource_from_item {
my ($self, $c, $item, $form) = @_;
my %resource = $item->get_inflated_columns;
$resource{country}{id} = delete $resource{country};
$resource{timezone}{name} = delete $resource{timezone};
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{id} = int($item->id);
$resource{country} = $resource{country}{id};
$resource{timezone} = $resource{timezone}{name};
return \%resource;
}
sub hal_from_contact {
my ($self, $c, $contact, $form) = @_;
my %resource = $contact->get_inflated_columns;
my $resource = $self->resource_from_item($c, $contact, $form);
my $hal = Data::HAL->new(
links => [
@ -60,20 +84,8 @@ sub hal_from_contact {
relation => 'ngcp:'.$self->resource_name,
);
$resource{country}{id} = delete $resource{country};
$resource{timezone}{name} = delete $resource{timezone};
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{country} = $resource{country}{id};
$resource{timezone} = $resource{timezone}{name};
$resource{id} = int($contact->id);
$hal->resource({%resource});
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -48,6 +48,7 @@ sub hal_from_item {
run => 0,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -60,6 +60,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -51,6 +51,8 @@ sub hal_from_item {
my $resource = $self->resource_from_item($c, $item);
return unless $resource;
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -34,6 +34,46 @@ sub get_form {
return NGCP::Panel::Form::get("NGCP::Panel::Form::Contract::CustomerAPI", $c);
}
sub resource_from_item {
my ($self, $c, $item, $form, $now) = @_;
my %resource = $item->get_inflated_columns;
$now //= NGCP::Panel::Utils::DateTime::current_local;
my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $item);
my $billing_profile_id = $billing_mapping->billing_profile->id;
my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($item);
my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($item);
NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $item,
now => $now);
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
foreach my $field (qw/create_timestamp activate_timestamp modify_timestamp terminate_timestamp/) {
$resource{$field} = defined $resource{$field}
? NGCP::Panel::Utils::DateTime::to_string(NGCP::Panel::Utils::DateTime::from_string($resource{$field}))
: undef;
}
# return the virtual "type" instead of the actual product id
$resource{type} = $item->product->class; #$billing_mapping->product->class;
$resource{billing_profiles} = $future_billing_profiles;
$resource{all_billing_profiles} = $billing_profiles;
$resource{id} = int($item->id);
$resource{billing_profile_id} = int($billing_profile_id);
$resource{billing_profile_definition} = 'id';
return \%resource;
}
sub hal_from_customer {
my ($self, $c, $customer, $form, $now) = @_;
@ -43,16 +83,7 @@ sub hal_from_customer {
$is_adm = 1;
}
my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $customer, );
my $billing_profile_id = $billing_mapping->billing_profile->id;
my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($customer);
my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($customer);
NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $customer,
now => $now);
my %resource = $customer->get_inflated_columns;
my $resource = $self->resource_from_item($c, $customer, $form, $now);
my @profile_links = ();
my @network_links = ();
@ -96,26 +127,8 @@ sub hal_from_customer {
relation => 'ngcp:'.$self->resource_name,
);
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
foreach my $field (qw/create_timestamp activate_timestamp modify_timestamp terminate_timestamp/){
$resource{$field} = defined $resource{$field} ? NGCP::Panel::Utils::DateTime::to_string(NGCP::Panel::Utils::DateTime::from_string($resource{$field})) : undef ;
}
# return the virtual "type" instead of the actual product id
$resource{type} = $customer->product->class; #$billing_mapping->product->class;
$resource{billing_profiles} = $future_billing_profiles;
$resource{all_billing_profiles} = $billing_profiles;
$resource{id} = int($customer->id);
$resource{billing_profile_id} = int($billing_profile_id);
$resource{billing_profile_definition} = 'id';
$hal->resource({%resource});
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -22,10 +22,34 @@ sub get_form {
return;
}
sub hal_from_item {
sub resource_from_item {
my ($self, $c, $item, $form) = @_;
my %resource = $item->get_inflated_columns;
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{id} = int($item->id);
if ($c->user->roles eq "admin" && $item->domain_resellers->first) {
$resource{reseller_id} = int($item->domain_resellers->first->reseller_id)
}
return \%resource;
}
sub hal_from_item {
my ($self, $c, $item, $form) = @_;
my $resource = $self->resource_from_item($c, $item, $form);
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(
@ -44,73 +68,8 @@ sub hal_from_item {
relation => 'ngcp:'.$self->resource_name,
);
$form //= $self->get_form($c);
$self->validate_form(
c => $c,
resource => \%resource,
form => $form,
run => 0,
);
$resource{id} = int($item->id);
if($c->user->roles eq "admin") {
$resource{reseller_id} =
int($item->domain_resellers->first->reseller_id)
if($item->domain_resellers->first);
} elsif($c->user->roles eq "reseller") {
}
=pod
# TODO: do we really want to provide this info, as you can't actually
# PUT/PATCH/POST it? Or should you?
$resource{preferences} = {};
foreach my $pref($item->provisioning_voip_domain->voip_dom_preferences->all) {
next if($pref->attribute->internal);
my $plain = { "boolean" => 1, "int" => 1, "string" => 1 };
if(exists $plain->{$pref->attribute->data_type}) {
# plain key/value pairs
my $value;
SWITCH: for ($pref->attribute->data_type) {
/^int$/ && do {
$value = int($pref->value);
last SWITCH;
};
/^boolean$/ && do {
$value = JSON::Types::bool($pref->value);
last SWITCH;
};
# default
$value = $pref->value;
} # SWITCH
if($pref->attribute->max_occur != 1) {
$resource{preferences}{$pref->attribute->attribute} = $value;
} else {
$resource{preferences}{$pref->attribute->attribute} = []
unless(exists $resource{preferences}{$pref->attribute->attribute});
push @{ $resource{preferences}{$pref->attribute->attribute} }, $value;
}
} else {
# enum mappings
my $value;
SWITCH: for ($pref->attribute->data_type) {
/^int$/ && do {
$value = int($pref->value);
last SWITCH;
};
/^boolean$/ && do {
$value = JSON::Types::bool($pref->value);
last SWITCH;
};
# default
$value = $pref->value;
} # SWITCH
$resource{preferences}{$pref->attribute->attribute} = $value;
}
}
=cut
$hal->resource({%resource});
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -61,6 +61,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -66,6 +66,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -60,6 +60,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -107,6 +107,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -53,6 +53,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -61,6 +61,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -53,6 +53,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -86,7 +86,9 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->post_process_hal_resource($c, $item, \%resource, $form);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -65,6 +65,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -74,6 +74,7 @@ sub hal_from_item {
run => 0,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -62,6 +62,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -55,6 +55,8 @@ sub hal_from_item {
$resource{id} = int($item->id);
$resource{carrier_id} = int($item->lnp_provider_id);
delete $resource{lnp_provider_id};
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -64,6 +64,8 @@ sub hal_from_item {
$resource->{id} = int($item->id);
delete $resource->{data};
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -63,6 +63,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -41,6 +41,8 @@ sub hal_from_item {
);
my $resource = $self->resource_from_item($c, $item);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -41,6 +41,7 @@ sub hal_from_item {
);
my $resource = $self->resource_from_item($c, $item);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -59,6 +59,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -53,6 +53,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -53,6 +53,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -53,6 +53,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -45,6 +45,8 @@ sub hal_from_item {
);
my $resource = $self->get_resource($c, $item, $type);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -81,6 +81,8 @@ sub hal_from_item {
resource => \%resource,
run => 0,
);
$self->expand_fields($c, \%resource);
$hal->resource(\%resource);
return $hal;
}

@ -87,6 +87,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -25,15 +25,30 @@ sub get_form {
return NGCP::Panel::Form::get("NGCP::Panel::Form::ResellerAPI", $c);
}
sub resource_from_item {
my ($self, $c, $item, $form) = @_;
my %resource = $item->get_inflated_columns;
$resource{enable_rtc} = $item->rtc_user ? JSON::true : JSON::false;
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$resource{id} = int($item->id);
return \%resource;
}
sub hal_from_reseller {
my ($self, $c, $reseller, $form) = @_;
my %resource = $reseller->get_inflated_columns;
if ($reseller->rtc_user) {
$resource{enable_rtc} = JSON::true;
} else {
$resource{enable_rtc} = JSON::false;
}
my $resource = $self->resource_from_item($c, $reseller, $form);
# TODO: we should return the relations in embedded fields,
# if the structure is returned for one single item
@ -61,16 +76,8 @@ sub hal_from_reseller {
relation => 'ngcp:'.$self->resource_name,
);
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => \%resource,
run => 0,
);
$resource{id} = int($reseller->id);
$hal->resource({%resource});
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -70,6 +70,7 @@ sub hal_from_item {
);
}
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -70,6 +70,7 @@ sub hal_from_item {
);
}
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -64,6 +64,7 @@ sub hal_from_item {
relation => 'ngcp:'.$self->resource_name,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -98,6 +98,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -54,6 +54,7 @@ sub hal_from_item {
run => 0,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -62,6 +62,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -62,6 +62,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -64,6 +64,8 @@ sub hal_from_item {
$resource->{attributes} = delete $resource->{attribute};
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -166,6 +166,7 @@ sub hal_from_item {
$resource->{id} = ($item->id =~ /^\d+$/) ? int($item->id) : $item->id;
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -266,6 +266,7 @@ sub hal_from_item {
relation => 'ngcp:'.$self->resource_name,
);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -64,6 +64,8 @@ sub hal_from_contact {
$resource{timezone} = $resource{timezone}{name};
$resource{id} = int($contact->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -81,6 +81,8 @@ sub hal_from_item {
);
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

@ -64,6 +64,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -69,6 +69,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -73,6 +73,8 @@ sub hal_from_item {
);
$resource->{id} = int($item->provisioning_voip_subscriber->voip_subscriber->id);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -69,6 +69,7 @@ sub hal_from_item {
);
my $resource = $self->resource_from_item($c, $item, $form);
$self->expand_fields($c, $resource);
$hal->resource($resource);
return $hal;
}

@ -68,6 +68,8 @@ sub hal_from_item {
delete $resource{code};
}
$resource{id} = int($item->id);
$self->expand_fields($c, \%resource);
$hal->resource({%resource});
return $hal;
}

Loading…
Cancel
Save