aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conf/httpd.conf4
-rw-r--r--perllib/FixMyStreet/App/Controller/JSON.pm17
-rw-r--r--t/app/controller/json.t30
3 files changed, 30 insertions, 21 deletions
diff --git a/conf/httpd.conf b/conf/httpd.conf
index 2645af791..1de0f6f4a 100644
--- a/conf/httpd.conf
+++ b/conf/httpd.conf
@@ -87,8 +87,8 @@ RewriteRule ^/reports/{/rss/(.*)}$ /rss/$1 [R=permanent,L]
RewriteRule ^/alerts/?$ /alert [R=permanent,L]
# JSON API for summaries of reports
-RewriteRule ^/json/problems/new$ /json.cgi?type=new_problems [QSA,L]
-RewriteRule ^/json/problems/fixed$ /json.cgi?type=fixed_problems [QSA,L]
+# RewriteRule ^/json/problems/new$ /json.cgi?type=new_problems [QSA,L]
+# RewriteRule ^/json/problems/fixed$ /json.cgi?type=fixed_problems [QSA,L]
# Proxy tilma so that our js code can make calls on the originating server. Use
# a RewriteRule rather than ProxyPass so that Apache's processing order is more
diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm
index c437aafc0..d3688f19a 100644
--- a/perllib/FixMyStreet/App/Controller/JSON.pm
+++ b/perllib/FixMyStreet/App/Controller/JSON.pm
@@ -18,15 +18,24 @@ Provide information as JSON
=head1 METHODS
-=head2 json
+=head2 problems
+
+Provide JSON of new/fixed problems in a specified time range
=cut
-sub json : Path : Args(0) {
- my ( $self, $c ) = @_;
+sub problems : Local {
+ my ( $self, $c, $path_type ) = @_;
+
+ # get the type from the path - this is to deal with the historic url
+ # structure. In futur
+ $path_type ||= '';
+ my $type =
+ $path_type eq 'new' ? 'new_problems'
+ : $path_type eq 'fixed' ? 'fixed_problems'
+ : '';
# gather the parameters
- my $type = $c->req->param('type') || '';
my $start_date = $c->req->param('start_date') || '';
my $end_date = $c->req->param('end_date') || '';
diff --git a/t/app/controller/json.t b/t/app/controller/json.t
index 2c9ff4a61..7c5dce786 100644
--- a/t/app/controller/json.t
+++ b/t/app/controller/json.t
@@ -13,23 +13,23 @@ subtest "check that a bad request produces the appropriate response" => sub {
my $bad_type = "Invalid type supplied";
my %tests = (
- '' => $bad_date,
- 'foo=bar' => $bad_date,
- 'type=&start_date=&end_date=' => $bad_date,
- 'type=&start_date=bad&end_date=2000-02-01' => $bad_date,
- 'type=&start_date=2000-01-01&end_date=bad' => $bad_date,
- 'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date,
- 'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date,
-
- 'type=&start_date=2000-02-01&end_date=2000-01-01' => $mad_date,
-
- 'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
- 'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
+ '?' => $bad_date,
+ '?foo=bar' => $bad_date,
+ '?start_date=&end_date=' => $bad_date,
+ '?start_date=bad&end_date=2000-02-01' => $bad_date,
+ '?start_date=2000-01-01&end_date=bad' => $bad_date,
+ '?start_date=2000-02-31&end_date=2000-02-01' => $bad_date,
+ '?start_date=2000-01-01&end_date=2000-02-31' => $bad_date,
+
+ '?start_date=2000-02-01&end_date=2000-01-01' => $mad_date,
+
+ '?start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
+ '/foo?type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type,
);
foreach my $q ( sort keys %tests ) {
is_deeply #
- $mech->get_ok_json("/json?$q"), #
+ $mech->get_ok_json("/json/problems$q"), #
{ error => $tests{$q} }, #
"correct error for query '$q'";
}
@@ -38,7 +38,7 @@ subtest "check that a bad request produces the appropriate response" => sub {
is_deeply #
$mech->get_ok_json(
- "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), #
+ "/json/problems/new?start_date=2000-01-01&end_date=2000-02-01"), #
[], #
"correct response";
@@ -75,7 +75,7 @@ ok $anon_problem, "created anon test problem";
is_deeply #
$mech->get_ok_json(
- "/json?type=new_problems&start_date=2000-01-01&end_date=2000-02-01"), #
+ "/json/problems/new?start_date=2000-01-01&end_date=2000-02-01"), #
[
{
'anonymous' => 0,