Added an API endpoint to search for objects by name (closes #337)

This commit is contained in:
Bernd Bestel
2019-08-10 13:07:08 +02:00
parent e6020432c6
commit fa326fdfda
4 changed files with 96 additions and 0 deletions

View File

@@ -113,6 +113,25 @@ class GenericEntityApiController extends BaseApiController
}
}
public function SearchObjects(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
try
{
return $this->ApiResponse($this->Database->{$args['entity']}()->where('name LIKE ?', '%' . $args['searchString'] . '%'));
}
catch (\PDOException $ex)
{
return $this->GenericErrorResponse($response, 'The given entity has no field "name"');
}
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function GetUserfields(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
try