From eed41633bd158e43bdf8deb5eb51b0117804b799 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Tue, 3 Mar 2015 18:14:18 +0100 Subject: [PATCH] MT#11917 Write journal for customer create/update. Work in progress. --- lib/NGCP/Panel/Controller/API/Customers.pm | 7 +++++++ lib/NGCP/Panel/Role/API.pm | 5 +++++ lib/NGCP/Panel/Role/API/Customers.pm | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/NGCP/Panel/Controller/API/Customers.pm b/lib/NGCP/Panel/Controller/API/Customers.pm index 7725fac266..40fbef5d51 100644 --- a/lib/NGCP/Panel/Controller/API/Customers.pm +++ b/lib/NGCP/Panel/Controller/API/Customers.pm @@ -243,6 +243,13 @@ sub POST :Allow { } try { $customer = $schema->resultset('contracts')->create($resource); + $schema->resultset('journals')->create({ + type => "create", + resource => "customers", + resource_id => $customer->id, + timestamp => $now->hires_epoch, + content => undef, + }); } catch($e) { $c->log->error("failed to create customer contract: $e"); # TODO: user, message, trace, ... $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create customer."); diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 6968fca405..8e50076a99 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -518,5 +518,10 @@ sub is_false { return; } +sub to_json { + my ($self, $data) = @_; + return JSON::to_json($data, { canonical => 1, pretty => 1, utf8 => 1 }); +} + 1; # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index ef7d5fc3d0..2762c1ada7 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -116,6 +116,15 @@ sub customer_by_id { sub update_customer { my ($self, $c, $customer, $old_resource, $resource, $form) = @_; + my $old_hal = $self->hal_from_customer($c, $customer, $form); + $c->model('DB')->resultset('journals')->create({ + type => "update", + resource => "customers", + resource_id => $customer->id, + timestamp => NGCP::Panel::Utils::DateTime::current_local->hires_epoch, + content => $self->to_json($old_hal->resource), + }); + my $billing_mapping = $customer->billing_mappings->find($customer->get_column('bmid')); $old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id; $old_resource->{prepaid} = $billing_mapping->billing_profile->prepaid;