api: rewrite /tag/:tag_id_or_name
Commit 3a41ea6d0b
allows for using a
SELECT WHERE ... OR ... instead of two SELECT WHERE.
Page the media results.
This commit is contained in:
parent
a0d3601c57
commit
978f979d4d
@ -85,21 +85,27 @@ post "/tags" => sub {
|
||||
};
|
||||
|
||||
get "/tag/:tag_id_or_name" => sub {
|
||||
my ($tag, $tag_rset, @media);
|
||||
my $page = query_parameters->get("page") // 1;
|
||||
send_error("Invalid page number", 400) if $page !~ $NUMERIC_ID_RE;
|
||||
|
||||
my $tag_id_or_name = route_parameters->get("tag_id_or_name");
|
||||
|
||||
$tag_rset = schema("default")->resultset("Tag");
|
||||
$tag = $tag_rset->single({ tag_id => $tag_id_or_name }) //
|
||||
$tag_rset->single({ name => $tag_id_or_name });
|
||||
|
||||
my $query = [
|
||||
{ tag_id => $tag_id_or_name },
|
||||
{ name => $tag_id_or_name },
|
||||
];
|
||||
my $tag = schema("default")->resultset("Tag")->single($query);
|
||||
send_error("Tag not found", 404) if !defined($tag);
|
||||
|
||||
@media = map { $_->media_id } schema("default")->resultset("MediaTag")
|
||||
->search({ tag_id => $tag->tag_id })->all;
|
||||
my $paged_media = schema("default")->resultset("MediaTag")
|
||||
->search({ tag_id => $tag->tag_id }, $MEDIA_SEARCH_OPTS)
|
||||
->page($page);
|
||||
my @media = map { $_->media_id } $paged_media->all;
|
||||
|
||||
return {
|
||||
id => $tag->tag_id,
|
||||
name => $tag->name,
|
||||
pager => mkpager($paged_media),
|
||||
media => \@media,
|
||||
};
|
||||
};
|
||||
@ -110,7 +116,6 @@ get "/media" => sub {
|
||||
|
||||
my $paged_media = schema("default")->resultset("Media")
|
||||
->search({}, $MEDIA_SEARCH_OPTS)->page($page);
|
||||
|
||||
my @media = map { $_->media_id } $paged_media->all;
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user