Skip to content

Commit eb6ecf1

Browse files
committed
Search API extension
1 parent 064e541 commit eb6ecf1

9 files changed

Lines changed: 1154 additions & 144 deletions

File tree

lib/LANraragi/Controller/Api/Search.pm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,36 @@ sub handle_api {
107107
}
108108
}
109109

110+
# Composite search API with multi-clause OR support.
111+
sub handle_composite {
112+
113+
my $self = shift->openapi->valid_input or return;
114+
my $body = $self->req->json;
115+
116+
my $clauses_raw = $body->{clauses};
117+
my $start = $body->{start} // 0;
118+
my $sortkey = $body->{sortby};
119+
my $sortorder = ( $body->{order} && $body->{order} eq 'desc' ) ? 1 : 0;
120+
my $grouptanks = $body->{groupby_tanks} // 1;
121+
122+
my ( $total, $filtered, @ids ) = LANraragi::Model::Search::do_composite_search(
123+
$clauses_raw, $start, $sortkey, $sortorder, $grouptanks ? 1 : 0
124+
);
125+
126+
if ( $total eq -1 && $filtered eq -1 ) {
127+
$self->render(
128+
openapi => {
129+
recordsTotal => 0,
130+
recordsFiltered => 0,
131+
data => []
132+
},
133+
status => 204
134+
);
135+
} else {
136+
$self->render( openapi => get_api_object( $total, $filtered, @ids ) );
137+
}
138+
}
139+
110140
sub clear_cache {
111141
invalidate_cache();
112142
render_api_response( shift, "clear_cache" );

0 commit comments

Comments
 (0)