mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Optionally remove only done shopping list items (/stock/shoppinglist/clear
API endpoint, closes #1730)
This commit is contained in:
parent
0b36d02aa1
commit
3a6f04f770
@ -7,3 +7,4 @@
|
||||
- Fixed that the barcode lookup for the "Stock by-barcode" API endpoints was case sensitive
|
||||
- Fixed that the logout button/menu was missing when using external authentication (e.g. LDAP)
|
||||
- Fixed that the consume page/dialog wasn't properly initialized when opening it from the stock entries page
|
||||
- The API endpoint `/stock/shoppinglist/clear` has now a new optional request body parameter `done_only` (to only remove done items from the given shopping list, defaults to `false`)
|
||||
|
@ -233,13 +233,18 @@ class StockApiController extends BaseApiController
|
||||
$requestBody = $this->GetParsedAndFilteredRequestBody($request);
|
||||
|
||||
$listId = 1;
|
||||
|
||||
if (array_key_exists('list_id', $requestBody) && !empty($requestBody['list_id']) && is_numeric($requestBody['list_id']))
|
||||
{
|
||||
$listId = intval($requestBody['list_id']);
|
||||
}
|
||||
|
||||
$this->getStockService()->ClearShoppingList($listId);
|
||||
$doneOnly = false;
|
||||
if (array_key_exists('done_only', $requestBody) && filter_var($requestBody['done_only'], FILTER_VALIDATE_BOOLEAN) !== false)
|
||||
{
|
||||
$doneOnly = boolval($requestBody['done_only']);
|
||||
}
|
||||
|
||||
$this->getStockService()->ClearShoppingList($listId, $doneOnly);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
@ -2961,10 +2961,15 @@
|
||||
"list_id": {
|
||||
"type": "integer",
|
||||
"description": "The shopping list id to clear, when omitted, the default shopping list (with id 1) is used"
|
||||
},
|
||||
"done_only": {
|
||||
"type": "boolean",
|
||||
"description": "When `true`, only done items will be removed (defaults to `false` when ommited)"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"list_id": 2
|
||||
"list_id": 2,
|
||||
"done_only": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -336,14 +336,21 @@ class StockService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
public function ClearShoppingList($listId = 1)
|
||||
public function ClearShoppingList($listId = 1, $doneOnly = false)
|
||||
{
|
||||
if (!$this->ShoppingListExists($listId))
|
||||
{
|
||||
throw new \Exception('Shopping list does not exist');
|
||||
}
|
||||
|
||||
$this->getDatabase()->shopping_list()->where('shopping_list_id = :1', $listId)->delete();
|
||||
if ($doneOnly)
|
||||
{
|
||||
$this->getDatabase()->shopping_list()->where('shopping_list_id = :1 AND IFNULL(done, 0) = 1', $listId)->delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->getDatabase()->shopping_list()->where('shopping_list_id = :1', $listId)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function ConsumeProduct(int $productId, float $amount, bool $spoiled, $transactionType, $specificStockEntryId = 'default', $recipeId = null, $locationId = null, &$transactionId = null, $allowSubproductSubstitution = false, $consumeExactAmount = false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user