Allow filtering pins and setting limit

This commit is contained in:
Citlali del Rey 2022-11-04 21:06:23 -07:00
parent c885111b08
commit 0ac565903a
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
1 changed files with 36 additions and 2 deletions

View File

@ -12,9 +12,43 @@ sub list($c) {
my $uid = $c->stash('uid');
$c->pins->list({
my %query = (
uid => $uid,
}, 10)->then(sub ($res) {
);
my $cid = $c->param('cid');
my $name = $c->param('name');
# TODO: Text matching strategy
my $match = $c->param('match');
# TODO: filter by status (only pinned)
my $status = $c->param('status');
my $before = $c->param('before');
my $after = $c->param('after');
my $limit = $c->param('limit') || 10;
# Not supporting meta.
if (defined $cid) {
$query{cid} = $cid;
}
if (defined $name) {
$query{name} = $name;
}
if (defined $before) {
$query{created_at} = { '<' => $before };
}
if (defined $after) {
if (defined $query{created_at}) {
$query{created_at}->{'>'} = $after;
} else {
$query{created_at} = { '>' => $after };
}
}
$c->pins->list(\%query, $limit)->then(sub ($res) {
my @formatted;