fixed category list on postgres
This commit is contained in:
parent
fb60ba4c0f
commit
6527d1e36c
5 changed files with 26 additions and 26 deletions
|
@ -10,6 +10,7 @@
|
|||
* Added API ability to edit and delete transactions
|
||||
* Added test for above
|
||||
* Made test dumping more sane
|
||||
* Fixed category view on postgres
|
||||
|
||||
# v0.10.5
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ sub post_category_list {
|
|||
value => { sum => 'value' },
|
||||
category_id => 'category_id',
|
||||
essential => 'essential',
|
||||
}
|
||||
},
|
||||
],
|
||||
group_by => [ qw/ category_id quantised_weeks / ],
|
||||
group_by => [ qw/ category_id quantised_weeks essential value / ],
|
||||
order_by => { '-desc' => 'value' },
|
||||
}
|
||||
);
|
||||
|
|
|
@ -10,18 +10,18 @@ __PACKAGE__->table('view_quantised_transactions');
|
|||
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||
|
||||
__PACKAGE__->result_source_instance->view_definition( qq/
|
||||
SELECT "transactions.value",
|
||||
"transactions.distance",
|
||||
"transactions.purchase_time",
|
||||
"transactions.buyer_id",
|
||||
"transactions.seller_id",
|
||||
"transactions.essential",
|
||||
"transaction_category.category_id",
|
||||
DATE_TRUNC('hour', "transactions.purchase_time") AS "quantised_hours",
|
||||
DATE_TRUNC('day', "transactions.purchase_time") AS "quantised_days",
|
||||
DATE_TRUNC('week', "transactions.purchase_time") AS "quantised_weeks"
|
||||
SELECT "transactions"."value",
|
||||
"transactions"."distance",
|
||||
"transactions"."purchase_time",
|
||||
"transactions"."buyer_id",
|
||||
"transactions"."seller_id",
|
||||
"transactions"."essential",
|
||||
"transaction_category"."category_id",
|
||||
DATE_TRUNC('hour', "transactions"."purchase_time") AS "quantised_hours",
|
||||
DATE_TRUNC('day', "transactions"."purchase_time") AS "quantised_days",
|
||||
DATE_TRUNC('week', "transactions"."purchase_time") AS "quantised_weeks"
|
||||
FROM "transactions"
|
||||
LEFT JOIN "transaction_category" ON "transactions.id" = "transaction_category.transaction_id"
|
||||
LEFT JOIN "transaction_category" ON "transactions"."id" = "transaction_category"."transaction_id"
|
||||
/);
|
||||
|
||||
1;
|
||||
|
|
|
@ -19,7 +19,7 @@ SELECT "transactions"."value",
|
|||
"transaction_category"."category_id",
|
||||
DATETIME(STRFTIME('%Y-%m-%d %H:00:00',"transactions"."purchase_time")) AS "quantised_hours",
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time")) AS "quantised_days",
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time", 'weekday 1')) AS "quantised_weeks"
|
||||
DATETIME(STRFTIME('%Y-%m-%d 00:00:00',"transactions"."purchase_time", 'weekday 0','-6 days')) AS "quantised_weeks"
|
||||
FROM "transactions"
|
||||
LEFT JOIN "transaction_category" ON "transactions"."id" = "transaction_category"."transaction_id"
|
||||
/);
|
||||
|
|
|
@ -19,6 +19,11 @@ $framework->install_fixtures('users');
|
|||
my $t = $framework->framework;
|
||||
my $schema = $t->app->schema;
|
||||
|
||||
$schema->resultset('Category')->create({
|
||||
id => 1,
|
||||
name => 'test',
|
||||
});
|
||||
|
||||
set_absolute_time('2017-01-02T00:00:00Z');
|
||||
|
||||
my $start = DateTime->today->subtract( hours => 12 );
|
||||
|
@ -52,7 +57,7 @@ $t->post_ok('/api/stats/category' => json => {
|
|||
categories => {
|
||||
"2016-12-05" => [{
|
||||
days => "2016-12-05",
|
||||
value => 30,
|
||||
value => 210,
|
||||
category => 1,
|
||||
}],
|
||||
"2016-12-12" => [{
|
||||
|
@ -62,7 +67,7 @@ $t->post_ok('/api/stats/category' => json => {
|
|||
}],
|
||||
"2016-12-19" => [{
|
||||
days => "2016-12-19",
|
||||
value => 220,
|
||||
value => 210,
|
||||
category => 1,
|
||||
}],
|
||||
"2016-12-26" => [{
|
||||
|
@ -70,28 +75,20 @@ $t->post_ok('/api/stats/category' => json => {
|
|||
value => 190,
|
||||
category => 1,
|
||||
}],
|
||||
"2017-01-02" => [{
|
||||
days => "2017-01-02",
|
||||
value => 170,
|
||||
category => 1,
|
||||
}],
|
||||
},
|
||||
essentials => {
|
||||
"2016-12-05" => {
|
||||
value => 30,
|
||||
value => 210,
|
||||
},
|
||||
"2016-12-12" => {
|
||||
value => 200,
|
||||
},
|
||||
"2016-12-19" => {
|
||||
value => 220,
|
||||
value => 210,
|
||||
},
|
||||
"2016-12-26" => {
|
||||
value => 190,
|
||||
},
|
||||
"2017-01-02" => {
|
||||
value => 170,
|
||||
},
|
||||
}
|
||||
})->or($framework->dump_error);
|
||||
|
||||
|
@ -99,6 +96,7 @@ 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;
|
||||
my $test_transaction = $schema->resultset('Transaction')->create({
|
||||
|
@ -109,6 +107,7 @@ sub create_random_transaction {
|
|||
purchase_time => $time,
|
||||
essential => 1,
|
||||
});
|
||||
|
||||
$schema->resultset('TransactionCategory')->create({
|
||||
category_id => 1,
|
||||
transaction_id => $test_transaction->id,
|
||||
|
|
Reference in a new issue