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

View File

@ -32,7 +32,7 @@ sub list ($self)
) if $v->has_error; ) if $v->has_error;
my $paged_tags = $self->schema->resultset("TagCountView") 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 +{ my @tags = map +{
id => $_->tag_id, id => $_->tag_id,
name => $_->name, name => $_->name,
@ -56,10 +56,15 @@ sub show ($self)
) if $v->has_error; ) if $v->has_error;
my $tag_id_or_name = $self->stash("tag_id_or_name"); my $tag_id_or_name = $self->stash("tag_id_or_name");
my $tag = $self->schema->resultset("Tag")->single([
{ tag_id => $tag_id_or_name }, my @search;
{ name => $tag_id_or_name }, 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( return $self->render(
json => {error => "Tag not found"}, json => {error => "Tag not found"},