Use FilteredApiResponse for Generic-Entity-Search

This commit is contained in:
fipwmaqzufheoxq92ebc 2020-09-01 12:28:03 +02:00
parent 84f519c5f4
commit 5c82fe14ca
No known key found for this signature in database
GPG Key ID: F4DF989490C2ADB7
2 changed files with 6 additions and 4 deletions

View File

@ -3,6 +3,7 @@
namespace Grocy\Controllers;
use Grocy\Controllers\Users\User;
use Slim\Exception\HttpBadRequestException;
class GenericEntityApiController extends BaseApiController
{
@ -178,12 +179,13 @@ class GenericEntityApiController extends BaseApiController
{
try
{
return $this->ApiResponse($response, $this->getDatabase()->{$args['entity']}
()->where('name LIKE ?', '%' . $args['searchString'] . '%'));
return $this->FilteredApiResponse($response, $this->getDatabase()->{$args['entity']}
()->where('name LIKE ?', '%' . $args['searchString'] . '%'), $request->getQueryParams());
}
catch (\PDOException $ex)
{
return $this->GenericErrorResponse($response, 'The given entity has no field "name"');
throw new HttpBadRequestException($request, $ex->getMessage(), $ex);
//return $this->GenericErrorResponse($response, 'The given entity has no field "name"', $ex);
}
}

View File

@ -153,7 +153,7 @@ $app->group('/api', function(RouteCollectorProxy $group)
// Generic entity interaction
$group->get('/objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects');
$group->get('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject');
$group->get('/objects/{entity}/search/{searchString}', '\Grocy\Controllers\GenericEntityApiController:SearchObjects');
$group->get('/objects/{entity}/search/{searchString:.*}', '\Grocy\Controllers\GenericEntityApiController:SearchObjects');
$group->post('/objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject');
$group->put('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject');
$group->delete('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject');