2018-07-14 22:49:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
|
|
|
use \Grocy\Services\RecipesService;
|
|
|
|
|
|
|
|
class RecipesApiController extends BaseApiController
|
|
|
|
{
|
|
|
|
public function __construct(\Slim\Container $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
$this->RecipesService = new RecipesService();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected $RecipesService;
|
|
|
|
|
|
|
|
public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
2019-03-03 14:49:46 +01:00
|
|
|
$requestBody = $request->getParsedBody();
|
|
|
|
$excludedProductIds = null;
|
|
|
|
|
|
|
|
if ($requestBody !== null && array_key_exists('excludedProductIds', $requestBody))
|
|
|
|
{
|
|
|
|
$excludedProductIds = $requestBody['excludedProductIds'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds);
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->EmptyApiResponse($response);
|
2018-07-14 22:49:42 +02:00
|
|
|
}
|
2018-08-11 11:48:25 +02:00
|
|
|
|
|
|
|
public function ConsumeRecipe(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->RecipesService->ConsumeRecipe($args['recipeId']);
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->EmptyApiResponse($response);
|
2018-08-11 11:48:25 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
2018-08-11 11:48:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-14 22:49:42 +02:00
|
|
|
}
|