mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Filtering of API-Results (#985)
* Add FilteredApiResponse * Use FilteredApiResponse for Generic-Entity-Search * Use FilteredApiResponse for Recipe-Fullfillment * Use FilteredApiResponse for GetUsers * Use FilteredApiResponse for current Tasks * Use FilteredApiResponse for ProductStockEntries & ProductStockLocations * Use FilteredApiResponse for current chores * Use FilteredApiResponse for batteries-current * Fix missing highlighting of "< X days" * Keep to use existing views Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
committed by
GitHub
parent
60f3d900e8
commit
32a4f81f62
@@ -26,8 +26,7 @@ class BatteriesService extends BaseService
|
||||
|
||||
public function GetCurrent()
|
||||
{
|
||||
$sql = 'SELECT * from batteries_current';
|
||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
return $this->getDatabase()->batteries_current();
|
||||
}
|
||||
|
||||
public function TrackChargeCycle(int $batteryId, string $trackedTime)
|
||||
|
@@ -152,8 +152,7 @@ class ChoresService extends BaseService
|
||||
|
||||
public function GetCurrent()
|
||||
{
|
||||
$sql = 'SELECT chores_current.*, chores.name AS chore_name from chores_current join chores on chores_current.chore_id = chores.id';
|
||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
return $this->getDatabase()->chores_current();
|
||||
}
|
||||
|
||||
public function TrackChore(int $choreId, string $trackedTime, $doneBy = GROCY_USER_ID)
|
||||
|
@@ -4,6 +4,8 @@ namespace Grocy\Services;
|
||||
|
||||
#use \Grocy\Services\StockService;
|
||||
|
||||
use LessQL\Result;
|
||||
|
||||
class RecipesService extends BaseService
|
||||
{
|
||||
const RECIPE_TYPE_MEALPLAN_DAY = 'mealplan-day';
|
||||
@@ -82,10 +84,9 @@ class RecipesService extends BaseService
|
||||
return $this->getDataBaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function GetRecipesResolved()
|
||||
public function GetRecipesResolved(): Result
|
||||
{
|
||||
$sql = 'SELECT * FROM recipes_resolved';
|
||||
return $this->getDataBaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
return $this->getDatabase()->recipes_resolved();
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
@@ -603,7 +603,7 @@ class StockService extends BaseService
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
public function GetProductStockEntries($productId, $excludeOpened = false, $allowSubproductSubstitution = false)
|
||||
public function GetProductStockEntries($productId, $excludeOpened = false, $allowSubproductSubstitution = false, $ordered = true)
|
||||
{
|
||||
// In order of next use:
|
||||
// First expiring first, then first in first out
|
||||
@@ -621,8 +621,10 @@ class StockService extends BaseService
|
||||
{
|
||||
$sqlWhereAndOpen = 'AND open = 0';
|
||||
}
|
||||
|
||||
return $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen, $productId)->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC')->fetchAll();
|
||||
$result = $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen, $productId);
|
||||
if ($ordered)
|
||||
return $result->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC');
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function GetProductStockEntriesForLocation($productId, $locationId, $excludeOpened = false, $allowSubproductSubstitution = false)
|
||||
@@ -633,7 +635,7 @@ class StockService extends BaseService
|
||||
|
||||
public function GetProductStockLocations($productId)
|
||||
{
|
||||
return $this->getDatabase()->stock_current_locations()->where('product_id', $productId)->fetchAll();
|
||||
return $this->getDatabase()->stock_current_locations()->where('product_id', $productId);
|
||||
}
|
||||
|
||||
public function GetStockEntry($entryId)
|
||||
|
@@ -4,10 +4,9 @@ namespace Grocy\Services;
|
||||
|
||||
class TasksService extends BaseService
|
||||
{
|
||||
public function GetCurrent()
|
||||
public function GetCurrent(): \LessQL\Result
|
||||
{
|
||||
$sql = 'SELECT * from tasks_current';
|
||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
return $this->getDatabase()->tasks_current();
|
||||
}
|
||||
|
||||
public function MarkTaskAsCompleted($taskId, $doneTime)
|
||||
|
@@ -81,19 +81,9 @@ class UsersService extends BaseService
|
||||
return array_merge($GROCY_DEFAULT_USER_SETTINGS, $settings);
|
||||
}
|
||||
|
||||
public function GetUsersAsDto()
|
||||
public function GetUsersAsDto(): \LessQL\Result
|
||||
{
|
||||
$users = $this->getDatabase()->users();
|
||||
$returnUsers = [];
|
||||
|
||||
foreach ($users as $user)
|
||||
{
|
||||
unset($user->password);
|
||||
$user->display_name = GetUserDisplayName($user);
|
||||
$returnUsers[] = $user;
|
||||
}
|
||||
|
||||
return $returnUsers;
|
||||
return $this->getDatabase()->users_dto();
|
||||
}
|
||||
|
||||
public function SetUserSetting($userId, $settingKey, $settingValue)
|
||||
|
Reference in New Issue
Block a user