mirror of
https://github.com/grocy/grocy.git
synced 2025-08-13 01:06:23 +00:00
Add API call to remove an item from the shopping list by productid
This adds an API call, so a shopping list item can easily be removed Please note: This is UNTESTED, as I was unable to run the current grocy master commit on my server.
This commit is contained in:
@@ -288,6 +288,44 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function RemoveFromShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
$listId = 1;
|
||||
$amount = 1;
|
||||
$productId = null;
|
||||
if (array_key_exists('list_id', $requestBody) && !empty($requestBody['list_id']) && is_numeric($requestBody['list_id']))
|
||||
{
|
||||
$listId = intval($requestBody['list_id']);
|
||||
}
|
||||
if (array_key_exists('product_amount', $requestBody) && !empty($requestBody['product_amount']) && is_numeric($requestBody['product_amount']))
|
||||
{
|
||||
$amount = intval($requestBody['product_amount']);
|
||||
}
|
||||
if (array_key_exists('product_id', $requestBody) && !empty($requestBody['product_id']) && is_numeric($requestBody['product_id']))
|
||||
{
|
||||
$productId = intval($requestBody['product_id']);
|
||||
}
|
||||
|
||||
if ($productId == null)
|
||||
{
|
||||
throw new \Exception("No product id was supplied");
|
||||
}
|
||||
|
||||
$this->StockService->RemoveProductFromShoppingList($productId, $amount, $listId);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
return $this->GenericErrorResponse($response, $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function ExternalBarcodeLookup(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
|
Reference in New Issue
Block a user