mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Also return userfields in generic object(s) GET API routes (closes #601)
This commit is contained in:
parent
87e68523e5
commit
25be604b31
@ -36,6 +36,7 @@
|
||||
- New endpoint `/user/settings` to get all user settings of the currently logged in user (key/value pairs)
|
||||
- New endpoint `/system/config` to get all config settings (`config.php`) (key/value pairs)
|
||||
- The endpoint `/stock/products/{productId}/locations` now also returns the current stock amount of the product in that loctation (new field/property `amount`) (thanks @Forceu)
|
||||
- The endpoints `/objects/{entity}` and `/objects/{entity}/{objectId}` now also include/return userfields of the object(s) (new field/property `userfields` per object, is an array of key/value pairs and `null`, when the object has no userfields)
|
||||
- Fixed that CORS was broken (there was no response to preflight OPTIONS requests)
|
||||
|
||||
### General & other improvements/fixes
|
||||
|
@ -11,9 +11,27 @@ class GenericEntityApiController extends BaseApiController
|
||||
|
||||
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$objects = $this->getDatabase()->{$args['entity']}();
|
||||
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
|
||||
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
$userfields = FindAllObjectsInArrayByPropertyValue($allUserfields, 'object_id', $object->id);
|
||||
$userfieldKeyValuePairs = null;
|
||||
if (count($userfields) > 0)
|
||||
{
|
||||
foreach ($userfields as $userfield)
|
||||
{
|
||||
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
|
||||
}
|
||||
}
|
||||
|
||||
$object->userfields = $userfieldKeyValuePairs;
|
||||
}
|
||||
|
||||
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
|
||||
{
|
||||
return $this->ApiResponse($response, $this->getDatabase()->{$args['entity']}());
|
||||
return $this->ApiResponse($response, $objects);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -25,7 +43,16 @@ class GenericEntityApiController extends BaseApiController
|
||||
{
|
||||
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
|
||||
{
|
||||
return $this->ApiResponse($response, $this->getDatabase()->{$args['entity']}($args['objectId']));
|
||||
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
|
||||
if (count($userfields) === 0)
|
||||
{
|
||||
$userfields = null;
|
||||
}
|
||||
|
||||
$object = $this->getDatabase()->{$args['entity']}($args['objectId']);
|
||||
$object['userfields'] = $userfields;
|
||||
|
||||
return $this->ApiResponse($response, $object);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user