aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311/endpoint/Endpoint2.pm
blob: 664a7f3d6cd8bf0ba1963d95a7839a34aa449a9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package t::open311::endpoint::Endpoint2;
use Web::Simple;
extends 't::open311::endpoint::Endpoint1';
with 'Open311::Endpoint::Role::mySociety';

sub get_service_request_updates {
    my ($self, $args) = @_;

    my $start_date = $self->maybe_inflate_datetime($args->{start_date});
    my $end_date   = $self->maybe_inflate_datetime($args->{end_date});

    my @requests = $self->filter_requests( sub { $_[0]->has_updates } );

    return map {
        $_->filter_updates( sub {
            my $update = shift;
            my $updated_datetime = $update->updated_datetime or return;
            if ($start_date) { return unless $updated_datetime >= $start_date }
            if ($end_date)   { return unless $updated_datetime <= $end_date }
            return 1;
        });
    } @requests;
}

1;