diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Open311/Updates.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311/Updates.pm | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm index 105400a8a..8881a1b87 100644 --- a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm +++ b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm @@ -3,7 +3,6 @@ package FixMyStreet::App::Controller::Open311::Updates; use utf8; use Moose; use namespace::autoclean; -use Open311; use Open311::GetServiceRequestUpdates; BEGIN { extends 'Catalyst::Controller'; } @@ -31,7 +30,6 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) { $body = $c->model('DB::Body')->find({ id => $c->get_param('jurisdiction_id') }); } $c->detach('bad_request', ['jurisdiction_id']) unless $body; - my $user = $body->comment_user; my $key = $c->get_param('api_key') || ''; my $token = $c->cobrand->feature('open311_token') || ''; @@ -45,37 +43,36 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) { $request->{$_} = $c->get_param($_) || $c->detach('bad_request', [ $_ ]); } - my %open311_conf = ( - endpoint => $body->endpoint, - api_key => $body->api_key, - jurisdiction => $body->jurisdiction, - extended_statuses => $body->send_extended_statuses, - ); + $c->forward('process_update', [ $body, $request ]); +} - my $cobrand = $body->get_cobrand_handler; - $cobrand->call_hook(open311_config_updates => \%open311_conf) - if $cobrand; +sub process_update : Private { + my ($self, $c, $body, $request) = @_; - my $open311 = Open311->new(%open311_conf); my $updates = Open311::GetServiceRequestUpdates->new( - system_user => $user, - current_open311 => $open311, + system_user => $body->comment_user, current_body => $body, ); my $p = $updates->find_problem($request); $c->detach('bad_request', [ 'not found' ]) unless $p; - my $comment = $p->comments->search( { external_id => $request->{update_id} } )->first; - $c->detach('bad_request', [ 'already exists' ]) if $comment; + $c->forward('check_existing', [ $p, $request, $updates ]); - $comment = $updates->process_update($request, $p); + my $comment = $updates->process_update($request, $p); my $data = { service_request_updates => { update_id => $comment->id } }; $c->forward('/open311/format_output', [ $data ]); } +sub check_existing : Private { + my ($self, $c, $p, $request, $updates) = @_; + + my $comment = $p->comments->search( { external_id => $request->{update_id} } )->first; + $c->detach('bad_request', [ 'already exists' ]) if $comment; +} + sub bad_request : Private { my ($self, $c, $comment) = @_; $c->response->status(400); |