api/v0: simplify Tags model get

Since previous commit, get only effectively serves search for ids or
displays. Remove the machinery to deal with other stuff and simplify
error checking.
This commit is contained in:
Lucas Gabriel Vuotto 2025-05-03 16:42:30 +00:00
parent f1c3d1ed0e
commit fa6f642ca2

View file

@ -1,6 +1,8 @@
package Pooru::API::V0::Model::Tags;
use v5.40;
use Carp;
use Pooru::API::V0::Model::PagedResults;
@ -29,26 +31,18 @@ sub random_id ($self)
sub get ($self, %search)
{
my $key = exists($search{id}) ?
"id" : exists($search{display}) ?
"display" : "name";
my $where_clause = where_in($key, $search{$key}->@*);
my @bind_values = $search{$key}->@*;
croak "Exactly one of 'id' or 'display' must be defined" if
!(defined($search{id}) ^^ defined($search{display}));
if (exists($search{kind_id})) {
$where_clause .= " AND kind_id = ?";
push(@bind_values, $search{kind_id});
}
my $key = defined($search{id}) ? "id" : "display";
my $where_clause = where_in($key, $search{$key}->@*);
my $sth = $self->{_dbh}->prepare(qq{
SELECT *
FROM tag
WHERE $where_clause
LIMIT ?
SELECT * FROM tag WHERE $where_clause LIMIT ?
});
return Pooru::API::V0::Model::Results->new($sth, $slice,
(@bind_values, $self->ROWS));
($search{$key}->@*, $self->ROWS));
}
sub _ranked ($self, $stmt, @bind_values)