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.
這個提交存在於:
父節點
f1c3d1ed0e
當前提交
fa6f642ca2
共有 1 個檔案被更改,包括 8 行新增 和 14 行删除
|
@ -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)
|
||||||
|
|
載入中…
新增表格
新增連結
新增問題並參考