diff options
author | Dave Arter <davea@mysociety.org> | 2016-08-18 14:29:41 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-08-22 11:26:36 +0100 |
commit | d55d835fa6e95db47badd5b57172d9accda2eec8 (patch) | |
tree | 8d90539c9253b6acca072b2cb246440b5b6ca6fa /perllib/FixMyStreet/App/Controller | |
parent | b296995e528da8f25328fdba7df71b4f50909e41 (diff) |
Allow searching for reports with ref: prefix in postcode field
Searches the `id` and `external_id` fields.
This takes you directly to the report if only a single report matches, otherwise
a disambiguation page is shown.
For mysociety/fixmystreetforcouncils#16
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 82a7a9e76..c4feca8b6 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -38,6 +38,11 @@ sub index : Path : Args(0) { # Check if we have a partial report my $partial_report = $c->forward('load_partial'); + # Check if the user is searching for a report by ID + if ( $c->get_param('pc') && $c->get_param('pc') =~ $c->cobrand->lookup_by_ref_regex ) { + $c->go('lookup_by_ref', [ $1 ]); + } + # Try to create a location for whatever we have my $ret = $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); @@ -385,6 +390,24 @@ sub _geocode : Private { } +sub lookup_by_ref : Private { + my ( $self, $c, $ref ) = @_; + + my $problems = $c->cobrand->problems->search([ + id => $ref, + external_id => $ref + ]); + + if ( $problems->count == 0) { + $c->detach( '/page_error_404_not_found', [] ); + } elsif ( $problems->count == 1 ) { + $c->res->redirect( $c->uri_for( '/report', $problems->first->id ) ); + } else { + $c->stash->{ref} = $ref; + $c->stash->{matching_reports} = [ $problems->all ]; + } +} + __PACKAGE__->meta->make_immutable; 1; |