diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-24 22:44:37 +0100 |
---|---|---|
committer | M Somerville <matthew-github@dracos.co.uk> | 2020-11-11 10:29:20 +0000 |
commit | 26ca5c069d168eded92b95abd3be0d7b7349b430 (patch) | |
tree | 538f93cc1e6d52343a07def933afc9f638b8a7ed /perllib/FixMyStreet/App/Controller/Open311/Updates.pm | |
parent | cabc4f91d55b952ab2521ec85ec745de4c354d8c (diff) |
[Bromley] Push notification from Echo.
Make sure a 200 response is always sent for a valid notification.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Open311/Updates.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311/Updates.pm | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm index d5754bab7..8881a1b87 100644 --- a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm +++ b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm @@ -43,6 +43,12 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) { $request->{$_} = $c->get_param($_) || $c->detach('bad_request', [ $_ ]); } + $c->forward('process_update', [ $body, $request ]); +} + +sub process_update : Private { + my ($self, $c, $body, $request) = @_; + my $updates = Open311::GetServiceRequestUpdates->new( system_user => $body->comment_user, current_body => $body, @@ -51,16 +57,22 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) { 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); |