aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm53
-rw-r--r--t/app/controller/around.t31
-rw-r--r--t/app/controller/index.t7
-rw-r--r--templates/web/default/around/around_index.html5
5 files changed, 93 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 0768f83cd..f41cdf212 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ blib/
inc/
.sass-cache
_Inline/
+lib
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
new file mode 100644
index 000000000..8df7b880f
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -0,0 +1,53 @@
+package FixMyStreet::App::Controller::Around;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+use FixMyStreet::Map;
+use List::MoreUtils qw(any);
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Around - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Allow the user to search for reports around a particular location.
+
+=head1 METHODS
+
+=head2 around
+
+Find the location search and display nearby reports (for pc or lat,lon).
+
+For x,y searches convert to lat,lon and 301 redirect to them.
+
+If no search redirect back to the homepage.
+
+=cut
+
+sub around_index : Path : Args(0) {
+ my ( $self, $c ) = @_;
+
+ # check for x,y requests and redirect them to lat,lon
+ my $x = $c->req->param('x');
+ my $y = $c->req->param('y');
+ if ( $x || $y ) {
+ my ( $lat, $lon ) = FixMyStreet::Map::tile_xy_to_wgs84( $x, $y );
+ my $ll_uri = $c->uri_for( '/around', { lat => $lat, lon => $lon } );
+ $c->res->redirect( $ll_uri, 301 );
+ return;
+ }
+
+ # if there was no search then redirect to the homepage
+ if ( !any { $c->req->param($_) } qw(pc lat lon) ) {
+ return $c->res->redirect( $c->uri_for('/') );
+ }
+
+
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
new file mode 100644
index 000000000..021cf8f7d
--- /dev/null
+++ b/t/app/controller/around.t
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+subtest "check that if no query we get sent back to the homepage" => sub {
+ $mech->get_ok('/around');
+ is $mech->uri->path, '/', "sent back to '/'";
+};
+
+# x,y requests were generated by the old map code. We keep the behavior for
+# historic links
+subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub {
+
+ $mech->get_ok('/around?x=3281&y=1113');
+
+ # did we redirect to lat,lon?
+ is $mech->uri->path, '/around', "still on /around";
+ is_deeply { $mech->uri->query_form },
+ { lat => 51.4998246332569, lon => -0.140137309739907, },
+ "lat,lon correctly set";
+
+ # was it a 301?
+ is $mech->res->code, 200, "got 200 for final destination";
+ is $mech->res->previous->code, 301, "got 301 for redirect";
+
+};
+
+done_testing();
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index 91f01c943..11c59d289 100644
--- a/t/app/controller/index.t
+++ b/t/app/controller/index.t
@@ -21,10 +21,9 @@ subtest "check that the form goes to /around" => sub {
};
subtest "check that requests with pc, x,y or lat,lon go to /around" => sub {
- foreach my $test (
- { pc => 'SW1A 1AA', },
- { x => 3281, y => 1113, },
- { lat => 51.50100, lon => -0.14158, },
+ foreach my $test ( #
+ { pc => 'SW1A 1AA' }, #
+ { lat => 51.50100, lon => -0.14158 },
)
{
my $uri = URI->new('http://localhost/');
diff --git a/templates/web/default/around/around_index.html b/templates/web/default/around/around_index.html
new file mode 100644
index 000000000..a132be440
--- /dev/null
+++ b/templates/web/default/around/around_index.html
@@ -0,0 +1,5 @@
+[% INCLUDE 'header.html', title => loc('') %]
+
+
+
+[% INCLUDE 'footer.html' %] \ No newline at end of file