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:
Forceu
2019-08-04 20:31:47 +02:00
committed by GitHub
parent 3dbce7547f
commit 1a23eaabf1
4 changed files with 113 additions and 0 deletions

View File

@@ -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