Skip to content

Commit

Permalink
feat(api): add order by for computer search and exclude groups from r…
Browse files Browse the repository at this point in the history
…esult
  • Loading branch information
charleneauger committed Mar 18, 2024
1 parent f215b40 commit 689c8d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions Api/Ocsinventory/Restapi/ApiCommon.pm
Expand Up @@ -269,10 +269,14 @@ sub get_item_main_table_informations{

sub execute_custom_request{

my ($query, $start, $limit, @args) = @_;
my ($query, $start, $limit, $orderby, @args) = @_;

my $database = api_database_connect();

if($orderby ne "") {
$query .= $orderby;
}

if($start ne "" && $limit ne ""){
$start =~ s/\D//g;
$limit =~ s/\D//g;
Expand All @@ -299,14 +303,19 @@ sub format_query_for_computer_search{
my @args;
my $start = "";
my $limit = "";

my $orderby = "";

foreach my $hash_ref (@args_array) {
foreach (keys %{$hash_ref}) {
if(lc($_) eq "limit"){
$limit = ${$hash_ref}{$_};
}elsif (lc($_) eq "start"){
$start = ${$hash_ref}{$_};
}elsif (lc($_) eq "orderby"){
my ($field, $order) = split /;/, ${$hash_ref}{$_};
$field =~ tr/a-zA-Z//dc ;
$order =~ tr/a-zA-Z//dc ;
$orderby = " ORDER BY $field $order ";
}elsif (${$hash_ref}{$_} eq "null"){
$field_name = $_;
$field_name =~ tr/a-zA-Z//dc ;
Expand All @@ -320,9 +329,13 @@ sub format_query_for_computer_search{
}
}

# Exclude group from the result
$query_string .= " deviceid <> ? AND";
push @args, "_SYSTEMGROUP_";

$query_string = substr($query_string, 0, -3);

return execute_custom_request($query_string, $start, $limit, @args);
return execute_custom_request($query_string, $start, $limit, $orderby, @args);

}

Expand Down
Expand Up @@ -20,7 +20,7 @@ sub get_ipdiscover_network{

my @args = ($network);

my $netmaps = Api::Ocsinventory::Restapi::ApiCommon::execute_custom_request($query, "", "", @args);
my $netmaps = Api::Ocsinventory::Restapi::ApiCommon::execute_custom_request($query, "", "", "", @args);

return to_json($netmaps);
}
Expand Down
2 changes: 1 addition & 1 deletion Api/Ocsinventory/Restapi/Ipdiscover/Get/IpdiscoverTag.pm
Expand Up @@ -19,7 +19,7 @@ sub get_ipdiscover_tag{
my $query = "SELECT * from `netmap` WHERE TAG = ?";
my @args = ($tag);

my $netmaps = Api::Ocsinventory::Restapi::ApiCommon::execute_custom_request($query, "", "", @args);
my $netmaps = Api::Ocsinventory::Restapi::ApiCommon::execute_custom_request($query, "", "", "", @args);

return to_json($netmaps);
}
Expand Down

0 comments on commit 689c8d5

Please sign in to comment.