+sub contest_list {
+ my ($self, %args) = @_;
+ my $rs = $self->contests->search(undef, {order_by => {-desc => 'start'}, prefetch => 'owner'});
+ $rs = $rs->search({owner => $args{owner}}) if $args{owner};
+ my %params;
+ for ($rs->all) {
+ my $state = $_->is_pending ? 'pending' : $_->is_running ? 'running' : 'finished';
+ $params{$state} //= [];
+ push $params{$state}, { $_->get_columns, started => !$_->is_pending, owner_name => $_->owner->name };
+ }
+ \%params
+}
+
+sub contest_entry {
+ my ($self, $id) = @_;
+ my $ct = $self->contest($id);
+ +{ $ct->get_columns, started => !$ct->is_pending, owner_name => $ct->owner->name }
+}
+
+sub job_list {
+ my ($self, %args) = @_;
+ $args{page} //= 1;
+ my $rs = $self->jobs->search(undef, {order_by => {-desc => 'me.id'}, prefetch => ['problem', 'owner'], rows => JOBS_PER_PAGE, offset => ($args{page} - 1) * JOBS_PER_PAGE});
+ $rs = $rs->search({'me.owner' => $args{owner}}) if $args{owner};
+ $rs = $rs->search({contest => $args{contest}}) if $args{contest};
+ $rs = $rs->search({problem => $args{problem}}) if $args{problem};
+ [map {
+ my %params = $_->get_columns;
+ $params{owner_name} = $_->owner->name;
+ $params{problem_name} = $_->problem->name;
+ $params{results} &&= decode_json $params{results};
+ $params{size} = length $params{source};
+ delete $params{source};
+ \%params
+ } $rs->all]
+}
+
+sub job_entry {
+ my ($self, $id) = @_;
+ my $job = $self->jobs->find($id, {prefetch => ['problem', 'owner']});
+ my %params = $job->get_columns;
+ $params{owner_name} = $job->owner->name;
+ $params{problem_name} = $job->problem->name;
+ $params{results} &&= decode_json $params{results};
+ $params{size} = length $params{source};
+ delete $params{source};
+ \%params
+}