Added resultset for leaderboard for more consice code

This commit is contained in:
Tom Bloor 2017-06-05 22:34:48 +01:00
parent 7e11fc50bd
commit 5e06f0a69b
3 changed files with 323 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package Pear::LocalLoop::Schema::ResultSet::Leaderboard;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub get_latest {
my $self = shift;
my $type = shift;
my $type_result = $self->find_by_type( $type );
return undef unless defined $type_result;
my $latest = $type_result->search_related('sets', {}, {
order_by => { -desc => 'date' },
})->first;
return $latest;
}
sub create_new {
my $self = shift;
my $type = shift;
my $date = shift;
my $type_result = $self->find_by_type($type);
return undef unless $type_result;
return $type_result->create_new($date);
}
sub find_by_type {
my $self = shift;
my $type = shift;
return $self->find({ type => $type });
}
1;