From c9ffa62be833820d71f9a1c5edf1c2359334ba75 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 5 Mar 2023 17:23:13 +0000 Subject: [PATCH] api: quiet a warning about tag_id not being numeric Only add one of tag_id or name to the search query, depending on whether tag_id_or_name is numeric or not. While at it, replace a {} with undef in search(). --- lib/PoorBooru/API/V0/Controller/Tags.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/PoorBooru/API/V0/Controller/Tags.pm b/lib/PoorBooru/API/V0/Controller/Tags.pm index 4698c28..906720f 100644 --- a/lib/PoorBooru/API/V0/Controller/Tags.pm +++ b/lib/PoorBooru/API/V0/Controller/Tags.pm @@ -32,7 +32,7 @@ sub list ($self) ) if $v->has_error; my $paged_tags = $self->schema->resultset("TagCountView") - ->search({}, $TAGS_COUNT_VIEW_SEARCH_OPTS)->page($page); + ->search(undef, $TAGS_COUNT_VIEW_SEARCH_OPTS)->page($page); my @tags = map +{ id => $_->tag_id, name => $_->name, @@ -56,10 +56,15 @@ sub show ($self) ) if $v->has_error; my $tag_id_or_name = $self->stash("tag_id_or_name"); - my $tag = $self->schema->resultset("Tag")->single([ - { tag_id => $tag_id_or_name }, - { name => $tag_id_or_name }, - ]); + + my @search; + if ($tag_id_or_name =~ /^[1-9][0-9]*$/) { + push @search, { tag_id => $tag_id_or_name }; + } else { + push @search, { name => $tag_id_or_name }; + } + + my $tag = $self->schema->resultset("Tag")->single(\@search); return $self->render( json => {error => "Tag not found"},