Added grocycode for recipes (closes #1562)

This commit is contained in:
Bernd Bestel
2022-02-11 17:49:30 +01:00
parent 51fdefaede
commit 222c518a5f
16 changed files with 212 additions and 16 deletions

View File

@@ -3,6 +3,8 @@
namespace Grocy\Controllers;
use Grocy\Controllers\Users\User;
use Grocy\Helpers\WebhookRunner;
use Grocy\Helpers\Grocycode;
class RecipesApiController extends BaseApiController
{
@@ -76,4 +78,28 @@ class RecipesApiController extends BaseApiController
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function RecipePrintLabel(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
$recipe = $this->getDatabase()->recipes()->where('id', $args['recipeId'])->fetch();
$webhookData = array_merge([
'recipe' => $recipe->name,
'grocycode' => (string)(new Grocycode(Grocycode::RECIPE, $args['recipeId'])),
], GROCY_LABEL_PRINTER_PARAMS);
if (GROCY_LABEL_PRINTER_RUN_SERVER)
{
(new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON);
}
return $this->ApiResponse($response, $webhookData);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
}

View File

@@ -3,9 +3,12 @@
namespace Grocy\Controllers;
use Grocy\Services\RecipesService;
use Grocy\Helpers\Grocycode;
class RecipesController extends BaseController
{
use GrocycodeTrait;
public function MealPlan(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$start = date('Y-m-d');
@@ -213,4 +216,10 @@ class RecipesController extends BaseController
'mealplanSections' => $this->getDatabase()->meal_plan_sections()->where('id > 0')->orderBy('sort_number')
]);
}
public function RecipeGrocycodeImage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$gc = new Grocycode(Grocycode::RECIPE, $args['recipeId']);
return $this->ServeGrocycodeImage($request, $response, $gc);
}
}