Added entity postcode lookup
This commit is contained in:
parent
cc84dbb76e
commit
a45c354834
12 changed files with 4793 additions and 1 deletions
|
@ -0,0 +1,30 @@
|
|||
package Pear::LocalLoop::Plugin::Minion::Job::entity_postcode_lookup;
|
||||
use Mojo::Base 'Pear::LocalLoop::Plugin::Minion::Job';
|
||||
|
||||
sub run {
|
||||
my ( $self, $entity_id ) = @_;
|
||||
|
||||
my $entity_rs = $self->app->schema->resultset('Entity');
|
||||
$entity_rs = $entity_rs->search({id => $entity_id }) if $entity_id;
|
||||
|
||||
while ( my $entity = $entity_rs->next ) {
|
||||
my $obj = $entity->type_object;
|
||||
next unless $obj;
|
||||
|
||||
my $postcode_obj = Geo::UK::Postcode::Regex->parse( $obj->postcode );
|
||||
|
||||
unless ( defined $postcode_obj && $postcode_obj->{non_geographical} ) {
|
||||
my $pc_result = $self->app->schema->resultset('GbPostcode')->find({
|
||||
incode => $postcode_obj->{incode},
|
||||
outcode => $postcode_obj->{outcode},
|
||||
});
|
||||
if ( defined $pc_result ) {
|
||||
$entity->update_or_create_related('postcode', {
|
||||
gb_postcode => $pc_result,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -6,7 +6,7 @@ use warnings;
|
|||
|
||||
use base 'DBIx::Class::Schema';
|
||||
|
||||
our $VERSION = 27;
|
||||
our $VERSION = 28;
|
||||
|
||||
__PACKAGE__->load_namespaces;
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ __PACKAGE__->might_have(
|
|||
"Pear::LocalLoop::Schema::Result::EntityAssociation" => "entity_id",
|
||||
);
|
||||
|
||||
__PACKAGE__->might_have(
|
||||
"postcode",
|
||||
"Pear::LocalLoop::Schema::Result::EntityPostcode" => "entity_id",
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"purchases",
|
||||
"Pear::LocalLoop::Schema::Result::Transaction",
|
||||
|
|
44
lib/Pear/LocalLoop/Schema/Result/EntityPostcode.pm
Normal file
44
lib/Pear/LocalLoop/Schema/Result/EntityPostcode.pm
Normal file
|
@ -0,0 +1,44 @@
|
|||
package Pear::LocalLoop::Schema::Result::EntityPostcode;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table('entities_postcodes');
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
outcode => {
|
||||
data_type => 'char',
|
||||
size => 4,
|
||||
is_nullable => 0,
|
||||
},
|
||||
incode => {
|
||||
data_type => 'char',
|
||||
size => 3,
|
||||
is_nullable => 0,
|
||||
},
|
||||
entity_id => {
|
||||
data_type => 'integer',
|
||||
is_nullable => 0,
|
||||
is_foreign_key => 1,
|
||||
},
|
||||
);
|
||||
|
||||
__PACKAGE__->set_primary_key(qw/ outcode incode entity_id /);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
"entity",
|
||||
"Pear::LocalLoop::Schema::Result::Entity",
|
||||
"entity_id",
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
"gb_postcode",
|
||||
"Pear::LocalLoop::Schema::Result::GbPostcode",
|
||||
{
|
||||
"foreign.outcode" => "self.outcode",
|
||||
"foreign.incode" => "self.incode",
|
||||
},
|
||||
);
|
||||
1;
|
Reference in a new issue