Removde the /objects/{entity}/search API endpoint, added the new filter capabilities to /objects/{entity} (references #985)

This commit is contained in:
Bernd Bestel 2020-11-14 11:27:13 +01:00
parent 16b17b25a4
commit 62997d39bc
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
5 changed files with 6 additions and 99 deletions

View File

@ -132,11 +132,13 @@ _- (Because the stock quantity unit is now the base for everything, it cannot be
- All prices are now related to the products stock quantity unit (instead of the products purchase QU)
- All (product) amounts are now related to the products stock quantity unit (was related to the products purchase QU for the shopping list before)
- The product object no longer has a field `barcodes` with a comma separated barcode list, instead barcodes are now stored in a separate table/entity `product_barcodes` (use the existing "Generic entity interactions" endpoints to access them)
- The endpoint `/objects/{entity}/search` was removed (use the existing `/objects/{entity}` endpoint with new new filter capabilities mentioned below)
- The output / field names of `ProductDetailsResponse` have slightly changed (endpoint `/stock/products/{productId}`)
- For better integration (apps), it's now possible to show a QR-Code for API keys (thanks @fipwmaqzufheoxq92ebc)
- New QR-Code button on the "Manage API keys"-page (top right corner settings menu), the QR-Codes contains `<API-Url>|<API-Key>`
- And on the calendar page when using the button "Share/Integrate calendar (iCal)", there the QR-Codes contains the Share-URL (which is displayed in the textbox above)
- The output of the following endpoints can now be filtered (by any field), ordered and paginated (thanks @fipwmaqzufheoxq92ebc)
- `/objects/{entity}/search`
- The output of the following endpoints can now be filtered (by any field), ordered and paginated (thanks for the initial work on this @fipwmaqzufheoxq92ebc)
- `/objects/{entity}`
- `/stock/products/{productId}/entries`
- `/stock/products/{productId}/locations`
- `/recipes/fulfillment`

View File

@ -135,7 +135,7 @@ class GenericEntityApiController extends BaseApiController
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$objects = $this->getDatabase()->{$args['entity']}();
$objects = $this->queryData($this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
foreach ($objects as $object)
@ -176,25 +176,6 @@ class GenericEntityApiController extends BaseApiController
}
}
public function SearchObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
try
{
return $this->FilteredApiResponse($response, $this->getDatabase()->{$args['entity']}(), $request->getQueryParams());
}
catch (\PDOException $ex)
{
throw new HttpBadRequestException($request, $ex->getMessage(), $ex);
}
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function SetUserfields(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_MASTER_DATA_EDIT);

View File

@ -524,81 +524,6 @@
}
}
},
"/objects/{entity}/search/{searchString}": {
"get": {
"summary": "Returns all objects of the given entity where the field \"name\" contains the search string (so only works for entities which have that field)",
"tags": [
"Generic entity interactions"
],
"parameters": [
{
"in": "path",
"name": "entity",
"required": true,
"description": "A valid entity name",
"schema": {
"$ref": "#/components/internalSchemas/ExposedEntity"
}
},
{
"in": "path",
"name": "searchString",
"required": true,
"description": "The search string",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "An entity object",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/Product"
},
{
"$ref": "#/components/schemas/Chore"
},
{
"$ref": "#/components/schemas/Battery"
},
{
"$ref": "#/components/schemas/Location"
},
{
"$ref": "#/components/schemas/QuantityUnit"
},
{
"$ref": "#/components/schemas/ShoppingListItem"
},
{
"$ref": "#/components/schemas/StockEntry"
}
]
}
}
}
}
},
"400": {
"description": "The operation was not successful",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GenericErrorResponse"
}
}
}
}
}
}
},
"/userfields/{entity}/{objectId}": {
"get": {
"summary": "Returns all userfields with their values of the given object of the given entity",

View File

@ -271,7 +271,7 @@ if (Grocy.Components.ProductPicker !== undefined)
if (document.getElementById("product_id").getAttribute("barcode") != "null")
{
Grocy.Api.Get('objects/product_barcodes/search/?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"),
function(barcodeResult)
{
if (barcodeResult != null)

View File

@ -150,7 +150,6 @@ $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->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');