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.
這個提交存在於:
Lucas Gabriel Vuotto 2025-05-03 16:42:30 +00:00
父節點 f1c3d1ed0e
當前提交 fa6f642ca2

檢視檔案

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