Skip to content

Commit

Permalink
Merge branch 'Release-v0.9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
TBSliver committed Sep 28, 2017
2 parents 8f28c5e + 2dcb591 commit 0198d53
Show file tree
Hide file tree
Showing 120 changed files with 9,755 additions and 125 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ hypnotoad.pid

cover_db/
schema.png

etc/code-point-open/codepo_gb/

pear-local_loop.production.conf
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Next Release

# v0.9.3

* **Feature:** lat/long locations on customers and organisations
* **Feature:** Suppliers map co-ords

# v0.9.2

* **Fix:** Leaderboard total calculations not mapped correctly
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,20 @@
*Master:* [![Build Status](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=master)](https://travis-ci.org/Pear-Trading/Foodloop-Server)

*Development:* [![Build Status](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=development)](https://travis-ci.org/Pear-Trading/Foodloop-Server)

# Testing

To run the main test framework, first install all the dependencies, then run the tests:

```
cpanm --installdeps .
prove -lr
```

To run the main framework against a PostgreSQL backend, assuming you have postgres installed, you will need some extra dependencies first:

```
cpanm --installdeps . --with-feature postgres
PEAR_TEST_PG=1 prove -lr
```

13 changes: 12 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ requires 'MooX::Options::Actions';
requires 'Module::Runtime';
requires 'DBIx::Class::DeploymentHandler';
requires 'DBIx::Class::Fixtures';
requires 'GIS::Distance';

on 'schema-graph' => sub {
feature 'schema-graph', 'Draw diagrams of Schema' => sub {
requires 'GraphViz';
requires 'SQL::Translator';
};

feature 'postgres', 'PostgreSQL Support' => sub {
requires 'DBD::Pg';
requires 'Test::PostgreSQL';
};

feature 'codepoint-open', 'Code Point Open manipulation' => sub {
requires 'Geo::UK::Postcode::CodePointOpen';
};

2 changes: 1 addition & 1 deletion doc/Fixtures/Users.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* email: [email protected]
* password: abc123
* Test Org
* email: test5@example.com
* email: org@example.com
* password: abc123
* Test Admin
* email: [email protected]
Expand Down
10 changes: 10 additions & 0 deletions etc/code-point-open/LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ORDNANCE SURVEY DATA LICENCE

Your use of data is subject to terms at www.ordnancesurvey.co.uk/opendata/licence.

Contains Ordnance Survey data � Crown copyright and database right 2017.

Contains Royal Mail data � Royal Mail copyright and database right 2017.
Contains National Statistics data � Crown copyright and database right 2017.

August 2017
Binary file added etc/code-point-open/codepo_gb.zip
Binary file not shown.
13 changes: 12 additions & 1 deletion lib/Pear/LocalLoop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sub startup {
json => {
success => Mojo::JSON->false,
message => $c->error_messages->{$val}->{$check}->{message},
error => $check,
error => $c->error_messages->{$val}->{$check}->{error} || $check,
},
status => $c->error_messages->{$val}->{$check}->{status},
);
Expand Down Expand Up @@ -145,12 +145,23 @@ sub startup {
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');


my $api_v1 = $api->under('/v1');

my $api_v1_supplier = $api_v1->under('/supplier');

$api_v1_supplier->post('/location')->to('api-v1-supplier-location#index');

my $api_v1_org = $api_v1->under('/organisation')->to('api-v1-organisation#auth');

$api_v1_org->post('/graphs')->to('api-v1-organisation-graphs#index');
$api_v1_org->post('/snippets')->to('api-v1-organisation-snippets#index');
$api_v1_org->post('/payroll')->to('api-organisation#post_payroll_read');
$api_v1_org->post('/payroll/add')->to('api-organisation#post_payroll_add');
$api_v1_org->post('/supplier')->to('api-organisation#post_supplier_read');
$api_v1_org->post('/supplier/add')->to('api-organisation#post_supplier_add');
$api_v1_org->post('/employee')->to('api-organisation#post_employee_read');
$api_v1_org->post('/employee/add')->to('api-organisation#post_employee_add');

my $admin_routes = $r->under('/admin')->to('admin#under');

Expand Down
64 changes: 64 additions & 0 deletions lib/Pear/LocalLoop/Command/codepoint_open.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package Pear::LocalLoop::Command::codepoint_open;
use Mojo::Base 'Mojolicious::Command';

use Mojo::Util 'getopt';

use Geo::UK::Postcode::CodePointOpen;

has description => 'Manage Codepoint Open Data';

has usage => sub { shift->extract_usage };

sub run {
my ( $self, @args ) = @_;

getopt \@args,
'o|outcodes=s' => \my @outcodes,
'q|quiet' => \my $quiet_mode;

my $cpo_dir = $self->app->home->child('etc')->child('code-point-open');
my $zip_file = $cpo_dir->child('codepo_gb.zip')->realpath->to_string;
my $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string;

unless ( -d $output_dir ) {
print "Unzipping code-point-open data\n" unless $quiet_mode;
system( 'unzip', '-q', $zip_file, '-d', $output_dir );
}

my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir );

printf( "Importing data for %s outcode(s)\n", @outcodes ? join( ' ', @outcodes ) : 'all' )
unless $quiet_mode;

my $iter = $cpo->read_iterator(
outcodes => \@outcodes,
include_lat_long => 1,
split_postcode => 1,
);

my $pc_rs = $self->app->schema->resultset('GbPostcode');
while ( my $pc = $iter->() ) {
$pc_rs->find_or_create(
{
outcode => $pc->{Outcode},
incode => $pc->{Incode},
latitude => $pc->{Latitude},
longitude => $pc->{Longitude},
},
{ key => 'primary' },
);
}
}

=head1 SYNOPSIS
Usage: APPLICATION codepoint_open [OPTIONS]
Options:
-o|--outcodes <outcode> : limit to specified outcodes (can be defined
multiple times)
=cut

1;
83 changes: 83 additions & 0 deletions lib/Pear/LocalLoop/Command/latlong_setup.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package Pear::LocalLoop::Command::latlong_setup;
use Mojo::Base 'Mojolicious::Command';

use Mojo::Util 'getopt';

use Geo::UK::Postcode::Regex;
use GIS::Distance;

has description => 'Set lat/long data on customers and orgs';

has usage => sub { shift->extract_usage };

sub run {
my ( $self, @args ) = @_;

my $customer_rs = $self->app->schema->resultset('Customer');
my $org_rs = $self->app->schema->resultset('Organisation');

for my $result ( $customer_rs->all, $org_rs->all ) {
$self->_set_lat_long_for_result( $result );
}

my $transaction_rs = $self->app->schema->resultset('Transaction');

for my $result ( $transaction_rs->all ) {
my $distance = $self->_calculate_distance(
$result->buyer->${\$result->buyer->type},
$result->seller->${\$result->seller->type},
);
$result->update({ distance => $distance }) if defined $distance;
}
}

sub _set_lat_long_for_result {
my ( $self, $result ) = @_;

my $parsed_postcode = Geo::UK::Postcode::Regex->parse($result->postcode);
my $pc_rs = $self->app->schema->resultset('GbPostcode');

if ( $parsed_postcode->{valid} && !$parsed_postcode->{non_geographical} ) {
my $gb_pc = $pc_rs->find({
outcode => $parsed_postcode->{outcode},
incode => $parsed_postcode->{incode},
});
if ( $gb_pc ) {
$result->update({
latitude => $gb_pc->latitude,
longitude => $gb_pc->longitude,
});
}
}
}

sub _calculate_distance {
my ( $self, $buyer, $seller ) = @_;

my $gis = GIS::Distance->new();

my $buyer_lat = $buyer->latitude;
my $buyer_long = $buyer->longitude;
my $seller_lat = $seller->latitude;
my $seller_long = $seller->longitude;

if ( $buyer_lat && $buyer_long
&& $seller_lat && $seller_long ) {
return $gis->distance( $buyer_lat, $buyer_long => $seller_lat, $seller_long )->meters;
} else {
print STDERR "missing lat-long for: " . $buyer->name . " or " . $seller->name . "\n";
}
return;
}

=head1 SYNOPSIS
Usage: APPLICATION latlong_setup [OPTIONS]
Options:
none for now
=cut

1;
4 changes: 2 additions & 2 deletions lib/Pear/LocalLoop/Controller/Api/Feedback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use Mojo::Base 'Mojolicious::Controller';
has error_messages => sub {
return {
email => {
required => { message => 'Email is required', status => 400 },
in_resultset => { message => 'Change meeee', status => 400 },
required => { message => 'Email is required or not registered', status => 400 },
in_resultset => { message => 'Email is required or not registered', status => 400, error => "required" },
},
feedbacktext => {
required => { message => 'Feedback is required', status => 400 },
Expand Down
Loading

0 comments on commit 0198d53

Please sign in to comment.