From 46f30fa2be16451262b39015f7263bc482021074 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Fri, 13 Apr 2018 15:13:12 +0200 Subject: [PATCH] TT#35714 use collection_nav_links in all API controllers * colelction_nav_links() should be used instead of the old self/prev/next href link code * Entities.pm fix colletion_nav_links() to pass missing $c->request->params * collection_nav_links() use default $c->request->path and $c->request->params if those arguments are not specified Change-Id: Icca5afac812f2e06e6927ba6f4e91057f9745d21 (cherry picked from commit f976fe03fbea3f1109b727391f4883478ed36936) --- lib/NGCP/Panel/Controller/API/AutoAttendants.pm | 8 +------- lib/NGCP/Panel/Controller/API/BalanceIntervals.pm | 5 ++--- .../Panel/Controller/API/BalanceIntervalsItem.pm | 5 ++--- lib/NGCP/Panel/Controller/API/BillingFees.pm | 9 +-------- lib/NGCP/Panel/Controller/API/BillingNetworks.pm | 5 ++--- lib/NGCP/Panel/Controller/API/BillingProfiles.pm | 9 +-------- lib/NGCP/Panel/Controller/API/BillingZones.pm | 9 +-------- lib/NGCP/Panel/Controller/API/CCMapEntries.pm | 8 +------- lib/NGCP/Panel/Controller/API/CFDestinationSets.pm | 8 +------- lib/NGCP/Panel/Controller/API/CFMappings.pm | 8 +------- lib/NGCP/Panel/Controller/API/CFSourceSets.pm | 8 +------- lib/NGCP/Panel/Controller/API/CFTimeSets.pm | 8 +------- lib/NGCP/Panel/Controller/API/CallForwards.pm | 8 +------- lib/NGCP/Panel/Controller/API/CallLists.pm | 8 +------- .../Panel/Controller/API/CallRecordingStreams.pm | 8 +------- lib/NGCP/Panel/Controller/API/CallRecordings.pm | 8 +------- lib/NGCP/Panel/Controller/API/Calls.pm | 8 +------- lib/NGCP/Panel/Controller/API/Capabilities.pm | 8 +------- lib/NGCP/Panel/Controller/API/Contracts.pm | 14 ++------------ lib/NGCP/Panel/Controller/API/CustomerBalances.pm | 12 ++---------- lib/NGCP/Panel/Controller/API/CustomerContacts.pm | 8 +------- .../Panel/Controller/API/CustomerFraudEvents.pm | 9 +-------- .../Controller/API/CustomerFraudPreferences.pm | 5 ++--- lib/NGCP/Panel/Controller/API/CustomerLocations.pm | 5 ++--- .../Panel/Controller/API/CustomerPreferences.pm | 8 +------- lib/NGCP/Panel/Controller/API/CustomerZoneCosts.pm | 10 +--------- lib/NGCP/Panel/Controller/API/Customers.pm | 5 ++--- lib/NGCP/Panel/Controller/API/DomainPreferences.pm | 8 +------- lib/NGCP/Panel/Controller/API/Domains.pm | 8 +------- lib/NGCP/Panel/Controller/API/EmailTemplates.pm | 8 +------- .../Controller/API/EmergencyMappingContainers.pm | 9 +-------- lib/NGCP/Panel/Controller/API/EmergencyMappings.pm | 8 +------- lib/NGCP/Panel/Controller/API/Events.pm | 5 ++--- lib/NGCP/Panel/Controller/API/Faxes.pm | 8 +------- lib/NGCP/Panel/Controller/API/FaxserverSettings.pm | 8 +------- lib/NGCP/Panel/Controller/API/Interceptions.pm | 8 +------- lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm | 8 +------- lib/NGCP/Panel/Controller/API/LnpCarriers.pm | 9 +-------- lib/NGCP/Panel/Controller/API/LnpNumbers.pm | 8 +------- lib/NGCP/Panel/Controller/API/MailToFaxSettings.pm | 8 +------- lib/NGCP/Panel/Controller/API/MaliciousCalls.pm | 8 +------- lib/NGCP/Panel/Controller/API/ManagerSecretary.pm | 8 +------- lib/NGCP/Panel/Controller/API/NcosLevels.pm | 8 +------- lib/NGCP/Panel/Controller/API/NcosLnpCarriers.pm | 8 +------- lib/NGCP/Panel/Controller/API/NcosPatterns.pm | 8 +------- lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm | 8 +------- .../Panel/Controller/API/PbxDeviceFirmwares.pm | 8 +------- .../Panel/Controller/API/PbxDevicePreferences.pm | 8 +------- .../Controller/API/PbxDeviceProfilePreferences.pm | 8 +------- lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm | 8 +------- lib/NGCP/Panel/Controller/API/PbxDevices.pm | 8 +------- lib/NGCP/Panel/Controller/API/PeeringGroups.pm | 8 +------- .../Panel/Controller/API/PeeringInboundRules.pm | 8 +------- lib/NGCP/Panel/Controller/API/PeeringRules.pm | 8 +------- .../Controller/API/PeeringServerPreferences.pm | 8 +------- lib/NGCP/Panel/Controller/API/PeeringServers.pm | 8 +------- lib/NGCP/Panel/Controller/API/ProfilePackages.pm | 5 ++--- .../Panel/Controller/API/ProfilePreferences.pm | 8 +------- lib/NGCP/Panel/Controller/API/Reminders.pm | 8 +------- lib/NGCP/Panel/Controller/API/Resellers.pm | 9 +-------- lib/NGCP/Panel/Controller/API/RtcApps.pm | 8 +------- lib/NGCP/Panel/Controller/API/RtcNetworks.pm | 8 +------- lib/NGCP/Panel/Controller/API/RtcSessions.pm | 8 +------- lib/NGCP/Panel/Controller/API/SoundFiles.pm | 8 +------- lib/NGCP/Panel/Controller/API/SoundHandles.pm | 8 +------- lib/NGCP/Panel/Controller/API/SoundSets.pm | 8 +------- lib/NGCP/Panel/Controller/API/SpeedDials.pm | 8 +------- .../Panel/Controller/API/SubscriberPreferences.pm | 8 +------- .../Panel/Controller/API/SubscriberProfileSets.pm | 8 +------- .../Panel/Controller/API/SubscriberProfiles.pm | 8 +------- .../Controller/API/SubscriberRegistrations.pm | 8 +------- lib/NGCP/Panel/Controller/API/Subscribers.pm | 8 +------- lib/NGCP/Panel/Controller/API/SystemContacts.pm | 8 +------- lib/NGCP/Panel/Controller/API/TopupLogs.pm | 5 ++--- lib/NGCP/Panel/Controller/API/TrustedSources.pm | 8 +------- lib/NGCP/Panel/Controller/API/UpnRewriteSets.pm | 8 +------- lib/NGCP/Panel/Controller/API/VoicemailSettings.pm | 8 +------- lib/NGCP/Panel/Controller/API/Voicemails.pm | 8 +------- lib/NGCP/Panel/Controller/API/Vouchers.pm | 8 +------- lib/NGCP/Panel/Role/API.pm | 6 ++++-- lib/NGCP/Panel/Role/Entities.pm | 8 +------- lib/NGCP/Panel/Utils/Journal.pm | 5 ++--- 82 files changed, 97 insertions(+), 546 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/AutoAttendants.pm b/lib/NGCP/Panel/Controller/API/AutoAttendants.pm index 63585c67cf..ea0e871890 100644 --- a/lib/NGCP/Panel/Controller/API/AutoAttendants.pm +++ b/lib/NGCP/Panel/Controller/API/AutoAttendants.pm @@ -67,13 +67,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm b/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm index 85f3c8ea93..76a47c225e 100644 --- a/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm +++ b/lib/NGCP/Panel/Controller/API/BalanceIntervals.pm @@ -124,9 +124,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm b/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm index 3cd0edf258..6ebedfa703 100644 --- a/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm +++ b/lib/NGCP/Panel/Controller/API/BalanceIntervalsItem.pm @@ -127,9 +127,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BillingFees.pm b/lib/NGCP/Panel/Controller/API/BillingFees.pm index f7c26bf00f..1ca06598e8 100644 --- a/lib/NGCP/Panel/Controller/API/BillingFees.pm +++ b/lib/NGCP/Panel/Controller/API/BillingFees.pm @@ -87,14 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BillingNetworks.pm b/lib/NGCP/Panel/Controller/API/BillingNetworks.pm index 00920f9fdc..f132a6a1f3 100644 --- a/lib/NGCP/Panel/Controller/API/BillingNetworks.pm +++ b/lib/NGCP/Panel/Controller/API/BillingNetworks.pm @@ -101,9 +101,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BillingProfiles.pm b/lib/NGCP/Panel/Controller/API/BillingProfiles.pm index 9447a43937..312721c9fa 100644 --- a/lib/NGCP/Panel/Controller/API/BillingProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/BillingProfiles.pm @@ -89,14 +89,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/BillingZones.pm b/lib/NGCP/Panel/Controller/API/BillingZones.pm index 7430cee97c..dd0e7b1972 100644 --- a/lib/NGCP/Panel/Controller/API/BillingZones.pm +++ b/lib/NGCP/Panel/Controller/API/BillingZones.pm @@ -87,14 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CCMapEntries.pm b/lib/NGCP/Panel/Controller/API/CCMapEntries.pm index 9c2ceec3bb..ba76b1324b 100644 --- a/lib/NGCP/Panel/Controller/API/CCMapEntries.pm +++ b/lib/NGCP/Panel/Controller/API/CCMapEntries.pm @@ -67,13 +67,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm index 9f5e8313fe..f64a7a2074 100644 --- a/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFDestinationSets.pm @@ -91,13 +91,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CFMappings.pm b/lib/NGCP/Panel/Controller/API/CFMappings.pm index bd8244878f..4a86398a55 100644 --- a/lib/NGCP/Panel/Controller/API/CFMappings.pm +++ b/lib/NGCP/Panel/Controller/API/CFMappings.pm @@ -82,13 +82,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm index e9eeb632c8..079c3d5d67 100644 --- a/lib/NGCP/Panel/Controller/API/CFSourceSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFSourceSets.pm @@ -98,13 +98,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm index 7a0fe65f39..0232913096 100644 --- a/lib/NGCP/Panel/Controller/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Controller/API/CFTimeSets.pm @@ -91,13 +91,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CallForwards.pm b/lib/NGCP/Panel/Controller/API/CallForwards.pm index c6a6cb4018..11e9c681fe 100644 --- a/lib/NGCP/Panel/Controller/API/CallForwards.pm +++ b/lib/NGCP/Panel/Controller/API/CallForwards.pm @@ -86,13 +86,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CallLists.pm b/lib/NGCP/Panel/Controller/API/CallLists.pm index fb966201a0..5cd0ced918 100644 --- a/lib/NGCP/Panel/Controller/API/CallLists.pm +++ b/lib/NGCP/Panel/Controller/API/CallLists.pm @@ -314,13 +314,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s&%s', $c->request->path, $page, $rows, $href_data)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CallRecordingStreams.pm b/lib/NGCP/Panel/Controller/API/CallRecordingStreams.pm index 783d12dfcf..f6118adf0d 100644 --- a/lib/NGCP/Panel/Controller/API/CallRecordingStreams.pm +++ b/lib/NGCP/Panel/Controller/API/CallRecordingStreams.pm @@ -97,13 +97,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CallRecordings.pm b/lib/NGCP/Panel/Controller/API/CallRecordings.pm index 1611d08173..cf29f45566 100644 --- a/lib/NGCP/Panel/Controller/API/CallRecordings.pm +++ b/lib/NGCP/Panel/Controller/API/CallRecordings.pm @@ -104,13 +104,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Calls.pm b/lib/NGCP/Panel/Controller/API/Calls.pm index 4a04e05a8a..bc732d03af 100644 --- a/lib/NGCP/Panel/Controller/API/Calls.pm +++ b/lib/NGCP/Panel/Controller/API/Calls.pm @@ -101,13 +101,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Capabilities.pm b/lib/NGCP/Panel/Controller/API/Capabilities.pm index 75c5fd9305..8de3d7c271 100644 --- a/lib/NGCP/Panel/Controller/API/Capabilities.pm +++ b/lib/NGCP/Panel/Controller/API/Capabilities.pm @@ -72,13 +72,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Contracts.pm b/lib/NGCP/Panel/Controller/API/Contracts.pm index 775f4fa870..73fc597e09 100644 --- a/lib/NGCP/Panel/Controller/API/Contracts.pm +++ b/lib/NGCP/Panel/Controller/API/Contracts.pm @@ -108,18 +108,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); - - # Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - #if(($total_count / $rows) > $page ) { - # push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - #} - #if($page > 1) { - # push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - #} + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerBalances.pm b/lib/NGCP/Panel/Controller/API/CustomerBalances.pm index 88c8bee92b..440c56a482 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerBalances.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerBalances.pm @@ -151,16 +151,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); - # Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - #if(($total_count / $rows) > $page ) { - # push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - #} - #if($page > 1) { - # push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - #} + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerContacts.pm b/lib/NGCP/Panel/Controller/API/CustomerContacts.pm index 1410eb318d..5d27a2a051 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerContacts.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerContacts.pm @@ -88,13 +88,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerFraudEvents.pm b/lib/NGCP/Panel/Controller/API/CustomerFraudEvents.pm index 8badfd7087..f719f11b9e 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerFraudEvents.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerFraudEvents.pm @@ -80,14 +80,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerFraudPreferences.pm b/lib/NGCP/Panel/Controller/API/CustomerFraudPreferences.pm index f08920322e..1ddc596fb6 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerFraudPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerFraudPreferences.pm @@ -102,9 +102,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerLocations.pm b/lib/NGCP/Panel/Controller/API/CustomerLocations.pm index 9cd03766ca..7bd842c30c 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerLocations.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerLocations.pm @@ -89,9 +89,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm b/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm index 9a35bb7f36..9b02d27fa4 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm @@ -77,13 +77,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/CustomerZoneCosts.pm b/lib/NGCP/Panel/Controller/API/CustomerZoneCosts.pm index 3272eb2b8c..6e1334ce98 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerZoneCosts.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerZoneCosts.pm @@ -93,15 +93,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s&%s', $self->dispatch_path, $page, $rows, $query_string)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', - href => sprintf('%s?page=%d&rows=%d&%s', $self->dispatch_path, $page + 1, $rows, $query_string)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', - href => sprintf('%s?page=%d&rows=%d&%s', $self->dispatch_path, $page - 1, $rows, $query_string)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Customers.pm b/lib/NGCP/Panel/Controller/API/Customers.pm index 6d821a7dde..1b2d40652c 100644 --- a/lib/NGCP/Panel/Controller/API/Customers.pm +++ b/lib/NGCP/Panel/Controller/API/Customers.pm @@ -179,9 +179,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/DomainPreferences.pm b/lib/NGCP/Panel/Controller/API/DomainPreferences.pm index 4b65859fa4..7200e361a0 100644 --- a/lib/NGCP/Panel/Controller/API/DomainPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/DomainPreferences.pm @@ -68,13 +68,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Domains.pm b/lib/NGCP/Panel/Controller/API/Domains.pm index d4681d0e98..4a7891a4ad 100644 --- a/lib/NGCP/Panel/Controller/API/Domains.pm +++ b/lib/NGCP/Panel/Controller/API/Domains.pm @@ -90,13 +90,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm index 4729e7f491..63837b3848 100644 --- a/lib/NGCP/Panel/Controller/API/EmailTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/EmailTemplates.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm b/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm index 8c31a43d5a..4bebe82e79 100644 --- a/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm +++ b/lib/NGCP/Panel/Controller/API/EmergencyMappingContainers.pm @@ -88,14 +88,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm b/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm index a5a2f251c8..52faa8635d 100644 --- a/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm +++ b/lib/NGCP/Panel/Controller/API/EmergencyMappings.pm @@ -128,13 +128,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Events.pm b/lib/NGCP/Panel/Controller/API/Events.pm index 9d2c8e8358..f50d0a9ad4 100644 --- a/lib/NGCP/Panel/Controller/API/Events.pm +++ b/lib/NGCP/Panel/Controller/API/Events.pm @@ -126,9 +126,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Faxes.pm b/lib/NGCP/Panel/Controller/API/Faxes.pm index c163e53eda..b3d1f859c0 100644 --- a/lib/NGCP/Panel/Controller/API/Faxes.pm +++ b/lib/NGCP/Panel/Controller/API/Faxes.pm @@ -129,13 +129,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm b/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm index 012416bc30..870880008a 100644 --- a/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm +++ b/lib/NGCP/Panel/Controller/API/FaxserverSettings.pm @@ -99,13 +99,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Interceptions.pm b/lib/NGCP/Panel/Controller/API/Interceptions.pm index 17494fce3f..72ce8f350e 100644 --- a/lib/NGCP/Panel/Controller/API/Interceptions.pm +++ b/lib/NGCP/Panel/Controller/API/Interceptions.pm @@ -100,13 +100,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm index f6e6cab7a7..aeacb0316f 100644 --- a/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm +++ b/lib/NGCP/Panel/Controller/API/InvoiceTemplates.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/LnpCarriers.pm b/lib/NGCP/Panel/Controller/API/LnpCarriers.pm index 69543f1269..ed54d6a268 100644 --- a/lib/NGCP/Panel/Controller/API/LnpCarriers.pm +++ b/lib/NGCP/Panel/Controller/API/LnpCarriers.pm @@ -88,14 +88,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/LnpNumbers.pm b/lib/NGCP/Panel/Controller/API/LnpNumbers.pm index bed82ccfe2..c525f16a96 100644 --- a/lib/NGCP/Panel/Controller/API/LnpNumbers.pm +++ b/lib/NGCP/Panel/Controller/API/LnpNumbers.pm @@ -119,13 +119,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/MailToFaxSettings.pm b/lib/NGCP/Panel/Controller/API/MailToFaxSettings.pm index 89197c2176..f5ee98543d 100644 --- a/lib/NGCP/Panel/Controller/API/MailToFaxSettings.pm +++ b/lib/NGCP/Panel/Controller/API/MailToFaxSettings.pm @@ -99,13 +99,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/MaliciousCalls.pm b/lib/NGCP/Panel/Controller/API/MaliciousCalls.pm index 73f6a8ef4c..8f426f5a43 100644 --- a/lib/NGCP/Panel/Controller/API/MaliciousCalls.pm +++ b/lib/NGCP/Panel/Controller/API/MaliciousCalls.pm @@ -145,13 +145,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/ManagerSecretary.pm b/lib/NGCP/Panel/Controller/API/ManagerSecretary.pm index a4227ca252..badda200e3 100644 --- a/lib/NGCP/Panel/Controller/API/ManagerSecretary.pm +++ b/lib/NGCP/Panel/Controller/API/ManagerSecretary.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/NcosLevels.pm b/lib/NGCP/Panel/Controller/API/NcosLevels.pm index d3e00aaaa9..2465eabc8c 100644 --- a/lib/NGCP/Panel/Controller/API/NcosLevels.pm +++ b/lib/NGCP/Panel/Controller/API/NcosLevels.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/NcosLnpCarriers.pm b/lib/NGCP/Panel/Controller/API/NcosLnpCarriers.pm index 72ee093f2e..f4853f9725 100644 --- a/lib/NGCP/Panel/Controller/API/NcosLnpCarriers.pm +++ b/lib/NGCP/Panel/Controller/API/NcosLnpCarriers.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/NcosPatterns.pm b/lib/NGCP/Panel/Controller/API/NcosPatterns.pm index ef9bff4e32..a55912e7c2 100644 --- a/lib/NGCP/Panel/Controller/API/NcosPatterns.pm +++ b/lib/NGCP/Panel/Controller/API/NcosPatterns.pm @@ -76,13 +76,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm index 29d5b28eaa..c37501c537 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm @@ -98,13 +98,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceFirmwares.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceFirmwares.pm index cd29771052..ee6bf55788 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceFirmwares.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceFirmwares.pm @@ -99,13 +99,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm b/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm index 2f66a90ae2..e5f77b8f5a 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm @@ -60,13 +60,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm index f0e80eff49..1a985fb8ec 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm @@ -60,13 +60,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm index 0267aff15a..2ff849dced 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm @@ -88,13 +88,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PbxDevices.pm b/lib/NGCP/Panel/Controller/API/PbxDevices.pm index 5d5865c406..e75ba08c15 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDevices.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDevices.pm @@ -100,13 +100,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm index 60fdd98f14..b518fd20f4 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm @@ -75,13 +75,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm b/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm index e0af3a2e8a..dd957249b1 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringInboundRules.pm @@ -99,13 +99,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PeeringRules.pm b/lib/NGCP/Panel/Controller/API/PeeringRules.pm index b97101645f..be4b291bf1 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRules.pm @@ -99,13 +99,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm b/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm index 65a4ec3478..9a36d1e430 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm @@ -68,13 +68,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/PeeringServers.pm b/lib/NGCP/Panel/Controller/API/PeeringServers.pm index 52cc643b53..ec0f990acf 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServers.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServers.pm @@ -120,13 +120,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/ProfilePackages.pm b/lib/NGCP/Panel/Controller/API/ProfilePackages.pm index a22b231f49..109243fe71 100644 --- a/lib/NGCP/Panel/Controller/API/ProfilePackages.pm +++ b/lib/NGCP/Panel/Controller/API/ProfilePackages.pm @@ -115,9 +115,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm b/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm index 78a9a5e2a6..5ef05fcefe 100644 --- a/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm @@ -59,13 +59,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Reminders.pm b/lib/NGCP/Panel/Controller/API/Reminders.pm index eb6446c507..914af49c5b 100644 --- a/lib/NGCP/Panel/Controller/API/Reminders.pm +++ b/lib/NGCP/Panel/Controller/API/Reminders.pm @@ -93,13 +93,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Resellers.pm b/lib/NGCP/Panel/Controller/API/Resellers.pm index 161ebd4fb2..60fa969e94 100644 --- a/lib/NGCP/Panel/Controller/API/Resellers.pm +++ b/lib/NGCP/Panel/Controller/API/Resellers.pm @@ -79,14 +79,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/RtcApps.pm b/lib/NGCP/Panel/Controller/API/RtcApps.pm index 9963085593..b77188e52d 100644 --- a/lib/NGCP/Panel/Controller/API/RtcApps.pm +++ b/lib/NGCP/Panel/Controller/API/RtcApps.pm @@ -63,13 +63,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/RtcNetworks.pm b/lib/NGCP/Panel/Controller/API/RtcNetworks.pm index c67198b1c5..bccc4f3edc 100644 --- a/lib/NGCP/Panel/Controller/API/RtcNetworks.pm +++ b/lib/NGCP/Panel/Controller/API/RtcNetworks.pm @@ -63,13 +63,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/RtcSessions.pm b/lib/NGCP/Panel/Controller/API/RtcSessions.pm index d640052712..364e85e9c0 100644 --- a/lib/NGCP/Panel/Controller/API/RtcSessions.pm +++ b/lib/NGCP/Panel/Controller/API/RtcSessions.pm @@ -67,13 +67,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SoundFiles.pm b/lib/NGCP/Panel/Controller/API/SoundFiles.pm index 42bbf215f6..b39cb5c0b1 100644 --- a/lib/NGCP/Panel/Controller/API/SoundFiles.pm +++ b/lib/NGCP/Panel/Controller/API/SoundFiles.pm @@ -85,13 +85,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SoundHandles.pm b/lib/NGCP/Panel/Controller/API/SoundHandles.pm index c29faf44d1..a5d137c17f 100644 --- a/lib/NGCP/Panel/Controller/API/SoundHandles.pm +++ b/lib/NGCP/Panel/Controller/API/SoundHandles.pm @@ -78,13 +78,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SoundSets.pm b/lib/NGCP/Panel/Controller/API/SoundSets.pm index 1f97e67a9c..d4e2e4b090 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSets.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSets.pm @@ -98,13 +98,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SpeedDials.pm b/lib/NGCP/Panel/Controller/API/SpeedDials.pm index 03768441de..7603ebceae 100644 --- a/lib/NGCP/Panel/Controller/API/SpeedDials.pm +++ b/lib/NGCP/Panel/Controller/API/SpeedDials.pm @@ -81,13 +81,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm b/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm index 3e56ea2e50..3a61d40511 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm @@ -114,13 +114,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm index a2451a921f..03e17c4f3a 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfileSets.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm b/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm index 03f3334fa9..291f732c32 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberProfiles.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm b/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm index 0418a8013a..5ef9c64b91 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberRegistrations.pm @@ -98,13 +98,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Subscribers.pm b/lib/NGCP/Panel/Controller/API/Subscribers.pm index c16cad787b..26b3834a83 100644 --- a/lib/NGCP/Panel/Controller/API/Subscribers.pm +++ b/lib/NGCP/Panel/Controller/API/Subscribers.pm @@ -301,13 +301,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/SystemContacts.pm b/lib/NGCP/Panel/Controller/API/SystemContacts.pm index 1029d5630e..2c49ccaa2e 100644 --- a/lib/NGCP/Panel/Controller/API/SystemContacts.pm +++ b/lib/NGCP/Panel/Controller/API/SystemContacts.pm @@ -77,13 +77,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/TopupLogs.pm b/lib/NGCP/Panel/Controller/API/TopupLogs.pm index cee37157c0..3784786da8 100644 --- a/lib/NGCP/Panel/Controller/API/TopupLogs.pm +++ b/lib/NGCP/Panel/Controller/API/TopupLogs.pm @@ -185,9 +185,8 @@ sub GET :Allow { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $self->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/TrustedSources.pm b/lib/NGCP/Panel/Controller/API/TrustedSources.pm index e30c55d6ff..cc66a4970b 100644 --- a/lib/NGCP/Panel/Controller/API/TrustedSources.pm +++ b/lib/NGCP/Panel/Controller/API/TrustedSources.pm @@ -81,13 +81,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/UpnRewriteSets.pm b/lib/NGCP/Panel/Controller/API/UpnRewriteSets.pm index c872162217..f7133c2187 100644 --- a/lib/NGCP/Panel/Controller/API/UpnRewriteSets.pm +++ b/lib/NGCP/Panel/Controller/API/UpnRewriteSets.pm @@ -80,13 +80,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/VoicemailSettings.pm b/lib/NGCP/Panel/Controller/API/VoicemailSettings.pm index 0128326744..e7a608d370 100644 --- a/lib/NGCP/Panel/Controller/API/VoicemailSettings.pm +++ b/lib/NGCP/Panel/Controller/API/VoicemailSettings.pm @@ -80,13 +80,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Voicemails.pm b/lib/NGCP/Panel/Controller/API/Voicemails.pm index a685c314ae..5884b4a06e 100644 --- a/lib/NGCP/Panel/Controller/API/Voicemails.pm +++ b/lib/NGCP/Panel/Controller/API/Voicemails.pm @@ -88,13 +88,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Controller/API/Vouchers.pm b/lib/NGCP/Panel/Controller/API/Vouchers.pm index e17a6521a5..0eb11c7b1b 100644 --- a/lib/NGCP/Panel/Controller/API/Vouchers.pm +++ b/lib/NGCP/Panel/Controller/API/Vouchers.pm @@ -87,13 +87,7 @@ sub GET :Allow { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 7086afdd50..b56c3dd007 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -688,9 +688,11 @@ sub paginate_order_collection_rs { } sub collection_nav_links { - my ($self, $page, $rows, $total_count, $path, $params) = @_; + my ($self, $c, $page, $rows, $total_count, $path, $params) = @_; + + $path //= $c->request->path; + $params //= $c->request->params; - $params = { %{ $params } }; #copy delete @{$params}{'page', 'rows'}; my $rest_params = join( '&', map {"$_=".$params->{$_}} keys %{$params}); $rest_params = $rest_params ? "&$rest_params" : ""; diff --git a/lib/NGCP/Panel/Role/Entities.pm b/lib/NGCP/Panel/Role/Entities.pm index cde32d721c..d01e79e273 100644 --- a/lib/NGCP/Panel/Role/Entities.pm +++ b/lib/NGCP/Panel/Role/Entities.pm @@ -224,13 +224,7 @@ sub get { templated => true, ), Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), - Data::HAL::Link->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s%s', $c->request->path, $page, $rows, $href_params)); - if(($total_count / $rows) > $page ) { - push @links, Data::HAL::Link->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d%s', $c->request->path, $page + 1, $rows, $href_params)); - } - if($page > 1) { - push @links, Data::HAL::Link->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d%s', $c->request->path, $page - 1, $rows, $href_params)); - } + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded], diff --git a/lib/NGCP/Panel/Utils/Journal.pm b/lib/NGCP/Panel/Utils/Journal.pm index c336c02227..46f0f1fe6e 100644 --- a/lib/NGCP/Panel/Utils/Journal.pm +++ b/lib/NGCP/Panel/Utils/Journal.pm @@ -250,9 +250,8 @@ sub handle_api_journals_get { name => 'ngcp', templated => true, ), - Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'); - - push @links, $controller->collection_nav_links($page, $rows, $total_count, $c->request->path, $c->request->query_params); + Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'), + $self->collection_nav_links($c, $page, $rows, $total_count, $c->request->path, $c->request->query_params); my $hal = Data::HAL->new( embedded => [@embedded],