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().
This commit is contained in:
Lucas 2023-03-05 17:23:13 +00:00
parent 04580aca72
commit c9ffa62be8
1 changed files with 10 additions and 5 deletions

View File

@ -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"},