Merge pull request #41 from Pear-Trading/TBSliver/Schema-Changes

Major schema changes
This commit is contained in:
Finn 2017-09-04 14:31:20 +01:00 committed by GitHub
commit 537048b506
116 changed files with 3167 additions and 1052 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ hypnotoad.pid
*.swp
cover_db/
schema.png

View file

@ -21,3 +21,8 @@ requires 'MooX::Options::Actions';
requires 'Module::Runtime';
requires 'DBIx::Class::DeploymentHandler';
requires 'DBIx::Class::Fixtures';
on 'schema-graph' => sub {
requires 'GraphViz';
requires 'SQL::Translator';
};

24
doc/Fixtures/Users.md Normal file
View file

@ -0,0 +1,24 @@
# Users Fixtures
* Fixture Name: `users`
## Users:
* Test User1
* email: test1@example.com
* password: abc123
* Test User2
* email: test2@example.com
* password: abc123
* Test User3
* email: test3@example.com
* password: abc123
* Test User4
* email: test4@example.com
* password: abc123
* Test Org
* email: test5@example.com
* password: abc123
* Test Admin
* email: admin@example.com
* password: abc123

View file

@ -175,16 +175,12 @@ sub startup {
$admin_routes->get('/users/:id')->to('admin-users#read');
$admin_routes->post('/users/:id')->to('admin-users#update');
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
$admin_routes->post('/users/:id/edit')->to('admin-users#edit');
$admin_routes->get('/organisations')->to('admin-organisations#list');
$admin_routes->get('/organisations/add')->to('admin-organisations#add_org');
$admin_routes->post('/organisations/add/submit')->to('admin-organisations#add_org_submit');
$admin_routes->get('/organisations/valid/:id')->to('admin-organisations#valid_read');
$admin_routes->post('/organisations/valid/:id/edit')->to('admin-organisations#valid_edit');
$admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read');
$admin_routes->post('/organisations/pending/:id/edit')->to('admin-organisations#pending_edit');
$admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve');
$admin_routes->post('/organisations/add')->to('admin-organisations#add_org_submit');
$admin_routes->get('/organisations/:id')->to('admin-organisations#valid_read');
$admin_routes->post('/organisations/:id')->to('admin-organisations#valid_edit');
$admin_routes->get('/feedback')->to('admin-feedback#index');
$admin_routes->get('/feedback/:id')->to('admin-feedback#read');

View file

@ -5,10 +5,10 @@ sub under {
my $c = shift;
if ( $c->is_user_authenticated ) {
return 1 if defined $c->current_user->administrator;
return 1 if $c->current_user->is_admin;
}
$c->redirect_to('/');
return undef;
return 0;
}
sub home {
@ -16,8 +16,8 @@ sub home {
my $user_rs = $c->schema->resultset('User');
my $token_rs = $c->schema->resultset('AccountToken');
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation');
my $pending_transaction_rs = $c->schema->resultset('PendingTransaction');
my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
my $pending_transaction_rs = $pending_orgs_rs->entity->sales;
$c->stash(
user_count => $user_rs->count,
tokens => {

View file

@ -2,13 +2,12 @@ package Pear::LocalLoop::Controller::Admin::Organisations;
use Mojo::Base 'Mojolicious::Controller';
use Try::Tiny;
use Data::Dumper;
sub list {
my $c = shift;
my $valid_orgs_rs = $c->schema->resultset('Organisation');
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation');
my $valid_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 0 });
my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
$c->stash(
valid_orgs_rs => $valid_orgs_rs,
@ -30,38 +29,44 @@ sub add_org_submit {
$validation->required('town');
$validation->optional('sector');
$validation->optional('postcode')->postcode;
$validation->optional('pending');
if ( $validation->has_error ) {
$c->flash( error => 'The validation has failed' );
$c->app->log->warn(Dumper $validation);
return $c->redirect_to( '/admin/organisations/add/' );
return $c->redirect_to( '/admin/organisations/add' );
}
my $organisation;
try {
$organisation = $c->schema->resultset('Organisation')->create({
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
sector => $validation->param('sector'),
postcode => $validation->param('postcode'),
my $entity = $c->schema->resultset('Entity')->create({
organisation => {
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
sector => $validation->param('sector'),
postcode => $validation->param('postcode'),
submitted_by_id => $c->current_user->id,
pending => defined $validation->param('pending') ? 0 : 1,
},
type => 'organisation',
});
$organisation = $entity->organisation;
} finally {
if ( @_ ) {
$c->flash( error => 'Something went wrong Adding the Organisation' );
$c->app->log->warn(Dumper @_);
$c->redirect_to( '/admin/organisations/add' );
} else {
$c->flash( success => 'Added Organisation' );
$c->redirect_to( '/admin/organisations/' . $organisation->id);
}
};
$c->redirect_to( '/admin/organisations/add/' );
}
sub valid_read {
my $c = shift;
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
my $transactions = $valid_org->transactions->search(
my $transactions = $valid_org->entity->sales->search(
undef, {
page => $c->param('page') || 1,
rows => 10,
@ -83,11 +88,11 @@ sub valid_edit {
$validation->required('town');
$validation->optional('sector');
$validation->required('postcode')->postcode;
$validation->optional('pending');
if ( $validation->has_error ) {
$c->flash( error => 'The validation has failed' );
$c->app->log->warn(Dumper $validation);
return $c->redirect_to( '/admin/organisations/valid/' . $c->param('id') );
return $c->redirect_to( '/admin/organisations/' . $c->param('id') );
}
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
@ -100,95 +105,17 @@ sub valid_edit {
town => $validation->param('town'),
sector => $validation->param('sector'),
postcode => $validation->param('postcode'),
pending => defined $validation->param('pending') ? 0 : 1,
});
} );
} finally {
if ( @_ ) {
$c->flash( error => 'Something went wrong Updating the Organisation' );
$c->app->log->warn(Dumper @_);
} else {
$c->flash( success => 'Updated Organisation' );
}
};
$c->redirect_to( '/admin/organisations/valid/' . $valid_org->id );
}
sub pending_read {
my $c = shift;
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
my $transactions = $pending_org->transactions->search(
undef, {
page => $c->param('page') || 1,
rows => 10,
},
);
$c->stash(
pending_org => $pending_org,
transactions => $transactions,
);
}
sub pending_edit {
my $c = shift;
my $validation = $c->validation;
$validation->required('name');
$validation->required('street_name');
$validation->required('town');
$validation->required('postcode')->postcode;
if ( $validation->has_error ) {
$c->flash( error => 'The validation has failed' );
$c->app->log->warn(Dumper $validation);
return $c->redirect_to( '/admin/organisations/pending/' . $c->param('id') );
}
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
try {
$c->schema->storage->txn_do( sub {
$pending_org->update({
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
postcode => $validation->param('postcode'),
});
} );
} finally {
if ( @_ ) {
$c->flash( error => 'Something went wrong Updating the Organisation' );
$c->app->log->warn(Dumper @_);
} else {
$c->flash( success => 'Updated Organisation' );
}
};
$c->redirect_to( '/admin/organisations/pending/' . $pending_org->id );
}
sub pending_approve {
my $c = shift;
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
my $valid_org;
try {
$c->schema->storage->txn_do( sub {
$valid_org = $c->schema->resultset('Organisation')->create({
name => $pending_org->name,
street_name => $pending_org->street_name,
town => $pending_org->town,
postcode => $pending_org->postcode,
});
$c->copy_transactions_and_delete( $pending_org, $valid_org );
} );
} finally {
if ( @_ ) {
$c->flash( error => 'Something went wrong Validating the Organisation' );
$c->redirect_to( '/admin/organisations/pending/' . $pending_org->id );
} else {
$c->flash( success => 'Validated Organisation' );
$c->redirect_to( '/admin/organisations/valid/' . $valid_org->id );
}
}
$c->redirect_to( '/admin/organisations/' . $valid_org->id );
}
1;

View file

@ -40,7 +40,7 @@ sub read {
}
}
sub edit {
sub update {
my $c = shift;
my $id = $c->param('id');
@ -61,10 +61,10 @@ sub edit {
$validation->required('postcode')->postcode;
$validation->optional('new_password');
if ( defined $user->customer_id ) {
if ( $user->type eq 'customer' ) {
$validation->required('display_name');
$validation->required('full_name');
} elsif ( defined $user->organisation_id ) {
} elsif ( $user->type eq 'organisation' ) {
$validation->required('name');
$validation->required('street_name');
$validation->required('town');
@ -73,15 +73,14 @@ sub edit {
if ( $validation->has_error ) {
$c->flash( error => 'The validation has failed' );
$c->app->log->warn(Dumper $validation);
return $c->redirect_to( '/admin/users/' . $id );
}
if ( defined $user->customer_id ){
if ( $user->type eq 'customer' ){
try {
$c->schema->txn_do( sub {
$user->customer->update({
$user->entity->customer->update({
full_name => $validation->param('full_name'),
display_name => $validation->param('display_name'),
postcode => $validation->param('postcode'),
@ -100,11 +99,11 @@ sub edit {
};
}
}
elsif ( defined $user->organisation_id ) {
elsif ( $user->type eq 'organisation' ) {
try {
$c->schema->txn_do( sub {
$user->organisation->update({
$user->entity->organisation->update({
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
@ -129,9 +128,4 @@ sub edit {
$c->redirect_to( '/admin/users/' . $id );
}
sub update {
my $c = shift;
$c->redirect_to( '/admin/users' );
}
1;

View file

@ -48,7 +48,7 @@ has error_messages => sub {
};
};
sub post_register{
sub post_register {
my $c = shift;
my $validation = $c->validation;
@ -87,17 +87,19 @@ sub post_register{
name => $validation->param('token'),
used => 0,
})->update({ used => 1 });
# Create customer as a seperate step, so we dont leak data
my $customer = $c->schema->resultset('Customer')->create({
full_name => $validation->param('full_name'),
display_name => $validation->param('display_name'),
year_of_birth => $validation->param('year_of_birth'),
postcode => $validation->param('postcode'),
});
$c->schema->resultset('User')->create({
customer => $customer,
email => $validation->param('email'),
password => $validation->param('password'),
$c->schema->resultset('Entity')->create({
customer => {
full_name => $validation->param('full_name'),
display_name => $validation->param('display_name'),
year_of_birth => $validation->param('year_of_birth'),
postcode => $validation->param('postcode'),
},
user => {
email => $validation->param('email'),
password => $validation->param('password'),
},
type => 'customer',
});
});
@ -109,17 +111,19 @@ sub post_register{
name => $validation->param('token'),
used => 0,
})->update({ used => 1 });
my $organisation = $c->schema->resultset('Organisation')->create({
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
sector => $validation->param('sector'),
postcode => $validation->param('postcode'),
});
$c->schema->resultset('User')->create({
organisation => $organisation,
email => $validation->param('email'),
password => $validation->param('password'),
$c->schema->resultset('Entity')->create({
organisation => {
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
sector => $validation->param('sector'),
postcode => $validation->param('postcode'),
},
user => {
email => $validation->param('email'),
password => $validation->param('password'),
},
type => 'organisation',
});
});
}

View file

@ -15,21 +15,21 @@ has error_messages => sub {
sub post_index {
my $c = shift;
my $user = $c->stash->{api_user};
my $user = $c->stash->{api_user}->entity;
my $today_rs = $user->transactions->today_rs;
my $today_rs = $user->purchases->today_rs;
my $today_sum = $today_rs->get_column('value')->sum;
my $today_count = $today_rs->count;
my $week_rs = $user->transactions->week_rs;
my $week_rs = $user->purchases->week_rs;
my $week_sum = $week_rs->get_column('value')->sum;
my $week_count = $week_rs->count;
my $month_rs = $user->transactions->month_rs;
my $month_rs = $user->purchases->month_rs;
my $month_sum = $month_rs->get_column('value')->sum;
my $month_count = $month_rs->count;
my $user_rs = $user->transactions;
my $user_rs = $user->purchases;
my $user_sum = $user_rs->get_column('value')->sum;
my $user_count = $user_rs->count;
@ -40,7 +40,7 @@ sub post_index {
my $leaderboard_rs = $c->schema->resultset('Leaderboard');
my $monthly_board = $leaderboard_rs->get_latest( 'monthly_total' );
my $monthly_values = $monthly_board->values;
my $current_user_position = $monthly_values ? $monthly_values->find({ user_id => $c->stash->{api_user}->id }) : undef;
my $current_user_position = $monthly_values ? $monthly_values->find({ entity_id => $user->id }) : undef;
return $c->render( json => {
success => Mojo::JSON->true,
@ -84,14 +84,14 @@ sub post_leaderboards {
/,
{ display_name => 'customer.display_name' },
],
join => { user => 'customer' },
join => { entity => 'customer' },
},
);
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
my @leaderboard_array = $today_values->all;
my $current_user_position = $today_values->find({ user_id => $c->stash->{api_user}->id });
my $current_user_position = $today_values->find({ entity_id => $c->stash->{api_user}->entity->id });
return $c->render( json => {
success => Mojo::JSON->true,

View file

@ -112,7 +112,7 @@ sub post_upload {
if ( $type == 1 ) {
# Validated Organisation
my $valid_org_rs = $c->schema->resultset('Organisation');
my $valid_org_rs = $c->schema->resultset('Organisation')->search({ pending => 0 });
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
return $c->api_validation_error if $validation->has_error;
@ -121,7 +121,7 @@ sub post_upload {
} elsif ( $type == 2 ) {
# Unvalidated Organisation
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id });
my $valid_org_rs = $c->schema->resultset('Organisation')->search({ submitted_by_id => $user->id, pending => 1 });
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
return $c->api_validation_error if $validation->has_error;
@ -137,14 +137,15 @@ sub post_upload {
return $c->api_validation_error if $validation->has_error;
$organisation = $c->schema->resultset('PendingOrganisation')->create({
submitted_by => $user,
submitted_at => DateTime->now,
name => $validation->param('organisation_name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
postcode => $validation->param('postcode'),
my $entity = $c->schema->resultset('Entity')->create_org({
submitted_by_id => $user->id,
name => $validation->param('organisation_name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
postcode => $validation->param('postcode'),
pending => \"1"
});
$organisation = $entity->organisation;
}
unless ( defined $organisation ) {
@ -164,12 +165,12 @@ sub post_upload {
$purchase_time ||= DateTime->now();
my $file = defined $upload ? $c->store_file_from_upload( $upload ) : undef;
my $new_transaction = $organisation->create_related(
'transactions',
my $new_transaction = $organisation->entity->create_related(
'sales',
{
buyer => $user,
buyer => $user->entity,
value => $transaction_value,
( defined $file ? ( proof_image => $file ) : ( proof_image => 'a' ) ),
( defined $file ? ( proof_image => $file ) : () ),
purchase_time => $c->format_db_datetime($purchase_time),
}
);
@ -209,11 +210,15 @@ sub post_search {
my $search_stmt = [ 'LOWER("name") LIKE ?', '%' . lc $search_name . '%' ];
my $valid_orgs_rs = $c->schema->resultset('Organisation')->search(
my $org_rs = $c->schema->resultset('Organisation');
my $valid_orgs_rs = $org_rs->search({ pending => 0 })->search(
\$search_stmt,
);
my $pending_orgs_rs = $c->stash->{api_user}->pending_organisations->search(
my $pending_orgs_rs = $org_rs->search({
pending => 1,
submitted_by_id => $c->stash->{api_user}->id,
})->search(
\$search_stmt,
);

View file

@ -65,12 +65,12 @@ sub post_account {
my $postcode;
#Needs elsif added for trader page for this similar relevant entry
if ( defined $user_result->customer_id ) {
$full_name = $user_result->customer->full_name;
$display_name = $user_result->customer->display_name;
$postcode = $user_result->customer->postcode;
} elsif ( defined $user_result->organisation_id ) {
$display_name = $user_result->organisation->name;
if ( $user_result->type eq 'customer' ) {
$full_name = $user_result->entity->customer->full_name;
$display_name = $user_result->entity->customer->display_name;
$postcode = $user_result->entity->customer->postcode;
} elsif ( $user_result->type eq 'organisation' ) {
$display_name = $user_result->entity->organisation->name;
} else {
return;
}
@ -121,10 +121,10 @@ sub post_account_update {
$validation->required('postcode')->postcode;
$validation->optional('new_password');
if ( defined $user->customer_id ) {
if ( $user->type eq 'customer' ) {
$validation->required('display_name');
$validation->required('full_name');
} elsif ( defined $user->organisation_id ) {
} elsif ( $user->type eq 'organisation' ) {
$validation->required('name');
$validation->required('street_name');
$validation->required('town');
@ -133,10 +133,10 @@ sub post_account_update {
return $c->api_validation_error if $validation->has_error;
if ( defined $user->customer_id ){
if ( $user->type eq 'customer' ){
$c->schema->txn_do( sub {
$user->customer->update({
$user->entity->customer->update({
full_name => $validation->param('full_name'),
display_name => $validation->param('display_name'),
postcode => $validation->param('postcode'),
@ -148,10 +148,10 @@ sub post_account_update {
});
}
elsif ( defined $user->organisation_id ) {
elsif ( $user->type eq 'organisation' ) {
$c->schema->txn_do( sub {
$user->organisation->update({
$user->entity->organisation->update({
name => $validation->param('name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),

View file

@ -56,7 +56,7 @@ sub graph_customers_last_30_days {
sub _customers_last_duration {
my ( $c, $duration ) = @_;
my $org = $c->stash->{api_user}->organisation;
my $org = $c->stash->{api_user}->entity;
my $data = { day => [], count => [] };

View file

@ -6,7 +6,7 @@ use warnings;
use base 'DBIx::Class::Schema';
our $VERSION = 5;
our $VERSION = 6;
__PACKAGE__->load_namespaces;

View file

@ -1,28 +0,0 @@
package Pear::LocalLoop::Schema::Result::Administrator;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("administrators");
__PACKAGE__->add_columns(
"user_id",
{
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
);
__PACKAGE__->set_primary_key("user_id");
__PACKAGE__->belongs_to(
"user",
"Pear::LocalLoop::Schema::Result::User",
{ id => "user_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
1;

View file

@ -13,6 +13,11 @@ __PACKAGE__->add_columns(
is_auto_increment => 1,
is_nullable => 0,
},
"entity_id" => {
data_type => "integer",
is_nullable => 0,
is_foreign_key => 1,
},
"display_name" => {
data_type => "varchar",
size => 255,
@ -36,11 +41,10 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have(
"user",
"Pear::LocalLoop::Schema::Result::User",
{ "foreign.customer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
__PACKAGE__->belongs_to(
"entity",
"Pear::LocalLoop::Schema::Result::Entity",
"entity_id",
);
1;

View file

@ -0,0 +1,66 @@
package Pear::LocalLoop::Schema::Result::Entity;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("entities");
__PACKAGE__->add_columns(
"id" => {
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
},
"type" => {
data_type => "varchar",
size => 255,
is_nullable => 0,
},
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have(
"customer",
"Pear::LocalLoop::Schema::Result::Customer" => "entity_id",
);
__PACKAGE__->might_have(
"organisation",
"Pear::LocalLoop::Schema::Result::Organisation" => "entity_id",
);
__PACKAGE__->might_have(
"user",
"Pear::LocalLoop::Schema::Result::User" => "entity_id",
);
__PACKAGE__->has_many(
"purchases",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"sales",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.seller_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
sub name {
my $self = shift;
if ( $self->type eq 'customer' ) {
return $self->customer->display_name;
} elsif ( $self->type eq 'organisation' ) {
return $self->organisation->name;
} else {
return "Unknown Name";
}
}
1;

View file

@ -14,7 +14,11 @@ __PACKAGE__->load_components(qw/
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0
},
"user_id" => {
data_type => "integer",
is_foreign_key => 1,

View file

@ -67,8 +67,8 @@ sub create_new {
sub _get_customer_rs {
my $self = shift;
return $self->result_source->schema->resultset('User')->search({
organisation_id => undef,
return $self->result_source->schema->resultset('Entity')->search({
type => 'customer',
});
}
@ -93,7 +93,7 @@ sub _set_position_and_trend {
my $previous_value;
if ( defined $previous_board ) {
$previous_value = $previous_board->find({ user_id => $lb_val->{user_id} });
$previous_value = $previous_board->find({ entity_id => $lb_val->{entity_id} });
}
my $trend;
@ -122,12 +122,12 @@ sub _create_total_set {
my @leaderboard;
while ( my $user_result = $user_rs->next ) {
my $transaction_rs = $user_result->transactions->search_between( $start, $end );
my $transaction_rs = $user_result->purchases->search_between( $start, $end );
my $transaction_sum = $transaction_rs->get_column('value')->sum;
push @leaderboard, {
user_id => $user_result->id,
entity_id => $user_result->id,
value => $transaction_sum || 0,
};
}
@ -153,12 +153,12 @@ sub _create_count_set {
my @leaderboard;
while ( my $user_result = $user_rs->next ) {
my $transaction_rs = $user_result->transactions->search_between( $start, $end );
my $transaction_rs = $user_result->purchases->search_between( $start, $end );
my $transaction_count = $transaction_rs->count;
push @leaderboard, {
user_id => $user_result->id,
entity_id => $user_result->id,
value => $transaction_count || 0,
};
}
@ -184,12 +184,12 @@ sub _create_total_all_time {
my @leaderboard;
while ( my $user_result = $user_rs->next ) {
my $transaction_rs = $user_result->transactions->search_before( $end );
my $transaction_rs = $user_result->purchases->search_before( $end );
my $transaction_sum = $transaction_rs->get_column('value')->sum;
push @leaderboard, {
user_id => $user_result->id,
entity_id => $user_result->id,
value => $transaction_sum || 0,
};
}
@ -215,12 +215,12 @@ sub _create_count_all_time {
my @leaderboard;
while ( my $user_result = $user_rs->next ) {
my $transaction_rs = $user_result->transactions->search_before( $end );
my $transaction_rs = $user_result->purchases->search_before( $end );
my $transaction_count = $transaction_rs->count;
push @leaderboard, {
user_id => $user_result->id,
entity_id => $user_result->id,
value => $transaction_count || 0,
};
}

View file

@ -13,7 +13,7 @@ __PACKAGE__->add_columns(
is_auto_increment => 1,
is_nullable => 0,
},
"user_id" => {
"entity_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
@ -40,7 +40,7 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint([qw/ user_id set_id /]);
__PACKAGE__->add_unique_constraint([qw/ entity_id set_id /]);
__PACKAGE__->belongs_to(
"set",
@ -55,9 +55,9 @@ __PACKAGE__->belongs_to(
);
__PACKAGE__->belongs_to(
"user",
"Pear::LocalLoop::Schema::Result::User",
{ "foreign.id" => "self.user_id" },
"entity",
"Pear::LocalLoop::Schema::Result::Entity",
{ "foreign.id" => "self.entity_id" },
{
is_deferrable => 0,
join_type => "LEFT",

View file

@ -15,6 +15,11 @@ __PACKAGE__->add_columns(
is_auto_increment => 1,
is_nullable => 0,
},
entity_id => {
data_type => 'integer',
is_nullable => 0,
is_foreign_key => 1,
},
name => {
data_type => 'varchar',
size => 255,
@ -34,27 +39,33 @@ __PACKAGE__->add_columns(
size => 16,
is_nullable => 1,
},
country => {
data_type => 'varchar',
size => 255,
is_nullable => 1,
},
sector => {
data_type => "varchar",
data_type => 'varchar',
size => 1,
is_nullable => 1,
},
pending => {
data_type => 'boolean',
default_value => \"0",
is_nullable => 0,
},
submitted_by_id => {
data_type => 'integer',
is_nullable => 1,
},
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(
"transactions",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.seller_id" => 'self.id' },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->might_have(
"user",
"Pear::LocalLoop::Schema::Result::User",
{ "foreign.organisation_id" => 'self.id' },
{ cascade_copy => 0, cascade_delete => 0 },
__PACKAGE__->belongs_to(
"entity",
"Pear::LocalLoop::Schema::Result::Entity",
"entity_id",
);
1;

View file

@ -1,70 +0,0 @@
package Pear::LocalLoop::Schema::Result::PendingOrganisation;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components( qw/
InflateColumn::DateTime
TimeStamp
/);
__PACKAGE__->table("pending_organisations");
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0,
},
name => {
data_type => 'varchar',
size => 255,
is_nullable => 0,
},
street_name => {
data_type => 'text',
is_nullable => 1,
},
town => {
data_type => 'varchar',
size => 255,
is_nullable => 0,
},
postcode => {
data_type => 'varchar',
size => 16,
is_nullable => 1,
},
submitted_by_id => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
submitted_at => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(
"transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction",
{
"foreign.seller_id" => "self.id",
},
{ cascade_copy => 0, cascade_delete => 1 },
);
__PACKAGE__->belongs_to(
"submitted_by",
"Pear::LocalLoop::Schema::Result::User",
{ id => "submitted_by_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
1;

View file

@ -1,69 +0,0 @@
package Pear::LocalLoop::Schema::Result::PendingTransaction;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components( qw/
InflateColumn::DateTime
TimeStamp
/);
__PACKAGE__->table("pending_transactions");
__PACKAGE__->add_columns(
"id" => {
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
},
"buyer_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"seller_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"value" => {
data_type => "decimal",
size => [ 16, 2 ],
is_nullable => 0,
},
"proof_image" => {
data_type => "text",
is_nullable => 0,
},
"submitted_at" => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
"purchase_time" => {
data_type => "datetime",
timezone => "UTC",
is_nullable => 0,
set_on_create => 1,
},
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"buyer",
"Pear::LocalLoop::Schema::Result::User",
{ id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
__PACKAGE__->belongs_to(
"seller",
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
{ id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
1;

View file

@ -35,7 +35,7 @@ __PACKAGE__->add_columns(
},
"proof_image" => {
data_type => "text",
is_nullable => 0,
is_nullable => 1,
},
"submitted_at" => {
data_type => "datetime",
@ -54,14 +54,14 @@ __PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
"buyer",
"Pear::LocalLoop::Schema::Result::User",
"Pear::LocalLoop::Schema::Result::Entity",
{ id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
__PACKAGE__->belongs_to(
"seller",
"Pear::LocalLoop::Schema::Result::Organisation",
"Pear::LocalLoop::Schema::Result::Entity",
{ id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);

View file

@ -21,15 +21,10 @@ __PACKAGE__->add_columns(
is_auto_increment => 1,
is_nullable => 0,
},
"customer_id" => {
"entity_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 1,
},
"organisation_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 1,
is_nullable => 0,
},
"email" => {
data_type => "text",
@ -51,59 +46,21 @@ __PACKAGE__->add_columns(
},
passphrase_check_method => 'check_password',
},
"is_admin" => {
data_type => "boolean",
default_value => \"0",
is_nullable => 0,
},
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint(["customer_id"]);
__PACKAGE__->add_unique_constraint(["email"]);
__PACKAGE__->add_unique_constraint(["organisation_id"]);
__PACKAGE__->might_have(
"administrator",
"Pear::LocalLoop::Schema::Result::Administrator",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"customer",
"Pear::LocalLoop::Schema::Result::Customer",
{ "foreign.id" => "self.customer_id" },
{
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
);
__PACKAGE__->belongs_to(
"organisation",
"Pear::LocalLoop::Schema::Result::Organisation",
{ "foreign.id" => "self.organisation_id" },
{
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
);
__PACKAGE__->has_many(
"pending_organisations",
"Pear::LocalLoop::Schema::Result::PendingOrganisation",
{ "foreign.submitted_by_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"pending_transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction",
{ "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
"entity",
"Pear::LocalLoop::Schema::Result::Entity",
"entity_id",
);
__PACKAGE__->has_many(
@ -113,13 +70,6 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"transactions",
"Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"feedback",
"Pear::LocalLoop::Schema::Result::Feedback",
@ -144,22 +94,20 @@ sub generate_session {
sub name {
my $self = shift;
if ( defined $self->customer_id ) {
return $self->customer->display_name;
} elsif ( defined $self->organisation_id ) {
return $self->organisation->name;
if ( defined $self->entity->customer ) {
return $self->entity->customer->display_name;
} elsif ( defined $self->entity->organisation ) {
return $self->entity->organisation->name;
} else {
return;
}
}
# TODO Deprecate this sub?
sub type {
my $self = shift;
if ( defined $self->customer_id ) {
return "customer";
}
return "organisation";
return $self->entity->type;
}
1;

View file

@ -0,0 +1,19 @@
package Pear::LocalLoop::Schema::ResultSet::Entity;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub sales { shift->search_related('sales', @_) }
sub create_org {
my ( $self, $org ) = @_;
return $self->create({
organisation => $org,
type => 'organisation',
});
}
1;

View file

@ -0,0 +1,10 @@
package Pear::LocalLoop::Schema::ResultSet::Organisation;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub entity { shift->search_related('entity', @_) }
1;

36
script/schema/graph.pl Executable file
View file

@ -0,0 +1,36 @@
#! /usr/bin/env perl
use strict;
use warnings;
use feature "say";
use FindBin qw/ $Bin /;
use lib "$Bin/../../lib";
use SQL::Translator;
use Pear::LocalLoop::Schema;
say "Setting up Translator and Schema";
my $schema = Pear::LocalLoop::Schema->connect;
my $tr = SQL::Translator->new(
from => "SQL::Translator::Parser::DBIx::Class",
to => 'GraphViz',
debug => 1,
trace => 1,
producer_args => {
out_file => "$Bin/../../schema.png",
output_type => 'png',
width => 0,
height => 0,
show_constraints => 1,
show_datatypes => 1,
show_sizes => 1,
},
);
say "Translating Schema to image";
$tr->translate( data => $schema );
say "Finished";

View file

@ -0,0 +1,18 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Fri Sep 1 15:14:28 2017
--
;
--
-- Table: dbix_class_deploymenthandler_versions
--
CREATE TABLE "dbix_class_deploymenthandler_versions" (
"id" serial NOT NULL,
"version" character varying(50) NOT NULL,
"ddl" text,
"upgrade_sql" text,
PRIMARY KEY ("id"),
CONSTRAINT "dbix_class_deploymenthandler_versions_version" UNIQUE ("version")
);
;

View file

@ -0,0 +1,210 @@
--
-- Created by SQL::Translator::Producer::PostgreSQL
-- Created on Fri Sep 1 15:14:28 2017
--
;
--
-- Table: account_tokens
--
CREATE TABLE "account_tokens" (
"id" serial NOT NULL,
"name" text NOT NULL,
"used" integer DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "account_tokens_name" UNIQUE ("name")
);
;
--
-- Table: entities
--
CREATE TABLE "entities" (
"id" serial NOT NULL,
"type" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
;
--
-- Table: leaderboards
--
CREATE TABLE "leaderboards" (
"id" serial NOT NULL,
"name" character varying(255) NOT NULL,
"type" character varying(255) NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "leaderboards_type" UNIQUE ("type")
);
;
--
-- Table: customers
--
CREATE TABLE "customers" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"display_name" character varying(255) NOT NULL,
"full_name" character varying(255) NOT NULL,
"year_of_birth" integer NOT NULL,
"postcode" character varying(16) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "customers_idx_entity_id" on "customers" ("entity_id");
;
--
-- Table: leaderboard_sets
--
CREATE TABLE "leaderboard_sets" (
"id" serial NOT NULL,
"leaderboard_id" integer NOT NULL,
"date" timestamp NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "leaderboard_sets_idx_leaderboard_id" on "leaderboard_sets" ("leaderboard_id");
;
--
-- Table: organisations
--
CREATE TABLE "organisations" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"name" character varying(255) NOT NULL,
"street_name" text,
"town" character varying(255) NOT NULL,
"postcode" character varying(16),
"country" character varying(255),
"sector" character varying(1),
"pending" boolean DEFAULT 0 NOT NULL,
"submitted_by_id" integer,
PRIMARY KEY ("id")
);
CREATE INDEX "organisations_idx_entity_id" on "organisations" ("entity_id");
;
--
-- Table: transactions
--
CREATE TABLE "transactions" (
"id" serial NOT NULL,
"buyer_id" integer NOT NULL,
"seller_id" integer NOT NULL,
"value" numeric(16,2) NOT NULL,
"proof_image" text,
"submitted_at" timestamp NOT NULL,
"purchase_time" timestamp NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "transactions_idx_buyer_id" on "transactions" ("buyer_id");
CREATE INDEX "transactions_idx_seller_id" on "transactions" ("seller_id");
;
--
-- Table: users
--
CREATE TABLE "users" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"email" text NOT NULL,
"join_date" timestamp NOT NULL,
"password" character varying(100) NOT NULL,
"is_admin" boolean DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "users_email" UNIQUE ("email")
);
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
;
--
-- Table: feedback
--
CREATE TABLE "feedback" (
"id" serial NOT NULL,
"user_id" integer NOT NULL,
"submitted_at" timestamp NOT NULL,
"feedbacktext" text NOT NULL,
"app_name" character varying(255) NOT NULL,
"package_name" character varying(255) NOT NULL,
"version_code" character varying(255) NOT NULL,
"version_number" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "feedback_idx_user_id" on "feedback" ("user_id");
;
--
-- Table: session_tokens
--
CREATE TABLE "session_tokens" (
"id" serial NOT NULL,
"token" character varying(255) NOT NULL,
"user_id" integer NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "session_tokens_token" UNIQUE ("token")
);
CREATE INDEX "session_tokens_idx_user_id" on "session_tokens" ("user_id");
;
--
-- Table: leaderboard_values
--
CREATE TABLE "leaderboard_values" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"set_id" integer NOT NULL,
"position" integer NOT NULL,
"value" numeric(16,2) NOT NULL,
"trend" integer DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "leaderboard_values_entity_id_set_id" UNIQUE ("entity_id", "set_id")
);
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
;
--
-- Foreign Key Definitions
--
;
ALTER TABLE "customers" ADD CONSTRAINT "customers_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "leaderboard_sets" ADD CONSTRAINT "leaderboard_sets_fk_leaderboard_id" FOREIGN KEY ("leaderboard_id")
REFERENCES "leaderboards" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "organisations" ADD CONSTRAINT "organisations_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_buyer_id" FOREIGN KEY ("buyer_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "transactions" ADD CONSTRAINT "transactions_fk_seller_id" FOREIGN KEY ("seller_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "users" ADD CONSTRAINT "users_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE CASCADE DEFERRABLE;
;
ALTER TABLE "feedback" ADD CONSTRAINT "feedback_fk_user_id" FOREIGN KEY ("user_id")
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "session_tokens" ADD CONSTRAINT "session_tokens_fk_user_id" FOREIGN KEY ("user_id")
REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_entity_id" FOREIGN KEY ("entity_id")
REFERENCES "entities" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;
ALTER TABLE "leaderboard_values" ADD CONSTRAINT "leaderboard_values_fk_set_id" FOREIGN KEY ("set_id")
REFERENCES "leaderboard_sets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
;

View file

@ -0,0 +1,85 @@
-- Convert schema 'share/ddl/_source/deploy/5/001-auto.yml' to 'share/ddl/_source/deploy/6/001-auto.yml':;
-- Customised for proper migration
BEGIN;
CREATE TABLE "entities" (
"id" serial NOT NULL,
"type" character varying(255) NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE customers RENAME TO customers_temp;
ALTER TABLE organisations RENAME TO organisations_temp;
ALTER TABLE transactions RENAME TO transactions_temp;
ALTER TABLE users RENAME TO users_temp;
CREATE TABLE "customers" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"display_name" character varying(255) NOT NULL,
"full_name" character varying(255) NOT NULL,
"year_of_birth" integer NOT NULL,
"postcode" character varying(16) NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "customers_idx_entity_id" on "customers" ("entity_id");
CREATE TABLE "organisations" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"name" character varying(255) NOT NULL,
"street_name" text,
"town" character varying(255) NOT NULL,
"postcode" character varying(16),
"country" character varying(255),
"sector" character varying(1),
"pending" boolean DEFAULT 0 NOT NULL,
"submitted_by_id" integer,
PRIMARY KEY ("id")
);
CREATE INDEX "organisations_idx_entity_id" on "organisations" ("entity_id");
CREATE TABLE "transactions" (
"id" serial NOT NULL,
"buyer_id" integer NOT NULL,
"seller_id" integer NOT NULL,
"value" numeric(16,2) NOT NULL,
"proof_image" text,
"submitted_at" timestamp NOT NULL,
"purchase_time" timestamp NOT NULL,
PRIMARY KEY ("id")
);
CREATE INDEX "transactions_idx_buyer_id" on "transactions" ("buyer_id");
CREATE INDEX "transactions_idx_seller_id" on "transactions" ("seller_id");
CREATE TABLE "users" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"email" text NOT NULL,
"join_date" timestamp NOT NULL,
"password" character varying(100) NOT NULL,
"is_admin" boolean DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "users_email" UNIQUE ("email")
);
CREATE INDEX "users_idx_entity_id" on "users" ("entity_id");
DROP TABLE leaderboard_values;
TRUNCATE TABLE leaderboard_sets;
CREATE TABLE "leaderboard_values" (
"id" serial NOT NULL,
"entity_id" integer NOT NULL,
"set_id" integer NOT NULL,
"position" integer NOT NULL,
"value" numeric(16,2) NOT NULL,
"trend" integer DEFAULT 0 NOT NULL,
PRIMARY KEY ("id"),
CONSTRAINT "leaderboard_values_entity_id_set_id" UNIQUE ("entity_id", "set_id")
);
CREATE INDEX "leaderboard_values_idx_entity_id" on "leaderboard_values" ("entity_id");
CREATE INDEX "leaderboard_values_idx_set_id" on "leaderboard_values" ("set_id");
COMMIT;

View file

@ -0,0 +1,13 @@
-- Remove temporary tables created during migration
BEGIN;
DROP TABLE customers_temp;
DROP TABLE organisations_temp;
DROP TABLE transactions_temp;
DROP TABLE users_temp;
DROP TABLE pending_organisations;
DROP TABLE pending_transactions;
DROP TABLE administrators;
COMMIT;

View file

@ -0,0 +1,18 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Fri Sep 1 15:14:28 2017
--
;
BEGIN TRANSACTION;
--
-- Table: dbix_class_deploymenthandler_versions
--
CREATE TABLE dbix_class_deploymenthandler_versions (
id INTEGER PRIMARY KEY NOT NULL,
version varchar(50) NOT NULL,
ddl text,
upgrade_sql text
);
CREATE UNIQUE INDEX dbix_class_deploymenthandler_versions_version ON dbix_class_deploymenthandler_versions (version);
COMMIT;

View file

@ -0,0 +1,145 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Fri Sep 1 15:14:28 2017
--
;
BEGIN TRANSACTION;
--
-- Table: account_tokens
--
CREATE TABLE account_tokens (
id INTEGER PRIMARY KEY NOT NULL,
name text NOT NULL,
used integer NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX account_tokens_name ON account_tokens (name);
--
-- Table: entities
--
CREATE TABLE entities (
id INTEGER PRIMARY KEY NOT NULL,
type varchar(255) NOT NULL
);
--
-- Table: leaderboards
--
CREATE TABLE leaderboards (
id INTEGER PRIMARY KEY NOT NULL,
name varchar(255) NOT NULL,
type varchar(255) NOT NULL
);
CREATE UNIQUE INDEX leaderboards_type ON leaderboards (type);
--
-- Table: customers
--
CREATE TABLE customers (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
display_name varchar(255) NOT NULL,
full_name varchar(255) NOT NULL,
year_of_birth integer NOT NULL,
postcode varchar(16) NOT NULL,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX customers_idx_entity_id ON customers (entity_id);
--
-- Table: leaderboard_sets
--
CREATE TABLE leaderboard_sets (
id INTEGER PRIMARY KEY NOT NULL,
leaderboard_id integer NOT NULL,
date datetime NOT NULL,
FOREIGN KEY (leaderboard_id) REFERENCES leaderboards(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX leaderboard_sets_idx_leaderboard_id ON leaderboard_sets (leaderboard_id);
--
-- Table: organisations
--
CREATE TABLE organisations (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
name varchar(255) NOT NULL,
street_name text,
town varchar(255) NOT NULL,
postcode varchar(16),
country varchar(255),
sector varchar(1),
pending boolean NOT NULL DEFAULT 0,
submitted_by_id integer,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX organisations_idx_entity_id ON organisations (entity_id);
--
-- Table: transactions
--
CREATE TABLE transactions (
id INTEGER PRIMARY KEY NOT NULL,
buyer_id integer NOT NULL,
seller_id integer NOT NULL,
value decimal(16,2) NOT NULL,
proof_image text,
submitted_at datetime NOT NULL,
purchase_time datetime NOT NULL,
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX transactions_idx_buyer_id ON transactions (buyer_id);
CREATE INDEX transactions_idx_seller_id ON transactions (seller_id);
--
-- Table: users
--
CREATE TABLE users (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
email text NOT NULL,
join_date datetime NOT NULL,
password varchar(100) NOT NULL,
is_admin boolean NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX users_idx_entity_id ON users (entity_id);
CREATE UNIQUE INDEX users_email ON users (email);
--
-- Table: feedback
--
CREATE TABLE feedback (
id INTEGER PRIMARY KEY NOT NULL,
user_id integer NOT NULL,
submitted_at datetime NOT NULL,
feedbacktext text NOT NULL,
app_name varchar(255) NOT NULL,
package_name varchar(255) NOT NULL,
version_code varchar(255) NOT NULL,
version_number varchar(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX feedback_idx_user_id ON feedback (user_id);
--
-- Table: session_tokens
--
CREATE TABLE session_tokens (
id INTEGER PRIMARY KEY NOT NULL,
token varchar(255) NOT NULL,
user_id integer NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX session_tokens_idx_user_id ON session_tokens (user_id);
CREATE UNIQUE INDEX session_tokens_token ON session_tokens (token);
--
-- Table: leaderboard_values
--
CREATE TABLE leaderboard_values (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
set_id integer NOT NULL,
position integer NOT NULL,
value decimal(16,2) NOT NULL,
trend integer NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX leaderboard_values_idx_entity_id ON leaderboard_values (entity_id);
CREATE INDEX leaderboard_values_idx_set_id ON leaderboard_values (set_id);
CREATE UNIQUE INDEX leaderboard_values_entity_id_set_id ON leaderboard_values (entity_id, set_id);
COMMIT;

View file

@ -0,0 +1,90 @@
-- Convert schema 'share/ddl/_source/deploy/5/001-auto.yml' to 'share/ddl/_source/deploy/6/001-auto.yml':;
-- Customised for proper migration
BEGIN;
CREATE TABLE entities (
id INTEGER PRIMARY KEY NOT NULL,
type varchar(255) NOT NULL
);
ALTER TABLE customers RENAME TO customers_temp;
CREATE TABLE customers (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
display_name varchar(255) NOT NULL,
full_name varchar(255) NOT NULL,
year_of_birth integer NOT NULL,
postcode varchar(16) NOT NULL,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX customers_idx_entity_id ON customers (entity_id);
-- Leaderboards must be regenerated, this saves trying to do this the hard way
DROP TABLE leaderboard_values;
DELETE FROM leaderboard_sets;
CREATE TABLE leaderboard_values (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
set_id integer NOT NULL,
position integer NOT NULL,
value decimal(16,2) NOT NULL,
trend integer NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (set_id) REFERENCES leaderboard_sets(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX leaderboard_values_idx_entity_id ON leaderboard_values (entity_id);
CREATE INDEX leaderboard_values_idx_set_id ON leaderboard_values (set_id);
CREATE UNIQUE INDEX leaderboard_values_entity_id_set_id ON leaderboard_values (entity_id, set_id);
ALTER TABLE organisations RENAME TO organisations_temp;
CREATE TABLE organisations (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
name varchar(255) NOT NULL,
street_name text,
town varchar(255) NOT NULL,
postcode varchar(16),
country varchar(255),
sector varchar(1),
pending boolean NOT NULL DEFAULT 0,
submitted_by_id integer,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX organisations_idx_entity_id ON organisations (entity_id);
ALTER TABLE transactions RENAME TO transactions_temp;
CREATE TABLE transactions (
id INTEGER PRIMARY KEY NOT NULL,
buyer_id integer NOT NULL,
seller_id integer NOT NULL,
value decimal(16,2) NOT NULL,
proof_image text,
submitted_at datetime NOT NULL,
purchase_time datetime NOT NULL,
FOREIGN KEY (buyer_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION,
FOREIGN KEY (seller_id) REFERENCES entities(id) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE INDEX transactions_idx_buyer_id02 ON transactions (buyer_id);
CREATE INDEX transactions_idx_seller_id02 ON transactions (seller_id);
ALTER TABLE users RENAME TO users_temp;
CREATE TABLE users (
id INTEGER PRIMARY KEY NOT NULL,
entity_id integer NOT NULL,
email text NOT NULL,
join_date datetime NOT NULL,
password varchar(100) NOT NULL,
is_admin boolean NOT NULL DEFAULT 0,
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
);
CREATE INDEX users_idx_entity_id02 ON users (entity_id);
CREATE UNIQUE INDEX users_email02 ON users (email);
COMMIT;

View file

@ -0,0 +1,13 @@
-- Remove temporary tables created during migration
BEGIN;
DROP TABLE customers_temp;
DROP TABLE organisations_temp;
DROP TABLE transactions_temp;
DROP TABLE users_temp;
DROP TABLE pending_organisations;
DROP TABLE pending_transactions;
DROP TABLE administrators;
COMMIT;

View file

@ -0,0 +1,111 @@
#! perl
use strict;
use warnings;
use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers
'schema_from_schema_loader';
schema_from_schema_loader({ naming => 'v7' }, sub {
my $schema = shift;
my $user_rs = $schema->resultset('UsersTemp');
my $customer_rs = $schema->resultset('CustomersTemp');
my $organisation_rs = $schema->resultset('OrganisationsTemp');
my $transaction_rs = $schema->resultset('TransactionsTemp');
my $pending_org_rs = $schema->resultset('PendingOrganisation');
my $pending_trans_rs = $schema->resultset('PendingTransaction');
# Lookups used for converting transactions
my $org_lookup = {};
my $user_lookup = {};
# First migrate all customers, organisations, and pending organisations across to the entity table.
for my $customer_result ( $customer_rs->all ) {
my $user_result = $user_rs->find({ customer_id => $customer_result->id });
my $administrator = $schema->resultset('Administrator')->find({ user_id => $user_result->id });
my $new_entity = $schema->resultset('Entity')->create({ type => 'customer' });
my $new_customer = $schema->resultset('Customer')->create({
entity_id => $new_entity->id,
display_name => $customer_result->display_name,
full_name => $customer_result->full_name,
year_of_birth => $customer_result->year_of_birth,
postcode => $customer_result->postcode,
});
# In the old system, all customers were users
my $new_user = $schema->resultset('User')->create({
entity_id => $new_entity->id,
email => $user_result->email,
join_date => $user_result->join_date,
password => $user_result->password,
is_admin => defined $administrator ? 1 : 0,
});
$user_lookup->{$user_result->id} = $new_entity->id;
}
for my $organisation_result ( $organisation_rs->all ) {
my $user_result = $user_rs->find({ organisation_id => $organisation_result->id });
my $new_entity = $schema->resultset('Entity')->create({ type => 'organisation' });
my $org = $schema->resultset('Organisation')->create({
entity_id => $new_entity->id,
name => $organisation_result->name,
street_name => $organisation_result->street_name,
town => $organisation_result->town,
postcode => $organisation_result->postcode,
});
# In the old system, not all organisations were users - but could have still been an admin?
if ( defined $user_result ) {
my $administrator = $schema->resultset('Administrator')->find({ user_id => $user_result->id });
my $new_user = $schema->resultset('User')->create({
entity_id => $new_entity->id,
email => $user_result->email,
join_date => $user_result->join_date,
password => $user_result->password,
is_admin => defined $administrator ? 1 : 0,
});
$user_lookup->{$user_result->id} = $new_entity->id;
}
$org_lookup->{$organisation_result->id} = $new_entity->id;
}
for my $transaction_result ( $transaction_rs->all ) {
my $new_transaction = $schema->resultset('Transaction')->create({
buyer_id => $user_lookup->{ $transaction_result->buyer_id },
seller_id => $org_lookup->{ $transaction_result->seller_id },
value => $transaction_result->value,
proof_image => $transaction_result->proof_image,
submitted_at => $transaction_result->submitted_at,
purchase_time => $transaction_result->purchase_time,
});
}
for my $pending_result ( $pending_org_rs->all ) {
my $entity = $schema->resultset('Entity')->create({ type => 'organisation' });
my $org = $schema->resultset('Organisation')->create({
entity_id => $entity->id,
name => $pending_result->name,
street_name => $pending_result->street_name,
town => $pending_result->town,
postcode => $pending_result->postcode,
submitted_by_id => $user_lookup->{ $pending_result->submitted_by_id },
pending => 1,
});
my $pending_trans_set_rs = $pending_trans_rs->search({
seller_id => $pending_result->id,
});
for my $trans_result ( $pending_trans_set_rs->all ) {
$schema->resultset('Transaction')->create({
buyer_id => $user_lookup->{ $trans_result->buyer_id },
seller_id => $entity->id,
value => $trans_result->value,
proof_image => $trans_result->proof_image,
submitted_at => $trans_result->submitted_at,
purchase_time => $trans_result->purchase_time,
});
}
}
});

View file

@ -0,0 +1,91 @@
---
schema:
procedures: {}
tables:
dbix_class_deploymenthandler_versions:
constraints:
- deferrable: 1
expression: ''
fields:
- id
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
expression: ''
fields:
- version
match_type: ''
name: dbix_class_deploymenthandler_versions_version
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: UNIQUE
fields:
ddl:
data_type: text
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: ddl
order: 3
size:
- 0
id:
data_type: int
default_value: ~
is_auto_increment: 1
is_nullable: 0
is_primary_key: 1
is_unique: 0
name: id
order: 1
size:
- 0
upgrade_sql:
data_type: text
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: upgrade_sql
order: 4
size:
- 0
version:
data_type: varchar
default_value: ~
is_nullable: 0
is_primary_key: 0
is_unique: 1
name: version
order: 2
size:
- 50
indices: []
name: dbix_class_deploymenthandler_versions
options: []
order: 1
triggers: {}
views: {}
translator:
add_drop_table: 0
filename: ~
no_comments: 0
parser_args:
sources:
- __VERSION
parser_type: SQL::Translator::Parser::DBIx::Class
producer_args: {}
producer_type: SQL::Translator::Producer::YAML
show_warnings: 0
trace: 0
version: 0.11021

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

View file

@ -1,27 +1,18 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
$schema->resultset('User')->create({
email => 'admin@example.com',
password => 'abc123',
administrator => {},
});
$schema->resultset('User')->create({
email => 'user@example.com',
password => 'abc123',
});
is $schema->resultset('User')->count, 2, 'Users Created';
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
my $location_is = sub {
my ($t, $value, $desc) = @_;
$desc ||= "Location: $value";
@ -34,7 +25,7 @@ $t->get_ok('/admin')
$t->ua->max_redirects(10);
$t->post_ok('/admin', form => {
email => 'user@example.com',
email => 'test1@example.com',
password => 'abc123',
})->status_is(200);

View file

@ -1,38 +1,42 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
my $user = $schema->resultset('User')->create({
email => 'admin@example.com',
password => 'abc123',
administrator => {},
my $valid_entity = $schema->resultset('Entity')->create({
organisation => {
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
town => 'Gaia',
sector => 'A',
postcode => 'WC1E 6AD',
},
type => "organisation",
});
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
$schema->resultset('Organisation')->create({
id => 1,
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
town => 'Gaia',
sector => 'A',
postcode => 'WC1E 6AD',
my $pending_entity = $schema->resultset('Entity')->create({
organisation => {
name => '7th Heaven',
street_name => 'Slums, Sector 7',
town => 'Midgar',
sector => 'A',
postcode => 'WC1E 6AD',
pending => \"1",
},
type => "organisation",
});
$schema->resultset('PendingOrganisation')->create({
id => 2,
name => '7th Heaven',
street_name => 'Slums, Sector 7',
town => 'Midgar',
postcode => 'WC1E 6AD',
submitted_by_id => $user->id,
});
my $valid_id = $valid_entity->organisation->id;
my $pending_id = $pending_entity->organisation->id;
#login to admin
$t->ua->max_redirects(10);
@ -42,15 +46,15 @@ $t->post_ok('/admin', form => {
})->status_is(200);
#Read approved organisation
$t->get_ok('/admin/organisations/valid/1/')
->status_is(200);
$t->get_ok("/admin/organisations/$valid_id")
->status_is(200)->or($framework->dump_error);
#Read pending organisation
$t->get_ok('/admin/organisations/pending/2/')
->status_is(200);
$t->get_ok("/admin/organisations/$pending_id")
->status_is(200)->or($framework->dump_error);
#Valid approved organisation update
$t->post_ok('/admin/organisations/valid/1/edit', form => {
$t->post_ok("/admin/organisations/$valid_id", form => {
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
town => 'Gaia',
@ -59,7 +63,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
})->status_is(200)->content_like(qr/Updated Organisation/);
#Failed validation on approved organisation
$t->post_ok('/admin/organisations/valid/1/edit', form => {
$t->post_ok("/admin/organisations/$valid_id", form => {
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
sector => 'A',
@ -67,7 +71,7 @@ $t->post_ok('/admin/organisations/valid/1/edit', form => {
})->content_like(qr/The validation has failed/);
#Valid pending organisation update
$t->post_ok('/admin/organisations/pending/2/edit', form => {
$t->post_ok("/admin/organisations/$pending_id", form => {
name => '7th Heaven',
street_name => 'Slums, Sector 7',
town => 'Midgar',
@ -75,14 +79,14 @@ $t->post_ok('/admin/organisations/pending/2/edit', form => {
})->status_is(200)->content_like(qr/Updated Organisation/);
#Failed validation on pending organisation
$t->post_ok('/admin/organisations/pending/2/edit', form => {
$t->post_ok("/admin/organisations/$pending_id", form => {
name => '7th Heaven',
street_name => 'Slums, Sector 7',
postcode => 'WC1E 6AD',
})->content_like(qr/The validation has failed/);
#Valid adding organisation
$t->post_ok('/admin/organisations/add/submit', form => {
$t->post_ok('/admin/organisations/add', form => {
name => 'Wall Market',
street_name => 'Slums, Sector 6',
town => 'Midgar',
@ -91,7 +95,7 @@ $t->post_ok('/admin/organisations/add/submit', form => {
})->status_is(200)->content_like(qr/Added Organisation/);
#Failed validation on adding organisation
$t->post_ok('/admin/organisations/add/submit', form => {
$t->post_ok('/admin/organisations/add', form => {
name => 'Wall Market',
street_name => 'Slums, Sector 6',
postcode => 'TN35 5AQ',

View file

@ -1,49 +1,17 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
my $user = $schema->resultset('User')->create({
email => 'admin@example.com',
password => 'abc123',
administrator => {},
});
is $schema->resultset('Administrator')->count, 1, 'Admin Created';
my $user1 = {
token => 'a',
full_name => 'Test User1',
display_name => 'Test User1',
email => 'test1@example.com',
postcode => 'LA1 1AA',
password => 'abc123',
year_of_birth => 2006,
};
my $org = {
token => 'e',
email => 'test50@example.com',
name => '7th Heaven',
street_name => 'Slums, Sector 7',
town => 'Midgar',
sector => 'A',
postcode => 'WC1E 6AD',
password => 'abc123',
};
$schema->resultset('AccountToken')->create({ name => $_->{token} })
for ( $user1, $org );
$framework->register_customer($user1);
$framework->register_organisation($org);
#login to admin
$t->ua->max_redirects(10);
$t->post_ok('/admin', form => {
@ -51,27 +19,36 @@ $t->post_ok('/admin', form => {
password => 'abc123',
})->status_is(200);
$t->get_ok('/admin/users')
->status_is(200)
->or($framework->dump_error);
#Read customer user
$t->get_ok('/admin/users/2/')
$t->get_ok('/admin/users/1')
->status_is(200);
#Read organisation user
$t->get_ok('/admin/users/3/')
$t->get_ok('/admin/users/5')
->status_is(200);
#Valid customer user update
$t->post_ok('/admin/users/2/edit', form => {
email => 'test12@example.com',
new_password => 'abc123',
full_name => 'Test User1',
display_name => 'Test User1',
town => 'Midgar',
sector => 'A',
postcode => 'WC1E 6AD',
})->status_is(200)->content_like(qr/Updated User/);
$t->post_ok(
'/admin/users/1',
form => {
email => 'test12@example.com',
new_password => 'abc123',
full_name => 'Test User1',
display_name => 'Test User1',
town => 'Midgar',
sector => 'A',
postcode => 'WC1E 6AD',
})
->status_is(200)
->or($framework->dump_error)
->content_like(qr/Updated User/);
#Failed validation on customer user from no postcode
$t->post_ok('/admin/users/2/edit', form => {
$t->post_ok('/admin/users/2', form => {
email => 'test12@example.com',
new_password => 'abc123',
full_name => 'Test User1',
@ -81,7 +58,7 @@ $t->post_ok('/admin/users/2/edit', form => {
})->content_like(qr/The validation has failed/);
#Failed validation on customer user from no display name
$t->post_ok('/admin/users/2/edit', form => {
$t->post_ok('/admin/users/2', form => {
email => 'test12@example.com',
new_password => 'abc123',
full_name => 'Test User1',
@ -91,7 +68,7 @@ $t->post_ok('/admin/users/2/edit', form => {
})->content_like(qr/The validation has failed/);
#Valid organisation user update
$t->post_ok('/admin/users/3/edit', form => {
$t->post_ok('/admin/users/5', form => {
email => 'test51@example.com',
new_password => 'abc123',
name => '7th Heaven',
@ -102,7 +79,7 @@ $t->post_ok('/admin/users/3/edit', form => {
})->status_is(200)->content_like(qr/Updated User/);
#Failed validation on organisation user from no postcode
$t->post_ok('/admin/users/3/edit', form => {
$t->post_ok('/admin/users/5', form => {
email => 'test50@example.com',
new_password => 'abc123',
name => '7th Heaven',
@ -112,7 +89,7 @@ $t->post_ok('/admin/users/3/edit', form => {
})->content_like(qr/The validation has failed/);
#Failed validation on organisation user from no street name
$t->post_ok('/admin/users/3/edit', form => {
$t->post_ok('/admin/users/5', form => {
email => 'test50@example.com',
new_password => 'abc123',
name => '7th Heaven',

View file

@ -1,122 +1,46 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
my $framework = Test::Pear::LocalLoop->new;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('search');
my $t = $framework->framework;
my $schema = $t->app->schema;
my $dump_error = sub { diag $t->tx->res->to_string };
my @account_tokens = ('a', 'b');
$schema->resultset('AccountToken')->populate([
[ qw/ name / ],
map { [ $_ ] } @account_tokens,
]);
#Login as customer
my $session_key = $framework->login({
'email' => 'test1@example.com',
'password' => 'abc123',
});
$schema->resultset('Organisation')->populate([
[ qw/ name street_name town postcode / ],
[ "Avanti Bar & Restaurant", "57 Main St", "Kirkby Lonsdale", "LA6 2AH" ],
[ "Full House Noodle Bar", "21 Common Garden St", "Lancaster", "LA1 1XD" ],
[ "The Quay's Fishbar", "1 Adcliffe Rd", "Lancaster", "LA1 1SS" ],
[ "Dan's Fishop", "56 North Rd", "Lancaster", "LA1 1LT" ],
[ "Hodgeson's Chippy", "96 Prospect St", "Lancaster", "LA1 3BH" ],
]);
my $json;
my $upload;
#test with a customer.
print "test 1 - Create customer user account (Rufus)\n";
my $emailRufus = 'rufus@shinra.energy';
my $passwordRufus = 'MakoGold';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
'full_name' => 'RufusShinra',
'display_name' => 'RufusShinra',
'email' => $emailRufus,
'postcode' => 'RG26 5NU',
'password' => $passwordRufus,
'year_of_birth' => 2006
};
$t->post_ok('/api/register' => json => $testJson)
->status_is(200)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true);
#test with an organisation.
print "test 2 - Create organisation user account (Choco Billy)\n";
my $emailBilly = 'choco.billy@chocofarm.org';
my $passwordBilly = 'Choco';
$testJson = {
'usertype' => 'organisation',
'token' => shift(@account_tokens),
'name' => 'ChocoBillysGreens',
'email' => $emailBilly,
'postcode' => 'LA1 1HT',
'password' => $passwordBilly,
'street_name' => 'Market St',
'town' => 'Lancaster',
'sector' => 'A',
};
$t->post_ok('/api/register' => json => $testJson)
$t->post_ok( '/api/upload', form => {
json => Mojo::JSON::encode_json({
transaction_value => 10,
transaction_type => 3,
organisation_name => 'Shoreway Fisheries',
street_name => "2 James St",
town => "Lancaster",
postcode => "LA1 1UP",
purchase_time => "2017-08-14T11:29:07.965+01:00",
session_key => $session_key,
}),
file => { file => './t/test.jpg' },
})
->status_is(200)
->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true);
my $session_key;
sub login_rufus {
$testJson = {
'email' => $emailRufus,
'password' => $passwordRufus,
};
$t->post_ok('/api/login' => json => $testJson)
->status_is(200)
->json_is('/success', Mojo::JSON->true);
$session_key = $t->tx->res->json('/session_key');
};
sub login_billy {
$testJson = {
'email' => $emailBilly,
'password' => $passwordBilly,
};
$t->post_ok('/api/login' => json => $testJson)
->status_is(200)
->json_is('/success', Mojo::JSON->true);
$session_key = $t->tx->res->json('/session_key');
};
sub log_out{
$t->post_ok('/api/logout', json => { session_key => $session_key })
->status_is(200)
->json_is('/success', Mojo::JSON->true);
}
######################################################
#Login as Rufus (customer)
print "test 3 - Login - Rufus (cookies, customer)\n";
login_rufus();
print "test 4 - Added something containing 'fish'\n";
my $json = {
transaction_value => 10,
transaction_type => 3,
organisation_name => 'Shoreway Fisheries',
street_name => "2 James St",
town => "Lancaster",
postcode => "LA1 1UP",
purchase_time => "2017-08-14T11:29:07.965+01:00",
session_key => $session_key,
};
my $upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
$t->post_ok('/api/upload' => form => $upload )
->status_is(200)
->json_is('/success', Mojo::JSON->true);
print "test 5 - Logout Rufus \n";
log_out();
$framework->logout( $session_key );
#End of Rufus (customer)
@ -125,7 +49,10 @@ log_out();
#Login as Choco billy (organisation)
print "test 6 - Login - Choco billy (cookies, organisation)\n";
login_billy();
$session_key = $framework->login({
'email' => 'org@example.com',
'password' => 'abc123',
});
print "test 7 - Added something containing 'bar'\n";
$json = {
@ -160,16 +87,12 @@ $t->post_ok('/api/upload' => form => $upload )
->json_is('/success', Mojo::JSON->true);
print "test 9 - Logout Choco billy \n";
log_out();
$framework->logout( $session_key );
#End of Choco billy (organisation)
######################################################
#Login as Rufus (customer)
print "test 10 - Login - Rufus (cookies, customer)\n";
login_rufus();
$session_key = $framework->login({
'email' => 'test1@example.com',
'password' => 'abc123',
});
sub check_vars{
my ($searchTerm, $numValidated, $numUnvalidated) = @_;
@ -179,6 +102,7 @@ sub check_vars{
session_key => $session_key,
})
->status_is(200)
->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)
->json_has("unvalidated")
->json_has("validated");
@ -196,7 +120,7 @@ sub check_vars{
};
print "test 11 - search blank\n";
check_vars(" ", 5, 1);
check_vars(" ", 6, 1);
print "test 12 - Testing expected values with 'booths'\n";
#Expect 0 validated and 0 unvalidated with "booths".
@ -215,7 +139,7 @@ print "test 15 - Testing expected values with 'bar'\n";
check_vars("bar", 3, 0);
print "test 16 - Logout Rufus \n";
log_out();
$framework->logout( $session_key );
#End of Rufus (customer)
@ -224,7 +148,10 @@ log_out();
#Login as Choco billy (organisation)
print "test 17 - Login - Choco billy (cookies, organisation)\n";
login_billy();
$session_key = $framework->login({
'email' => 'org@example.com',
'password' => 'abc123',
});
print "test 18 - Testing expected values with 'booths'\n";
#Expect 0 validated and 0 unvalidated with "booths".
@ -243,7 +170,6 @@ print "test 21 - Testing expected values with 'bar', with two unvalidated organi
check_vars("bar", 3, 2);
print "test 22 - Logout Choco billy \n";
log_out();
$framework->logout( $session_key );
done_testing();

View file

@ -1,54 +1,33 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Mojo::JSON;
use Test::Pear::LocalLoop;
use DateTime;
my $framework = Test::Pear::LocalLoop->new;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/../etc",
);
$framework->install_fixtures('users');
my $t = $framework->framework;
my $schema = $t->app->schema;
my $dtf = $schema->storage->datetime_parser;
my $user = {
token => 'a',
full_name => 'Test User',
display_name => 'Test User',
email => 'test@example.com',
postcode => 'LA1 1AA',
password => 'abc123',
year_of_birth => 2006,
};
my $org = {
token => 'b',
email => 'test2@example.com',
name => 'Test Org',
street_name => 'Test Street',
town => 'Lancaster',
postcode => 'LA1 1AA',
password => 'abc123',
sector => 'A',
};
$schema->resultset('AccountToken')->create({ name => $user->{token} });
$schema->resultset('AccountToken')->create({ name => $org->{token} });
$framework->register_customer($user);
$framework->register_organisation($org);
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
my $user_result = $schema->resultset('User')->find({ email => $user->{email} });
my $org_result = $schema->resultset('Organisation')->find({ name => 'Test Org' })->entity;
my $user_result = $schema->resultset('User')->find({ email => 'test1@example.com' })->entity;
my $session_key = $framework->login({
email => $user->{email},
password => $user->{password},
email => 'test1@example.com',
password => 'abc123',
});
$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) );
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200)
->status_is(200)->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)
->json_is('/today_sum', 0)
->json_is('/today_count', 0)
@ -62,7 +41,7 @@ $t->post_ok('/api/stats' => json => { session_key => $session_key } )
->json_is('/global_count', 0);
for ( 1 .. 10 ) {
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
proof_image => 'a',
@ -70,7 +49,7 @@ for ( 1 .. 10 ) {
}
for ( 11 .. 20 ) {
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
proof_image => 'a',
@ -79,7 +58,7 @@ for ( 11 .. 20 ) {
}
for ( 21 .. 30 ) {
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
proof_image => 'a',
@ -88,7 +67,7 @@ for ( 21 .. 30 ) {
}
for ( 31 .. 40 ) {
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
proof_image => 'a',
@ -97,7 +76,7 @@ for ( 31 .. 40 ) {
}
for ( 41 .. 50 ) {
$org_result->user->create_related( 'transactions', {
$org_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => $_,
proof_image => 'a',
@ -105,7 +84,7 @@ for ( 41 .. 50 ) {
});
}
is $user_result->transactions->search({
is $user_result->purchases->search({
purchase_time => {
-between => [
$dtf->format_datetime(DateTime->today()),
@ -113,7 +92,7 @@ is $user_result->transactions->search({
],
},
})->get_column('value')->sum, 55, 'Got correct sum';
is $user_result->transactions->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
is $user_result->purchases->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200)

View file

@ -69,22 +69,22 @@ $framework->register_customer($_)
$framework->register_organisation($org);
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} })->entity;
my $tweak = 0;
my $now = DateTime->today();
{
my $user_result = $schema->resultset('User')->find({ email => $user1->{email} });
my $user_result = $schema->resultset('User')->find({ email => $user1->{email} })->entity;
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 1,
proof_image => 'a',
});
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 9,
proof_image => 'a',
@ -93,15 +93,15 @@ my $now = DateTime->today();
}
{
my $user_result = $schema->resultset('User')->find({ email => $user2->{email} });
my $user_result = $schema->resultset('User')->find({ email => $user2->{email} })->entity;
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 3,
proof_image => 'a',
});
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 1,
proof_image => 'a',
@ -110,15 +110,15 @@ my $now = DateTime->today();
}
{
my $user_result = $schema->resultset('User')->find({ email => $user3->{email} });
my $user_result = $schema->resultset('User')->find({ email => $user3->{email} })->entity;
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 5,
proof_image => 'a',
});
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 5,
proof_image => 'a',
@ -127,15 +127,15 @@ my $now = DateTime->today();
}
{
my $user_result = $schema->resultset('User')->find({ email => $user4->{email} });
my $user_result = $schema->resultset('User')->find({ email => $user4->{email} })->entity;
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 9,
proof_image => 'a',
});
$user_result->create_related( 'transactions', {
$user_result->create_related( 'purchases', {
seller_id => $org_result->id,
value => 3,
proof_image => 'a',

View file

@ -20,24 +20,25 @@ $schema->resultset('AccountToken')->populate([
my $test_purchase_time = "2017-08-14T11:29:07.965+01:00";
#Add one company that we've apparently authenticated but does not have an account.
my $org_id_shinra = 1;
my $org_rs = $schema->resultset('Organisation');
is $org_rs->count, 0, "No organisations";
$org_rs->create({
id => $org_id_shinra,
my $shinra_entity = $schema->resultset('Entity')->create_org({
name => 'Shinra Electric Power Company',
street_name => 'Sector 0, Midgar, Eastern Continent',
town => 'Gaia',
postcode => 'E1 M00',
submitted_by_id => 1,
});
is $org_rs->count, 1, "1 testing organisation";
my $org_id_shinra = $shinra_entity->organisation->id;
#Valid customer, this also tests that redirects are disabled for register.
print "test 1 - Create customer user account (Rufus)\n";
my $emailRufus = 'rufus@shinra.energy';
my $passwordRufus = 'MakoGold';
my $emailRufus = 'test1@example.com';
my $passwordRufus = 'abc123';
my $testJson = {
'usertype' => 'customer',
'token' => shift(@account_tokens),
@ -203,6 +204,7 @@ $json = {
$upload = {json => Mojo::JSON::encode_json($json)};
$t->post_ok('/api/upload' => form => $upload )
->status_is(200)
->or($framework->dump_error)
->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/);
is $schema->resultset('Transaction')->count, 1, "1 transaction";
@ -270,8 +272,8 @@ $t->post_ok('/api/upload' => form => $upload )
->content_like(qr/organisation_name is missing/i);
print "test 17 - add valid transaction (type 3: new organisation)\n";
is $schema->resultset('PendingOrganisation')->count, 0, "No pending organisations";
is $schema->resultset('PendingTransaction')->count, 0, "No pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 0, "No pending organisations";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 0, "No pending transactions";
$json = {
transaction_value => 10,
@ -288,8 +290,8 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(200)
->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/);
is $schema->resultset('PendingOrganisation')->count, 1, "1 pending organisations";
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->count, 1, "1 pending organisations";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
# Add type 2 (unverified organisation) checking.
@ -303,6 +305,7 @@ $json = {
$upload = {json => Mojo::JSON::encode_json($json), file => {file => './t/test.jpg'}};
$t->post_ok('/api/upload' => form => $upload )
->status_is(400)
->or($framework->dump_error)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/organisation_id is missing/i);
@ -335,10 +338,10 @@ $t->post_ok('/api/upload' => form => $upload )
->content_like(qr/organisation_id does not exist in the database/i);
print "test 21 - purchase_time is missing\n";
is $schema->resultset('PendingTransaction')->count, 1, "1 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
$json = {
transaction_value => 10,
transaction_type => 2,
transaction_type => 1,
organisation_id => $org_id_shinra,
session_key => $session_key,
};
@ -369,9 +372,9 @@ $t->post_ok('/api/login' => json => $testJson)
$session_key = $t->tx->res->json('/session_key');
print "test 24 - add valid transaction but for with account (type 2: existing organisation)\n";
my $org_result = $schema->resultset('PendingOrganisation')->find({ name => '7th Heaven' });
my $org_result = $schema->resultset('Organisation')->find({ name => '7th Heaven' });
my $unvalidatedOrganisationId = $org_result->id;
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
$json = {
transaction_value => 10,
transaction_type => 2,
@ -384,7 +387,7 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(400)
->json_is('/success', Mojo::JSON->false)
->content_like(qr/organisation_id does not exist in the database/i);
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
print "test 25 - Logout Hojo\n";
$t->post_ok('/api/logout', json => { session_key => $session_key } )
@ -408,7 +411,7 @@ $t->post_ok('/api/login' => json => $testJson)
$session_key = $t->tx->res->json('/session_key');
print "test 27 - add valid transaction (type 2: existing organisation)\n";
is $schema->resultset('PendingTransaction')->count, 2, "2 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 1, "1 pending transactions";
$json = {
transaction_value => 10,
transaction_type => 2,
@ -421,7 +424,7 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(200)
->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/);
is $schema->resultset('PendingTransaction')->count, 3, "3 pending transactions";
is $schema->resultset('Organisation')->search({ pending => 1 })->entity->sales->count, 2, "2 pending transactions";
print "test 28 - Logout Rufus\n";
@ -446,7 +449,7 @@ $t->post_ok('/api/login' => json => $testJson)
$session_key = $t->tx->res->json('/session_key');
print "test 30 - organisation buy from another organisation\n";
is $schema->resultset('Transaction')->count, 2, "2 transaction";
is $schema->resultset('Transaction')->count, 5, "5 transaction";
$json = {
transaction_value => 100000,
transaction_type => 1,
@ -459,6 +462,6 @@ $t->post_ok('/api/upload' => form => $upload )
->status_is(200)
->json_is('/success', Mojo::JSON->true)
->json_like('/message', qr/Upload Successful/);
is $schema->resultset('Transaction')->count, 3, "3 transaction";
is $schema->resultset('Transaction')->count, 6, "6 transaction";
done_testing();

View file

@ -77,9 +77,11 @@ sub create_random_transaction {
my $buyer = shift;
my $time = shift;
my $buyer_result = $schema->resultset('User')->find({ email => $buyer })->entity;
my $seller_result = $schema->resultset('Organisation')->find({ name => 'Test Org' })->entity;
$schema->resultset('Transaction')->create({
buyer => { email => $buyer },
seller => { name => 'Test Org' },
buyer => $buyer_result,
seller => $seller_result,
value => ( int( rand( 10000 ) ) / 100 ),
proof_image => 'a',
purchase_time => $time,

View file

@ -1,15 +1,16 @@
use Mojo::Base -strict;
use FindBin qw/ $Bin /;
use Test::More;
use Test::Mojo;
use Test::Pear::LocalLoop;
use FindBin;
my $framework = Test::Pear::LocalLoop->new(
etc_dir => "$Bin/etc",
);
$framework->install_fixtures('users');
BEGIN {
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_LOG_LEVEL} = 'debug';
}
my $t = Test::Mojo->new("Pear::LocalLoop");
my $t = $framework->framework;
$t->get_ok('/')->status_is(200);
done_testing();

View file

@ -0,0 +1,88 @@
#! /usr/bin/env perl
use strict;
use warnings;
use DBIx::Class::Fixtures;
use FindBin qw/ $Bin /;
use lib "$Bin/../../../../lib";
use Pear::LocalLoop::Schema;
use DateTime;
my $fixtures = DBIx::Class::Fixtures->new({
config_dir => "$Bin",
});
my $schema = Pear::LocalLoop::Schema->connect('dbi:SQLite::memory:');
$schema->deploy;
$fixtures->populate({
directory => "$Bin/../data/users",
no_deploy => 1,
schema => $schema,
});
my @orgs = (
{
organisation => {
name => 'Avanti Bar & Restaurant',
street_name => '57 Main St',
town => 'Kirkby Lonsdale',
postcode => 'LA6 2AH',
sector => 'I',
},
type => "organisation",
},
{
organisation => {
name => 'Full House Noodle Bar',
street_name => '21 Common Garden St',
town => 'Lancaster',
postcode => 'LA1 1XD',
sector => 'I',
},
type => "organisation",
},
{
organisation => {
name => 'The Quay\'s Fishbar',
street_name => '1 Adcliffe Rd',
town => 'Lancaster',
postcode => 'LA1 1SS',
sector => 'I',
},
type => "organisation",
},
{
organisation => {
name => 'Dan\'s Fishop',
street_name => '56 North Rd',
town => 'Lancaster',
postcode => 'LA1 1LT',
sector => 'I',
},
type => "organisation",
},
{
organisation => {
name => 'Hodgeson\'s Chippy',
street_name => '96 Prospect St',
town => 'Lancaster',
postcode => 'LA1 3BH',
sector => 'I',
},
type => "organisation",
},
);
$schema->resultset('Entity')->create( $_ ) for @orgs;
my $data_set = 'search';
$fixtures->dump({
all => 1,
schema => $schema,
directory => "$Bin/../data/" . $data_set,
});

View file

@ -29,63 +29,93 @@ $schema->resultset('Leaderboard')->populate([
[ 'All Time Count', 'all_time_count' ],
]);
my $user1 = {
my $entity1 = {
customer => {
full_name => 'Test User1',
display_name => 'Test User1',
postcode => 'LA1 1AA',
year_of_birth => 2006,
},
email => 'test1@example.com',
password => 'abc123',
user => {
email => 'test1@example.com',
password => 'abc123',
},
type => "customer",
};
my $user2 = {
my $entity2 = {
customer => {
full_name => 'Test User2',
display_name => 'Test User2',
postcode => 'LA1 1AA',
full_name => 'Test User2',
display_name => 'Test User2',
postcode => 'LA1 1AA',
year_of_birth => 2006,
},
email => 'test2@example.com',
password => 'abc123',
user => {
email => 'test2@example.com',
password => 'abc123',
},
type => "customer",
};
my $user3 = {
my $entity3 = {
customer => {
full_name => 'Test User3',
display_name => 'Test User3',
postcode => 'LA1 1AA',
full_name => 'Test User3',
display_name => 'Test User3',
postcode => 'LA1 1AA',
year_of_birth => 2006,
},
email => 'test3@example.com',
password => 'abc123',
user => {
email => 'test3@example.com',
password => 'abc123',
},
type => "customer",
};
my $user4 = {
my $entity4 = {
customer => {
full_name => 'Test User4',
display_name => 'Test User4',
postcode => 'LA1 1AA',
full_name => 'Test User4',
display_name => 'Test User4',
postcode => 'LA1 1AA',
year_of_birth => 2006,
},
email => 'test4@example.com',
password => 'abc123',
user => {
email => 'test4@example.com',
password => 'abc123',
},
type => "customer",
};
my $org = {
my $entity5 = {
organisation => {
name => 'Test Org',
street_name => 'Test Street',
town => 'Lancaster',
postcode => 'LA1 1AA',
},
email => 'org@example.com',
password => 'abc123',
user => {
email => 'org@example.com',
password => 'abc123',
},
type => "organisation",
};
$schema->resultset('User')->create( $_ )
for ( $user1, $user2, $user3, $user4, $org );
my $entity6 = {
customer => {
full_name => 'Test Admin',
display_name => 'Test Admin',
postcode => 'LA1 1AA',
year_of_birth => 2006,
},
user => {
email => 'admin@example.com',
password => 'abc123',
is_admin => \"1",
},
type => "customer",
};
$schema->resultset('Entity')->create( $_ )
for ( $entity1, $entity2, $entity3, $entity4, $entity5, $entity6 );
my $data_set = 'users';

View file

@ -0,0 +1,57 @@
$VAR1 = {
'has_many' => {
'fetch' => 0
},
'sets' => [
{
'class' => 'Feedback',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'Transaction'
},
{
'quantity' => 'all',
'class' => 'User'
},
{
'quantity' => 'all',
'class' => 'LeaderboardSet'
},
{
'class' => 'Customer',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'Organisation'
},
{
'quantity' => 'all',
'class' => 'LeaderboardValue'
},
{
'class' => 'Entity',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'Leaderboard'
},
{
'class' => 'SessionToken',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'AccountToken'
}
],
'might_have' => {
'fetch' => 0
},
'belongs_to' => {
'fetch' => 0
}
};

View file

@ -0,0 +1 @@
1.001036

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test User1',
entity_id => 1,
full_name => 'Test User1',
id => 1,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test User2',
entity_id => 2,
full_name => 'Test User2',
id => 2,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test User3',
entity_id => 3,
full_name => 'Test User3',
id => 3,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test User4',
entity_id => 4,
full_name => 'Test User4',
id => 4,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test Admin',
entity_id => 6,
full_name => 'Test Admin',
id => 5,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 1,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 10,
type => 'organisation'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 11,
type => 'organisation'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 2,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 3,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 4,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 5,
type => 'organisation'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 6,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 7,
type => 'organisation'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 8,
type => 'organisation'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 9,
type => 'organisation'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 1,
name => 'Daily Total',
type => 'daily_total'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 2,
name => 'Daily Count',
type => 'daily_count'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 3,
name => 'Weekly Total',
type => 'weekly_total'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 4,
name => 'Weekly Count',
type => 'weekly_count'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 5,
name => 'Monthly Total',
type => 'monthly_total'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 6,
name => 'Monthly Count',
type => 'monthly_count'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 7,
name => 'All Time Total',
type => 'all_time_total'
};

View file

@ -0,0 +1,5 @@
$HASH1 = {
id => 8,
name => 'All Time Count',
type => 'all_time_count'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 5,
id => 1,
name => 'Test Org',
pending => 0,
postcode
=> 'LA1 1AA',
sector => undef,
street_name
=> 'Test Street',
submitted_by_id
=> undef,
town => 'Lancaster'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 7,
id => 2,
name => 'Avanti Bar & Restaurant',
pending => 0,
postcode
=> 'LA6 2AH',
sector => 'I',
street_name
=> '57 Main St',
submitted_by_id
=> undef,
town => 'Kirkby Lonsdale'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 8,
id => 3,
name => 'Full House Noodle Bar',
pending => 0,
postcode
=> 'LA1 1XD',
sector => 'I',
street_name
=> '21 Common Garden St',
submitted_by_id
=> undef,
town => 'Lancaster'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 9,
id => 4,
name => 'The Quay\'s Fishbar',
pending => 0,
postcode
=> 'LA1 1SS',
sector => 'I',
street_name
=> '1 Adcliffe Rd',
submitted_by_id
=> undef,
town => 'Lancaster'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 10,
id => 5,
name => 'Dan\'s Fishop',
pending => 0,
postcode
=> 'LA1 1LT',
sector => 'I',
street_name
=> '56 North Rd',
submitted_by_id
=> undef,
town => 'Lancaster'
};

View file

@ -0,0 +1,16 @@
$HASH1 = {
country => undef,
entity_id
=> 11,
id => 6,
name => 'Hodgeson\'s Chippy',
pending => 0,
postcode
=> 'LA1 3BH',
sector => 'I',
street_name
=> '96 Prospect St',
submitted_by_id
=> undef,
town => 'Lancaster'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'test1@example.com',
entity_id => 1,
id => 1,
is_admin => 0,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$HSuznDeSU1fuONwKhp2/S.TX/X4p4g0dHtz20kVXxprm8hIg5QQma'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'test2@example.com',
entity_id => 2,
id => 2,
is_admin => 0,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$5XYLWPJvVGuWUvfSWj9cIOg4/tyB4fZ3knzwgw5UnBSKFBFIKOiFC'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'test3@example.com',
entity_id => 3,
id => 3,
is_admin => 0,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$p5VU4leHetEvuz2P3uMfYuuPTkDGg8wsM7QuSVKkXR.s3B9T2JaVW'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'test4@example.com',
entity_id => 4,
id => 4,
is_admin => 0,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$fkkTUYA9zvt32iBbN7aOcOnmiHzOkbMEjN31PB9CsitGrE.KF7cAG'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'org@example.com',
entity_id => 5,
id => 5,
is_admin => 0,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$MWC45.w1AnLPNNHiS96ICOHfNlTrIqB0.7OPzy5qB.z0pZB0theo.'
};

View file

@ -0,0 +1,8 @@
$HASH1 = {
email => 'admin@example.com',
entity_id => 6,
id => 6,
is_admin => 1,
join_date => '2017-08-31 12:17:25',
password => '$2a$08$1sPcPB9GnoNgzhBAk2bHSOqEmv6.Y6YLrAa2DJ6TR2WefzTYZQ92G'
};

View file

@ -5,20 +5,21 @@ $VAR1 = {
'belongs_to' => {
'fetch' => 0
},
'might_have' => {
'fetch' => 0
},
'sets' => [
{
'class' => 'Leaderboard',
'class' => 'Feedback',
'quantity' => 'all'
},
{
'class' => 'AccountToken',
'quantity' => 'all',
'class' => 'LeaderboardSet'
},
{
'class' => 'Transaction',
'quantity' => 'all'
},
{
'class' => 'LeaderboardValue',
'class' => 'Entity',
'quantity' => 'all'
},
{
@ -26,40 +27,31 @@ $VAR1 = {
'class' => 'SessionToken'
},
{
'class' => 'Administrator',
'class' => 'AccountToken',
'quantity' => 'all'
},
{
'class' => 'LeaderboardSet',
'class' => 'Organisation',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'Feedback'
'class' => 'User'
},
{
'class' => 'PendingOrganisation',
'class' => 'Customer',
'quantity' => 'all'
},
{
'class' => 'User',
'quantity' => 'all'
},
{
'class' => 'Transaction',
'class' => 'Leaderboard',
'quantity' => 'all'
},
{
'quantity' => 'all',
'class' => 'Organisation'
},
{
'quantity' => 'all',
'class' => 'Customer'
},
{
'quantity' => 'all',
'class' => 'PendingTransaction'
'class' => 'LeaderboardValue'
}
]
],
'might_have' => {
'fetch' => 0
}
};

View file

@ -1,5 +1,6 @@
$HASH1 = {
display_name => 'Test User1',
entity_id => 1,
full_name => 'Test User1',
id => 1,
postcode => 'LA1 1AA',

View file

@ -1,5 +1,6 @@
$HASH1 = {
display_name => 'Test User2',
entity_id => 2,
full_name => 'Test User2',
id => 2,
postcode => 'LA1 1AA',

View file

@ -1,5 +1,6 @@
$HASH1 = {
display_name => 'Test User3',
entity_id => 3,
full_name => 'Test User3',
id => 3,
postcode => 'LA1 1AA',

View file

@ -1,5 +1,6 @@
$HASH1 = {
display_name => 'Test User4',
entity_id => 4,
full_name => 'Test User4',
id => 4,
postcode => 'LA1 1AA',

View file

@ -0,0 +1,8 @@
$HASH1 = {
display_name => 'Test Admin',
entity_id => 6,
full_name => 'Test Admin',
id => 5,
postcode => 'LA1 1AA',
year_of_birth => 2006
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 1,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 2,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 3,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 4,
type => 'customer'
};

View file

@ -0,0 +1,4 @@
$HASH1 = {
id => 5,
type => 'organisation'
};

Some files were not shown because too many files have changed in this diff Show more